Skip to content

Commit 2dceda4

Browse files
committed
Auto merge of #121859 - matthiaskrgr:rollup-i724wpm, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - #120646 (Fix incorrect suggestion for uninitialized binding in pattern) - #121416 (Improve error messages for generics with default parameters) - #121475 (Add tidy check for .stderr/.stdout files for non-existent test revisions) - #121580 (make unused_imports less assertive in test modules) - #121736 (Remove `Mutex::unlock` Function) - #121784 (Make the success arms of `if lhs || rhs` meet up in a separate block) - #121818 (CFI: Remove unused `typeid_for_fnsig`) - #121819 (Handle stashing of delayed bugs) - #121828 (Remove unused fluent messages) - #121831 (Fix typo in comment) - #121850 (Make `ZeroablePrimitive` trait unsafe.) - #121853 (normalizes-to: handle negative impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 17edace + ff22925 commit 2dceda4

File tree

56 files changed

+505
-828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+505
-828
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
613613
if self.sugg_span.is_some() {
614614
return;
615615
}
616-
if let hir::StmtKind::Local(hir::Local { span, ty, init: None, .. }) = &ex.kind
616+
617+
// FIXME: We make sure that this is a normal top-level binding,
618+
// but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern
619+
if let hir::StmtKind::Local(hir::Local { span, ty, init: None, pat, .. }) =
620+
&ex.kind
621+
&& let hir::PatKind::Binding(..) = pat.kind
617622
&& span.contains(self.decl_span)
618623
{
619624
self.sugg_span = ty.map_or(Some(self.decl_span), |ty| Some(ty.span));

compiler/rustc_builtin_macros/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ builtin_macros_requires_cfg_pattern =
221221
macro requires a cfg-pattern as an argument
222222
.label = cfg-pattern required
223223
224-
builtin_macros_should_panic = functions using `#[should_panic]` must return `()`
225-
226-
builtin_macros_test_arg_non_lifetime = functions used as tests can not have any non-lifetime generic parameters
227-
228-
builtin_macros_test_args = functions used as tests can not have any arguments
229-
230224
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
231225
.label = `{$kind}` because of this
232226

compiler/rustc_errors/src/lib.rs

+32-18
Original file line numberDiff line numberDiff line change
@@ -712,33 +712,47 @@ impl DiagCtxt {
712712
/// Stashes a diagnostic for possible later improvement in a different,
713713
/// later stage of the compiler. Possible actions depend on the diagnostic
714714
/// level:
715+
/// - Level::Bug, Level:Fatal: not allowed, will trigger a panic.
715716
/// - Level::Error: immediately counted as an error that has occurred, because it
716717
/// is guaranteed to be emitted eventually. Can be later accessed with the
717718
/// provided `span` and `key` through
718719
/// [`DiagCtxt::try_steal_modify_and_emit_err`] or
719720
/// [`DiagCtxt::try_steal_replace_and_emit_err`]. These do not allow
720721
/// cancellation or downgrading of the error. Returns
721722
/// `Some(ErrorGuaranteed)`.
723+
/// - Level::DelayedBug: this does happen occasionally with errors that are
724+
/// downgraded to delayed bugs. It is not stashed, but immediately
725+
/// emitted as a delayed bug. This is because stashing it would cause it
726+
/// to be counted by `err_count` which we don't want. It doesn't matter
727+
/// that we cannot steal and improve it later, because it's not a
728+
/// user-facing error. Returns `Some(ErrorGuaranteed)` as is normal for
729+
/// delayed bugs.
722730
/// - Level::Warning and lower (i.e. !is_error()): can be accessed with the
723731
/// provided `span` and `key` through [`DiagCtxt::steal_non_err()`]. This
724732
/// allows cancelling and downgrading of the diagnostic. Returns `None`.
725-
/// - Others: not allowed, will trigger a panic.
726733
pub fn stash_diagnostic(
727734
&self,
728735
span: Span,
729736
key: StashKey,
730737
diag: DiagInner,
731738
) -> Option<ErrorGuaranteed> {
732-
let guar = if diag.level() == Level::Error {
733-
// This `unchecked_error_guaranteed` is valid. It is where the
734-
// `ErrorGuaranteed` for stashed errors originates. See
735-
// `DiagCtxtInner::drop`.
736-
#[allow(deprecated)]
737-
Some(ErrorGuaranteed::unchecked_error_guaranteed())
738-
} else if !diag.is_error() {
739-
None
740-
} else {
741-
self.span_bug(span, format!("invalid level in `stash_diagnostic`: {}", diag.level));
739+
let guar = match diag.level {
740+
Bug | Fatal => {
741+
self.span_bug(
742+
span,
743+
format!("invalid level in `stash_diagnostic`: {:?}", diag.level),
744+
);
745+
}
746+
Error => {
747+
// This `unchecked_error_guaranteed` is valid. It is where the
748+
// `ErrorGuaranteed` for stashed errors originates. See
749+
// `DiagCtxtInner::drop`.
750+
#[allow(deprecated)]
751+
Some(ErrorGuaranteed::unchecked_error_guaranteed())
752+
}
753+
DelayedBug => return self.inner.borrow_mut().emit_diagnostic(diag),
754+
ForceWarning(_) | Warning | Note | OnceNote | Help | OnceHelp | FailureNote | Allow
755+
| Expect(_) => None,
742756
};
743757

744758
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
@@ -780,11 +794,11 @@ impl DiagCtxt {
780794
let err = self.inner.borrow_mut().stashed_diagnostics.swap_remove(&key);
781795
err.map(|(err, guar)| {
782796
// The use of `::<ErrorGuaranteed>` is safe because level is `Level::Error`.
783-
assert_eq!(err.level, Level::Error);
797+
assert_eq!(err.level, Error);
784798
assert!(guar.is_some());
785799
let mut err = Diag::<ErrorGuaranteed>::new_diagnostic(self, err);
786800
modify_err(&mut err);
787-
assert_eq!(err.level, Level::Error);
801+
assert_eq!(err.level, Error);
788802
err.emit()
789803
})
790804
}
@@ -803,7 +817,7 @@ impl DiagCtxt {
803817
let old_err = self.inner.borrow_mut().stashed_diagnostics.swap_remove(&key);
804818
match old_err {
805819
Some((old_err, guar)) => {
806-
assert_eq!(old_err.level, Level::Error);
820+
assert_eq!(old_err.level, Error);
807821
assert!(guar.is_some());
808822
// Because `old_err` has already been counted, it can only be
809823
// safely cancelled because the `new_err` supplants it.
@@ -1367,7 +1381,7 @@ impl DiagCtxtInner {
13671381
}
13681382

13691383
if diagnostic.has_future_breakage() {
1370-
// Future breakages aren't emitted if they're Level::Allow,
1384+
// Future breakages aren't emitted if they're `Level::Allow`,
13711385
// but they still need to be constructed and stashed below,
13721386
// so they'll trigger the must_produce_diag check.
13731387
self.suppressed_expected_diag = true;
@@ -1453,7 +1467,7 @@ impl DiagCtxtInner {
14531467
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
14541468
if already_emitted {
14551469
let msg = "duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`";
1456-
diagnostic.sub(Level::Note, msg, MultiSpan::new());
1470+
diagnostic.sub(Note, msg, MultiSpan::new());
14571471
}
14581472

14591473
if is_error {
@@ -1623,7 +1637,7 @@ impl DiagCtxtInner {
16231637
bug.arg("level", bug.level);
16241638
let msg = crate::fluent_generated::errors_invalid_flushed_delayed_diagnostic_level;
16251639
let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call
1626-
bug.sub(Level::Note, msg, bug.span.primary_span().unwrap().into());
1640+
bug.sub(Note, msg, bug.span.primary_span().unwrap().into());
16271641
}
16281642
bug.level = Bug;
16291643

@@ -1671,7 +1685,7 @@ impl DelayedDiagInner {
16711685
diag.arg("emitted_at", diag.emitted_at.clone());
16721686
diag.arg("note", self.note);
16731687
let msg = dcx.eagerly_translate_for_subdiag(&diag, msg); // after the `arg` calls
1674-
diag.sub(Level::Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into());
1688+
diag.sub(Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into());
16751689
diag
16761690
}
16771691
}

compiler/rustc_hir_analysis/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ hir_analysis_missing_one_of_trait_item = not all trait items implemented, missin
239239
.label = missing one of `{$missing_items_msg}` in implementation
240240
.note = required because of this annotation
241241
242-
hir_analysis_missing_tilde_const = missing `~const` qualifier for specialization
243-
244242
hir_analysis_missing_trait_item = not all trait items implemented, missing: `{$missing_items_msg}`
245243
.label = missing `{$missing_items_msg}` in implementation
246244

compiler/rustc_hir_analysis/src/astconv/lint.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_ast::TraitObjectSyntax;
2-
use rustc_errors::{codes::*, Diag, EmissionGuarantee, Level, StashKey};
2+
use rustc_errors::{codes::*, Diag, EmissionGuarantee, StashKey};
33
use rustc_hir as hir;
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
@@ -237,15 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
237237
}
238238
// check if the impl trait that we are considering is a impl of a local trait
239239
self.maybe_lint_blanket_trait_impl(self_ty, &mut diag);
240-
match diag.level() {
241-
Level::Error => {
242-
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
243-
}
244-
Level::DelayedBug => {
245-
diag.emit();
246-
}
247-
_ => unreachable!(),
248-
}
240+
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
249241
} else {
250242
let msg = "trait objects without an explicit `dyn` are deprecated";
251243
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12471247
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
12481248
let did1 = def1.did();
12491249
let did2 = def2.did();
1250-
let sub_no_defaults_1 =
1251-
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
1252-
let sub_no_defaults_2 =
1253-
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
1250+
1251+
let generics1 = self.tcx.generics_of(did1);
1252+
let generics2 = self.tcx.generics_of(did2);
1253+
1254+
let non_default_after_default = generics1
1255+
.check_concrete_type_after_default(self.tcx, sub1)
1256+
|| generics2.check_concrete_type_after_default(self.tcx, sub2);
1257+
let sub_no_defaults_1 = if non_default_after_default {
1258+
generics1.own_args(sub1)
1259+
} else {
1260+
generics1.own_args_no_defaults(self.tcx, sub1)
1261+
};
1262+
let sub_no_defaults_2 = if non_default_after_default {
1263+
generics2.own_args(sub2)
1264+
} else {
1265+
generics2.own_args_no_defaults(self.tcx, sub2)
1266+
};
12541267
let mut values = (DiagStyledString::new(), DiagStyledString::new());
12551268
let path1 = self.tcx.def_path_str(did1);
12561269
let path2 = self.tcx.def_path_str(did2);

compiler/rustc_lint/src/context/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
104104
if let Some(span) = in_test_module {
105105
diag.span_help(
106106
sess.source_map().guess_head_span(span),
107-
"consider adding a `#[cfg(test)]` to the containing module",
107+
"if this is a test module, consider adding a `#[cfg(test)]` to the containing module",
108108
);
109109
}
110110
}

compiler/rustc_middle/src/ty/generics.rs

+24
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,30 @@ impl<'tcx> Generics {
360360
let own = &args[self.parent_count..][..self.params.len()];
361361
if self.has_self && self.parent.is_none() { &own[1..] } else { own }
362362
}
363+
364+
/// Returns true if a concrete type is specified after a default type.
365+
/// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
366+
/// `T<usize, String>` will return true
367+
/// `T<usize>` will return false
368+
pub fn check_concrete_type_after_default(
369+
&'tcx self,
370+
tcx: TyCtxt<'tcx>,
371+
args: &'tcx [ty::GenericArg<'tcx>],
372+
) -> bool {
373+
let mut default_param_seen = false;
374+
for param in self.params.iter() {
375+
if let Some(inst) =
376+
param.default_value(tcx).map(|default| default.instantiate(tcx, args))
377+
{
378+
if inst == args[param.index as usize] {
379+
default_param_seen = true;
380+
} else if default_param_seen {
381+
return true;
382+
}
383+
}
384+
}
385+
false
386+
}
363387
}
364388

365389
/// Bounds on generics.

compiler/rustc_mir_build/src/build/matches/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9393
variable_source_info,
9494
true,
9595
));
96-
this.cfg.goto(lhs_success_block, variable_source_info, rhs_success_block);
97-
rhs_success_block.unit()
96+
97+
// Make the LHS and RHS success arms converge to a common block.
98+
// (We can't just make LHS goto RHS, because `rhs_success_block`
99+
// might contain statements that we don't want on the LHS path.)
100+
let success_block = this.cfg.start_new_block();
101+
this.cfg.goto(lhs_success_block, variable_source_info, success_block);
102+
this.cfg.goto(rhs_success_block, variable_source_info, success_block);
103+
success_block.unit()
98104
}
99105
ExprKind::Unary { op: UnOp::Not, arg } => {
100106
let local_scope = this.local_scope();

compiler/rustc_mir_transform/src/known_panics_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
586586
}
587587

588588
Aggregate(ref kind, ref fields) => {
589-
// Do not const pop union fields as they can be
589+
// Do not const prop union fields as they can be
590590
// made to produce values that don't match their
591591
// underlying layout's type (see ICE #121534).
592592
// If the last element of the `Adt` tuple

compiler/rustc_parse/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ parse_found_expr_would_be_stmt = expected expression, found `{$token}`
284284
parse_function_body_equals_expr = function body cannot be `= expression;`
285285
.suggestion = surround the expression with `{"{"}` and `{"}"}` instead of `=` and `;`
286286
287-
parse_gen_fn = `gen` functions are not yet implemented
288-
.help = for now you can use `gen {"{}"}` blocks and return `impl Iterator` instead
289-
290287
parse_generic_args_in_pat_require_turbofish_syntax = generic args in patterns require the turbofish syntax
291288
292289
parse_generic_parameters_without_angle_brackets = generic parameters without surrounding angle brackets

compiler/rustc_resolve/messages.ftl

-22
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ resolve_add_as_non_derive =
88
resolve_added_macro_use =
99
have you added the `#[macro_use]` on the module/import?
1010
11-
resolve_ampersand_used_without_explicit_lifetime_name =
12-
`&` without an explicit lifetime name cannot be used here
13-
.note = explicit lifetime name needed here
14-
1511
resolve_ancestor_only =
1612
visibilities can only be restricted to ancestor modules
1713
@@ -100,12 +96,6 @@ resolve_const_param_in_non_trivial_anon_const =
10096
resolve_const_param_in_ty_of_const_param =
10197
const parameters may not be used in the type of const parameters
10298
103-
resolve_crate_may_not_be_imported =
104-
`$crate` may not be imported
105-
106-
resolve_crate_root_imports_must_be_named_explicitly =
107-
crate root imports need to be explicitly named: `use crate as name;`
108-
10999
resolve_expected_found =
110100
expected module, found {$res} `{$path_str}`
111101
.label = not a module
@@ -220,9 +210,6 @@ resolve_param_in_ty_of_const_param =
220210
the type of const parameters must not depend on other generic parameters
221211
.label = the type must not depend on the parameter `{$name}`
222212
223-
resolve_parent_module_reset_for_binding =
224-
parent module is reset for binding
225-
226213
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
227214
.help = you can define integration tests in a directory named `tests`
228215
@@ -270,11 +257,6 @@ resolve_trait_impl_duplicate =
270257
.old_span_label = previous definition here
271258
.trait_item_span = item in trait
272259
273-
resolve_trait_impl_mismatch =
274-
item `{$name}` is an associated {$kind}, which doesn't match its trait `{$trait_path}`
275-
.label = does not match trait
276-
.label_trait_item = item in trait
277-
278260
resolve_try_using_similarly_named_label =
279261
try using similarly named label
280262
@@ -295,10 +277,6 @@ resolve_undeclared_label =
295277
use of undeclared label `{$name}`
296278
.label = undeclared label `{$name}`
297279
298-
resolve_underscore_lifetime_name_cannot_be_used_here =
299-
`'_` cannot be used here
300-
.note = `'_` is a reserved lifetime name
301-
302280
resolve_unexpected_res_change_ty_to_const_param_sugg =
303281
you might have meant to write a const parameter here
304282

compiler/rustc_symbol_mangling/src/typeid.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
/// For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
55
/// see design document in the tracking issue #89653.
66
use bitflags::bitflags;
7-
use rustc_middle::ty::{FnSig, Instance, Ty, TyCtxt};
7+
use rustc_middle::ty::{Instance, Ty, TyCtxt};
88
use rustc_target::abi::call::FnAbi;
99
use std::hash::Hasher;
1010
use twox_hash::XxHash64;
1111

1212
bitflags! {
13-
/// Options for typeid_for_fnabi and typeid_for_fnsig.
13+
/// Options for typeid_for_fnabi.
1414
#[derive(Clone, Copy, Debug)]
1515
pub struct TypeIdOptions: u32 {
1616
const GENERALIZE_POINTERS = 1;
@@ -30,15 +30,6 @@ pub fn typeid_for_fnabi<'tcx>(
3030
typeid_itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, options)
3131
}
3232

33-
/// Returns a type metadata identifier for the specified FnSig.
34-
pub fn typeid_for_fnsig<'tcx>(
35-
tcx: TyCtxt<'tcx>,
36-
fn_sig: &FnSig<'tcx>,
37-
options: TypeIdOptions,
38-
) -> String {
39-
typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, options)
40-
}
41-
4233
/// Returns a type metadata identifier for the specified Instance.
4334
pub fn typeid_for_instance<'tcx>(
4435
tcx: TyCtxt<'tcx>,
@@ -61,19 +52,6 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
6152
hash.finish() as u32
6253
}
6354

64-
/// Returns a KCFI type metadata identifier for the specified FnSig.
65-
pub fn kcfi_typeid_for_fnsig<'tcx>(
66-
tcx: TyCtxt<'tcx>,
67-
fn_sig: &FnSig<'tcx>,
68-
options: TypeIdOptions,
69-
) -> u32 {
70-
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
71-
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
72-
let mut hash: XxHash64 = Default::default();
73-
hash.write(typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, options).as_bytes());
74-
hash.finish() as u32
75-
}
76-
7755
/// Returns a KCFI type metadata identifier for the specified Instance.
7856
pub fn kcfi_typeid_for_instance<'tcx>(
7957
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)