From 87d8f5885b4f289477e48090a86356302437cec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 17:23:34 +0000 Subject: [PATCH 01/12] Provide more context on type errors in const context - On `const` and `static` point at the type (like we do for let bindings) - On fn calls, point at const parameter in fn definition - On type, point at const parameter in type definition - On array type lengths, explain that array length is always `usize` - On enum variant discriminant, mention `repr` --- compiler/rustc_hir_typeck/src/lib.rs | 112 +++++++++++++++++- .../closure-in-array-len.stderr | 1 + ...lice-only-once-semantic-restriction.stderr | 4 +- ...g-assoc-type-because-of-assoc-const.stderr | 4 +- .../defaults-in-other-trait-items.rs | 1 + .../defaults-in-other-trait-items.stderr | 6 +- tests/ui/associated-types/issue-26681.stderr | 4 +- tests/ui/closures/issue-90871.stderr | 1 + .../byte-string-u8-validation.rs | 1 + .../byte-string-u8-validation.stderr | 7 +- .../mismatch-raw-ptr-in-adt.stderr | 10 ++ .../transmutable-ice-110969.stderr | 4 +- .../unsized-anon-const-err-1.stderr | 4 +- .../unsized-anon-const-func-err.stderr | 4 +- .../unsized-anon-const-struct-err.stderr | 4 +- .../bad-generic-in-copy-impl.stderr | 3 + .../generic_const_exprs/error_in_ty.stderr | 12 ++ .../generic_const_exprs/issue-105257.stderr | 4 +- .../generic_const_exprs/opaque_type.stderr | 1 + .../invalid-patterns.64bit.stderr | 24 ++++ .../ui/const-generics/ogca/basic-fail.stderr | 4 +- tests/ui/const-generics/opaque_types.stderr | 5 + .../vec-macro-in-static-array.stderr | 4 +- .../consts/array-literal-len-mismatch.stderr | 7 +- tests/ui/consts/const-array-oob-arith.rs | 6 +- tests/ui/consts/const-array-oob-arith.stderr | 16 +-- .../const-eval/array-len-mismatch-type.stderr | 1 + tests/ui/consts/const-eval/const-eval-span.rs | 5 +- .../consts/const-eval/const-eval-span.stderr | 2 + tests/ui/consts/const-integer-bool-ops.rs | 10 ++ tests/ui/consts/const-integer-bool-ops.stderr | 70 +++++++---- .../const-result-no-expect-suggestion.stderr | 4 +- .../ui/consts/const-slice-array-deref.stderr | 4 +- tests/ui/consts/const-tup-index-span.rs | 7 +- tests/ui/consts/const-tup-index-span.stderr | 4 +- tests/ui/consts/const-type-mismatch.stderr | 8 +- tests/ui/consts/enum-discr-type-err.stderr | 2 + tests/ui/consts/issue-104768.stderr | 4 +- tests/ui/consts/issue-39974.rs | 10 +- tests/ui/consts/issue-39974.stderr | 8 +- ...issue-69310-array-size-lit-wrong-ty.stderr | 4 + tests/ui/consts/nested_erroneous_ctfe.stderr | 1 + .../promoted-type-error-issue-133968.stderr | 4 +- .../ui/diagnostic-width/long-span.long.stderr | 6 +- .../diagnostic-width/long-span.longest.stderr | 6 +- .../diagnostic-width/long-span.short.stderr | 6 +- .../long-span.shortest.stderr | 6 +- .../brackets-to-braces-single-element.stderr | 4 +- .../discriminant-ill-typed.rs | 40 ++++--- .../discriminant-ill-typed.stderr | 22 ++-- .../enum/closure-in-enum-issue-48838.stderr | 1 + .../enum-discriminant-type-mismatch-8761.rs | 10 +- ...num-discriminant-type-mismatch-8761.stderr | 4 +- .../assoc-const-missing-type.stderr | 5 +- ...-unconstrained-inference-vars-69306.stderr | 8 +- tests/ui/issues/issue-31910.rs | 9 +- tests/ui/issues/issue-31910.stderr | 2 + .../lifetimes/unusual-rib-combinations.stderr | 2 + .../array-len-is-closure.stderr | 1 + .../array-repeat-unit-struct.rs | 5 +- .../array-repeat-unit-struct.stderr | 2 + .../regress/loop-in-array-length.stderr | 1 + tests/ui/numeric/const-scope.stderr | 8 +- tests/ui/parser/pat-lt-bracket-6.stderr | 4 +- tests/ui/parser/pat-lt-bracket-7.stderr | 4 +- ...recover-for-loop-parens-around-head.stderr | 4 +- tests/ui/proc-macro/macro-brackets.stderr | 4 +- tests/ui/repeat-expr/repeat_count.stderr | 13 ++ tests/ui/self/issue-61882.stderr | 4 +- tests/ui/static/bad-const-type.rs | 5 +- tests/ui/static/bad-const-type.stderr | 4 +- tests/ui/static/issue-5216.stderr | 4 +- .../arrays/issue-103783-array-length.stderr | 2 + tests/ui/type/pattern_types/nested.stderr | 4 +- .../pattern_type_mismatch.stderr | 16 ++- ...range-expr-root-of-constant-issue-40749.rs | 14 ++- ...e-expr-root-of-constant-issue-40749.stderr | 1 + 77 files changed, 493 insertions(+), 139 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 77c95fd55be32..200cef49f35d6 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -41,7 +41,7 @@ pub use coercion::can_coerce; use fn_ctxt::FnCtxt; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; -use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_err}; +use rustc_errors::{Applicability, Diag, ErrorGuaranteed, pluralize, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{HirId, HirIdMap, Node}; @@ -204,7 +204,9 @@ fn typeck_with_inspect<'tcx>( ); } - fcx.check_expr_coercible_to_type(body.value, expected_type, None); + fcx.check_expr_coercible_to_type_or_error(body.value, expected_type, None, |err, _| { + extend_err_with_const_context(err, tcx, node); + }); fcx.write_ty(id, expected_type); }; @@ -274,6 +276,112 @@ fn typeck_with_inspect<'tcx>( typeck_results } +fn extend_err_with_const_context(err: &mut Diag<'_>, tcx: TyCtxt<'_>, node: hir::Node<'_>) { + match node { + hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), .. }) + | hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Const(ty, _, _), .. + }) => { + // Point at the `Type` in `const NAME: Type = value;`. + err.span_label(ty.span, "expected because of the type of the associated constant"); + } + hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, ty, _), .. }) => { + // Point at the `Type` in `const NAME: Type = value;`. + err.span_label(ty.span, "expected because of the type of the constant"); + } + hir::Node::Item(hir::Item { kind: hir::ItemKind::Static(_, _, ty, _), .. }) => { + // Point at the `Type` in `static NAME: Type = value;`. + err.span_label(ty.span, "expected because of the type of the static"); + } + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::Ty(parent) = tcx.parent_hir_node(parent.hir_id) + && let hir::TyKind::Array(_ty, _len) = parent.kind => + { + // `[type; len]` in type context. + err.note("array length can only be `usize`"); + } + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::Expr(parent) = tcx.parent_hir_node(parent.hir_id) + && let hir::ExprKind::Repeat(_ty, _len) = parent.kind => + { + // `[type; len]` in expr context. + err.note("array length can only be `usize`"); + } + // FIXME: support method calls too. + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::Expr(expr) = tcx.parent_hir_node(parent.hir_id) + && let hir::ExprKind::Path(path) = expr.kind + && let hir::QPath::Resolved(_, path) = path + && let Res::Def(_, def_id) = path.res => + { + // `foo()` in expression context, point at `foo`'s const parameter. + if let Some(i) = + path.segments.iter().last().and_then(|segment| segment.args).and_then(|args| { + args.args.iter().position(|arg| { + matches!(arg, hir::GenericArg::Const(arg) if arg.hir_id == parent.hir_id) + }) + }) + { + let generics = tcx.generics_of(def_id); + let param = &generics.param_at(i, tcx); + let sp = tcx.def_span(param.def_id); + err.span_note(sp, "expected because of the type of the const parameter"); + } + } + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::Ty(ty) = tcx.parent_hir_node(parent.hir_id) + && let hir::TyKind::Path(path) = ty.kind + && let hir::QPath::Resolved(_, path) = path + && let Res::Def(_, def_id) = path.res => + { + // `Foo` in type context, point at `Foo`'s const parameter. + if let Some(i) = + path.segments.iter().last().and_then(|segment| segment.args).and_then(|args| { + args.args.iter().position(|arg| { + matches!(arg, hir::GenericArg::Const(arg) if arg.hir_id == parent.hir_id) + }) + }) + { + let generics = tcx.generics_of(def_id); + let param = &generics.param_at(i, tcx); + let sp = tcx.def_span(param.def_id); + err.span_note(sp, "expected because of the type of the const parameter"); + } + } + hir::Node::AnonConst(anon) + if let hir::Node::Variant(_variant) = tcx.parent_hir_node(anon.hir_id) => + { + // FIXME: point at `repr` when present in the type. + err.note( + "enum variant discriminant can only be of a primitive type compatible with the \ + enum's `repr`", + ); + } + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::GenericParam(param) = tcx.parent_hir_node(parent.hir_id) + && let hir::GenericParamKind::Const { ty, .. } = param.kind => + { + // `fn foo` point at the `usize`. + err.span_label(ty.span, "expected because of the type of the const parameter"); + } + hir::Node::AnonConst(anon) + if let hir::Node::ConstArg(parent) = tcx.parent_hir_node(anon.hir_id) + && let hir::Node::TyPat(ty_pat) = tcx.parent_hir_node(parent.hir_id) + && let hir::Node::Ty(ty) = tcx.parent_hir_node(ty_pat.hir_id) + && let hir::TyKind::Pat(ty, _) = ty.kind => + { + // Point at `char` in `pattern_type!(char is 1..=1)`. + err.span_label(ty.span, "the pattern must match the type"); + } + _ => {} + } +} + fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Option> { let tcx = fcx.tcx; let def_id = fcx.body_id; diff --git a/tests/ui/array-slice-vec/closure-in-array-len.stderr b/tests/ui/array-slice-vec/closure-in-array-len.stderr index decdde042c6f7..04841f1d1f660 100644 --- a/tests/ui/array-slice-vec/closure-in-array-len.stderr +++ b/tests/ui/array-slice-vec/closure-in-array-len.stderr @@ -6,6 +6,7 @@ LL | fn([u8; |x: u8| {}]), | = note: expected type `usize` found closure `{closure@$DIR/closure-in-array-len.rs:3:13: 3:20}` + = note: array length can only be `usize` error: aborting due to 1 previous error diff --git a/tests/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr b/tests/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr index 4d6078788b228..d665125608aff 100644 --- a/tests/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr +++ b/tests/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr @@ -16,7 +16,9 @@ error[E0308]: mismatched types --> $DIR/subslice-only-once-semantic-restriction.rs:11:30 | LL | const RECOVERY_WITNESS: () = 0; - | ^ expected `()`, found integer + | -- ^ expected `()`, found integer + | | + | expected because of the type of the constant error: aborting due to 3 previous errors diff --git a/tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.stderr b/tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.stderr index 3b89ed66b355e..50bafc96acaab 100644 --- a/tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.stderr +++ b/tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/suggest-contraining-assoc-type-because-of-assoc-const.rs:13:21 | LL | const N: C::M = 4u8; - | ^^^ expected associated type, found `u8` + | ---- ^^^ expected associated type, found `u8` + | | + | expected because of the type of the associated constant | = note: expected associated type `::M` found type `u8` diff --git a/tests/ui/associated-types/defaults-in-other-trait-items.rs b/tests/ui/associated-types/defaults-in-other-trait-items.rs index 3de64e0d0db6d..7b3e7f96acb50 100644 --- a/tests/ui/associated-types/defaults-in-other-trait-items.rs +++ b/tests/ui/associated-types/defaults-in-other-trait-items.rs @@ -37,6 +37,7 @@ trait AssocConst { //~^ ERROR mismatched types //~| NOTE expected associated type, found `u8` //~| NOTE expected associated type `::Ty` + //~| NOTE expected because } // An impl can, however diff --git a/tests/ui/associated-types/defaults-in-other-trait-items.stderr b/tests/ui/associated-types/defaults-in-other-trait-items.stderr index 56abd6ebf73b2..fe9023e52324e 100644 --- a/tests/ui/associated-types/defaults-in-other-trait-items.stderr +++ b/tests/ui/associated-types/defaults-in-other-trait-items.stderr @@ -19,13 +19,15 @@ LL | type Ty = u8; | ------- associated type defaults can't be assumed inside the trait defining them ... LL | const C: Self::Ty = 0u8; - | ^^^ expected associated type, found `u8` + | -------- ^^^ expected associated type, found `u8` + | | + | expected because of the type of the associated constant | = note: expected associated type `::Ty` found type `u8` error[E0308]: mismatched types - --> $DIR/defaults-in-other-trait-items.rs:54:9 + --> $DIR/defaults-in-other-trait-items.rs:55:9 | LL | type Res = isize; | -------- associated type defaults can't be assumed inside the trait defining them diff --git a/tests/ui/associated-types/issue-26681.stderr b/tests/ui/associated-types/issue-26681.stderr index 5fb1a4ef3f5f0..798f0eb392c4b 100644 --- a/tests/ui/associated-types/issue-26681.stderr +++ b/tests/ui/associated-types/issue-26681.stderr @@ -4,7 +4,9 @@ error[E0308]: mismatched types LL | type Fv: Foo = u8; | ------------ associated type defaults can't be assumed inside the trait defining them LL | const C: ::Bar = 6665; - | ^^^^ expected associated type, found integer + | ---------------------- ^^^^ expected associated type, found integer + | | + | expected because of the type of the associated constant | = note: expected associated type `<::Fv as Foo>::Bar` found type `{integer}` diff --git a/tests/ui/closures/issue-90871.stderr b/tests/ui/closures/issue-90871.stderr index 140f249821404..a70c761201b6b 100644 --- a/tests/ui/closures/issue-90871.stderr +++ b/tests/ui/closures/issue-90871.stderr @@ -20,6 +20,7 @@ LL | type_ascribe!(2, n([u8; || 1])) | = note: expected type `usize` found closure `{closure@$DIR/issue-90871.rs:4:29: 4:31}` + = note: array length can only be `usize` help: use parentheses to call this closure | LL | type_ascribe!(2, n([u8; (|| 1)()])) diff --git a/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.rs b/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.rs index d49fb49d253cb..5d6e34804c5cc 100644 --- a/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.rs +++ b/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.rs @@ -9,6 +9,7 @@ struct ConstBytes //~^ ERROR rustc_dump_predicates //~| NOTE Binder { value: ConstArgHasType(T/#0, &'static [*mut u8; 3_usize]), bound_vars: [] } //~| NOTE Binder { value: TraitPredicate( as std::marker::Sized>, polarity:Positive), bound_vars: [] } +//~| NOTE expected because of the type of the const parameter where ConstBytes: Sized; diff --git a/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.stderr b/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.stderr index 1273a74102a24..34c65af7cd970 100644 --- a/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.stderr +++ b/tests/ui/const-generics/adt_const_params/byte-string-u8-validation.stderr @@ -1,11 +1,16 @@ error[E0308]: mismatched types - --> $DIR/byte-string-u8-validation.rs:14:16 + --> $DIR/byte-string-u8-validation.rs:15:16 | LL | ConstBytes: Sized; | ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]` | = note: expected reference `&'static [*mut u8; 3]` found reference `&'static [u8; 3]` +note: expected because of the type of the const parameter + --> $DIR/byte-string-u8-validation.rs:8:19 + | +LL | struct ConstBytes + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: rustc_dump_predicates --> $DIR/byte-string-u8-validation.rs:8:1 diff --git a/tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.stderr b/tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.stderr index d7eec45bae0f3..14afd18f82a71 100644 --- a/tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.stderr +++ b/tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.stderr @@ -15,6 +15,11 @@ LL | let _: ConstBytes = ConstBytes::; | = note: expected reference `&'static [*mut u8; 3]` found reference `&'static [u8; 3]` +note: expected because of the type of the const parameter + --> $DIR/mismatch-raw-ptr-in-adt.rs:5:19 + | +LL | struct ConstBytes; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/mismatch-raw-ptr-in-adt.rs:9:46 @@ -24,6 +29,11 @@ LL | let _: ConstBytes = ConstBytes::; | = note: expected reference `&'static [*mut u8; 3]` found reference `&'static [u8; 3]` +note: expected because of the type of the const parameter + --> $DIR/mismatch-raw-ptr-in-adt.rs:5:19 + | +LL | struct ConstBytes; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr index 9671668561477..bc8feaf5214ac 100644 --- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr +++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr @@ -16,7 +16,9 @@ error[E0308]: mismatched types --> $DIR/transmutable-ice-110969.rs:25:29 | LL | const FALSE: bool = assert::is_transmutable::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | | + | expected because of the type of the associated constant error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/adt_const_params/unsized-anon-const-err-1.stderr b/tests/ui/const-generics/adt_const_params/unsized-anon-const-err-1.stderr index daea55efbbc7c..4125461f92b2d 100644 --- a/tests/ui/const-generics/adt_const_params/unsized-anon-const-err-1.stderr +++ b/tests/ui/const-generics/adt_const_params/unsized-anon-const-err-1.stderr @@ -36,7 +36,9 @@ error[E0308]: mismatched types --> $DIR/unsized-anon-const-err-1.rs:8:34 | LL | const EMPTY_MATRIX: Matrix = [[0; 4]; 4]; - | ^^^^^^^^^^^ expected `[&u32]`, found `[&u32; 4]` + | ------ ^^^^^^^^^^^ expected `[&u32]`, found `[&u32; 4]` + | | + | expected because of the type of the constant error: aborting due to 5 previous errors diff --git a/tests/ui/const-generics/adt_const_params/unsized-anon-const-func-err.stderr b/tests/ui/const-generics/adt_const_params/unsized-anon-const-func-err.stderr index 14a41e87e4aa5..9e22119cf87f8 100644 --- a/tests/ui/const-generics/adt_const_params/unsized-anon-const-func-err.stderr +++ b/tests/ui/const-generics/adt_const_params/unsized-anon-const-func-err.stderr @@ -21,7 +21,9 @@ error[E0308]: mismatched types --> $DIR/unsized-anon-const-func-err.rs:9:22 | LL | const VALUE: [u32] = [0; 4]; - | ^^^^^^ expected `[u32]`, found `[u32; 4]` + | ----- ^^^^^^ expected `[u32]`, found `[u32; 4]` + | | + | expected because of the type of the constant error[E0277]: the size for values of type `[u32]` cannot be known at compilation time --> $DIR/unsized-anon-const-func-err.rs:14:12 diff --git a/tests/ui/const-generics/adt_const_params/unsized-anon-const-struct-err.stderr b/tests/ui/const-generics/adt_const_params/unsized-anon-const-struct-err.stderr index d9a13976d68ad..d81eeb465d6fb 100644 --- a/tests/ui/const-generics/adt_const_params/unsized-anon-const-struct-err.stderr +++ b/tests/ui/const-generics/adt_const_params/unsized-anon-const-struct-err.stderr @@ -30,7 +30,9 @@ error[E0308]: mismatched types --> $DIR/unsized-anon-const-struct-err.rs:6:22 | LL | const VALUE: [u32] = [0; 4]; - | ^^^^^^ expected `[u32]`, found `[u32; 4]` + | ----- ^^^^^^ expected `[u32]`, found `[u32; 4]` + | | + | expected because of the type of the constant error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr index fbd546d42fb52..c2cf80f38ecaa 100644 --- a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr +++ b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr @@ -3,6 +3,8 @@ error[E0308]: mismatched types | LL | x: [u8; SIZE], | ^^^^ expected `usize`, found `u32` + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/bad-generic-in-copy-impl.rs:3:13 @@ -10,6 +12,7 @@ error[E0308]: mismatched types LL | x: [u8; SIZE], | ^^^^ expected `usize`, found `u32` | + = note: array length can only be `usize` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr index 58f0d31b09601..e10ea5a44b263 100644 --- a/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr +++ b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr @@ -29,12 +29,24 @@ error[E0308]: mismatched types | LL | impl A<2> { | ^ expected `[usize; x]`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/error_in_ty.rs:6:14 + | +LL | pub struct A {} + | ^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/error_in_ty.rs:16:8 | LL | impl A<2> { | ^ expected `[usize; x]`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/error_in_ty.rs:6:14 + | +LL | pub struct A {} + | ^^^^^^^^^^^^^^^^^^^ error[E0592]: duplicate definitions with name `B` --> $DIR/error_in_ty.rs:12:5 diff --git a/tests/ui/const-generics/generic_const_exprs/issue-105257.stderr b/tests/ui/const-generics/generic_const_exprs/issue-105257.stderr index 1d0ab56519cfb..c90feb404181c 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-105257.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-105257.stderr @@ -14,7 +14,9 @@ error[E0308]: mismatched types --> $DIR/issue-105257.rs:5:29 | LL | fn fnc(&self) {} - | ^^ expected `usize`, found `&str` + | ----- ^^ expected `usize`, found `&str` + | | + | expected because of the type of the const parameter error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr index 9f48a8563c8ab..fd597cbde1931 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr @@ -9,6 +9,7 @@ LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; | = note: expected type `usize` found opaque type `Foo` + = note: array length can only be `usize` error[E0605]: non-primitive cast: `usize` as `Foo` --> $DIR/opaque_type.rs:11:17 diff --git a/tests/ui/const-generics/min_const_generics/invalid-patterns.64bit.stderr b/tests/ui/const-generics/min_const_generics/invalid-patterns.64bit.stderr index df7c2a0a86292..9392a171510d7 100644 --- a/tests/ui/const-generics/min_const_generics/invalid-patterns.64bit.stderr +++ b/tests/ui/const-generics/min_const_generics/invalid-patterns.64bit.stderr @@ -3,24 +3,48 @@ error[E0308]: mismatched types | LL | get_flag::(); | ^^^^ expected `char`, found `u8` + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:34 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:33:14 | LL | get_flag::<7, 'c'>(); | ^ expected `bool`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:13 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:35:14 | LL | get_flag::<42, 0x5ad>(); | ^^ expected `bool`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:13 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:35:18 | LL | get_flag::<42, 0x5ad>(); | ^^^^^ expected `char`, found `u8` + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:34 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0080]: reading memory at ALLOC0[0x0..0x4], but memory is uninitialized at [0x1..0x4], and this operation requires initialized memory --> $DIR/invalid-patterns.rs:40:32 diff --git a/tests/ui/const-generics/ogca/basic-fail.stderr b/tests/ui/const-generics/ogca/basic-fail.stderr index ce4e8eb1471c3..b1808deacd27f 100644 --- a/tests/ui/const-generics/ogca/basic-fail.stderr +++ b/tests/ui/const-generics/ogca/basic-fail.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/basic-fail.rs:15:30 | LL | const ARR: [(); ADD1::<0>] = [(); INC::<0>]; - | ^^^^^^^^^^^^^^ expected an array with a size of const { N + 1 }, found one with a size of const { N + 1 } + | --------------- ^^^^^^^^^^^^^^ expected an array with a size of const { N + 1 }, found one with a size of const { N + 1 } + | | + | expected because of the type of the constant error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/opaque_types.stderr b/tests/ui/const-generics/opaque_types.stderr index f67e1c8ce6992..d49a643e0d879 100644 --- a/tests/ui/const-generics/opaque_types.stderr +++ b/tests/ui/const-generics/opaque_types.stderr @@ -30,6 +30,11 @@ LL | foo::<42>(); | = note: expected opaque type `Foo` found type `{integer}` +note: expected because of the type of the const parameter + --> $DIR/opaque_types.rs:6:8 + | +LL | fn foo() {} + | ^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/vec-macro-in-static-array.stderr b/tests/ui/const-generics/vec-macro-in-static-array.stderr index 63d7b0c89fa1f..ae08cad556fc8 100644 --- a/tests/ui/const-generics/vec-macro-in-static-array.stderr +++ b/tests/ui/const-generics/vec-macro-in-static-array.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/vec-macro-in-static-array.rs:5:26 | LL | static VEC: [u32; 256] = vec![]; - | ^^^^^^ expected `[u32; 256]`, found `Vec<_>` + | ---------- ^^^^^^ expected `[u32; 256]`, found `Vec<_>` + | | + | expected because of the type of the static | = note: expected array `[u32; 256]` found struct `Vec<_>` diff --git a/tests/ui/consts/array-literal-len-mismatch.stderr b/tests/ui/consts/array-literal-len-mismatch.stderr index 39b8a647324b3..782d059a294c2 100644 --- a/tests/ui/consts/array-literal-len-mismatch.stderr +++ b/tests/ui/consts/array-literal-len-mismatch.stderr @@ -2,9 +2,10 @@ error[E0308]: mismatched types --> $DIR/array-literal-len-mismatch.rs:1:26 | LL | const NUMBERS: [u8; 3] = [10, 20]; - | - ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | - | help: consider specifying the actual array length: `2` + | ------- ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 + | | | + | | help: consider specifying the actual array length: `2` + | expected because of the type of the constant error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-array-oob-arith.rs b/tests/ui/consts/const-array-oob-arith.rs index 8e5c56e0ea82e..97f8406a10f03 100644 --- a/tests/ui/consts/const-array-oob-arith.rs +++ b/tests/ui/consts/const-array-oob-arith.rs @@ -4,10 +4,12 @@ const VAL: i32 = ARR[IDX]; const BONG: [i32; (ARR[0] - 41) as usize] = [5]; const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; //~^ ERROR: mismatched types -//~| NOTE expected an array +//~| NOTE: expected an array +//~| NOTE: expected because const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; //~^ ERROR: mismatched types -//~| NOTE expected an array +//~| NOTE: expected an array +//~| NOTE: expected because fn main() { let _ = VAL; diff --git a/tests/ui/consts/const-array-oob-arith.stderr b/tests/ui/consts/const-array-oob-arith.stderr index d3299082aa14c..d37ae5e4a7b30 100644 --- a/tests/ui/consts/const-array-oob-arith.stderr +++ b/tests/ui/consts/const-array-oob-arith.stderr @@ -2,17 +2,19 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:5:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ---------------------- ^^^ expected an array with a size of 2, found one with a size of 1 - | | - | help: consider specifying the actual array length: `1` + | ----------------------------- ^^^ expected an array with a size of 2, found one with a size of 1 + | | | + | | help: consider specifying the actual array length: `1` + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-array-oob-arith.rs:8:44 + --> $DIR/const-array-oob-arith.rs:9:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ---------------------- ^^^^^^^ expected an array with a size of 1, found one with a size of 2 - | | - | help: consider specifying the actual array length: `2` + | ----------------------------- ^^^^^^^ expected an array with a size of 1, found one with a size of 2 + | | | + | | help: consider specifying the actual array length: `2` + | expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/consts/const-eval/array-len-mismatch-type.stderr b/tests/ui/consts/const-eval/array-len-mismatch-type.stderr index ce641f4a74b9c..915fc8e394b3c 100644 --- a/tests/ui/consts/const-eval/array-len-mismatch-type.stderr +++ b/tests/ui/consts/const-eval/array-len-mismatch-type.stderr @@ -4,6 +4,7 @@ error[E0308]: mismatched types LL | pub struct Data([[&'static str]; 5_i32]); | ^^^^^ expected `usize`, found `i32` | + = note: array length can only be `usize` help: change the type of the numeric literal from `i32` to `usize` | LL - pub struct Data([[&'static str]; 5_i32]); diff --git a/tests/ui/consts/const-eval/const-eval-span.rs b/tests/ui/consts/const-eval/const-eval-span.rs index f1904c76b6c15..1846da22cd3d4 100644 --- a/tests/ui/consts/const-eval/const-eval-span.rs +++ b/tests/ui/consts/const-eval/const-eval-span.rs @@ -7,8 +7,9 @@ const CONSTANT: S = S(0); enum E { V = CONSTANT, - //~^ ERROR mismatched types - //~| NOTE expected `isize`, found `S` + //~^ ERROR: mismatched types + //~| NOTE: expected `isize`, found `S` + //~| NOTE: enum variant discriminant } fn main() {} diff --git a/tests/ui/consts/const-eval/const-eval-span.stderr b/tests/ui/consts/const-eval/const-eval-span.stderr index ba11759a71061..ff17da5a04d72 100644 --- a/tests/ui/consts/const-eval/const-eval-span.stderr +++ b/tests/ui/consts/const-eval/const-eval-span.stderr @@ -3,6 +3,8 @@ error[E0308]: mismatched types | LL | V = CONSTANT, | ^^^^^^^^ expected `isize`, found `S` + | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-integer-bool-ops.rs b/tests/ui/consts/const-integer-bool-ops.rs index fbbd51adfe885..e1da3e750876a 100644 --- a/tests/ui/consts/const-integer-bool-ops.rs +++ b/tests/ui/consts/const-integer-bool-ops.rs @@ -5,6 +5,7 @@ const X: usize = 42 && 39; //~| NOTE expected `bool`, found integer //~| ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARR: [i32; X] = [99; 34]; const X1: usize = 42 || 39; @@ -14,6 +15,7 @@ const X1: usize = 42 || 39; //~| NOTE expected `bool`, found integer //~| ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARR1: [i32; X1] = [99; 47]; const X2: usize = -42 || -39; @@ -23,6 +25,7 @@ const X2: usize = -42 || -39; //~| NOTE expected `bool`, found integer //~| ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARR2: [i32; X2] = [99; 18446744073709551607]; const X3: usize = -42 && -39; @@ -32,36 +35,43 @@ const X3: usize = -42 && -39; //~| NOTE expected `bool`, found integer //~| ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARR3: [i32; X3] = [99; 6]; const Y: usize = 42.0 == 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR: [i32; Y] = [99; 1]; const Y1: usize = 42.0 >= 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR1: [i32; Y1] = [99; 1]; const Y2: usize = 42.0 <= 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR2: [i32; Y2] = [99; 1]; const Y3: usize = 42.0 > 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR3: [i32; Y3] = [99; 0]; const Y4: usize = 42.0 < 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR4: [i32; Y4] = [99; 0]; const Y5: usize = 42.0 != 42.0; //~^ ERROR mismatched types //~| NOTE expected `usize`, found `bool` +//~| NOTE expected because const ARRR5: [i32; Y5] = [99; 0]; fn main() { diff --git a/tests/ui/consts/const-integer-bool-ops.stderr b/tests/ui/consts/const-integer-bool-ops.stderr index 4e503e5a5c0a4..5212a5cfeb1ea 100644 --- a/tests/ui/consts/const-integer-bool-ops.stderr +++ b/tests/ui/consts/const-integer-bool-ops.stderr @@ -14,97 +14,117 @@ error[E0308]: mismatched types --> $DIR/const-integer-bool-ops.rs:1:18 | LL | const X: usize = 42 && 39; - | ^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:10:19 + --> $DIR/const-integer-bool-ops.rs:11:19 | LL | const X1: usize = 42 || 39; | ^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:10:25 + --> $DIR/const-integer-bool-ops.rs:11:25 | LL | const X1: usize = 42 || 39; | ^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:10:19 + --> $DIR/const-integer-bool-ops.rs:11:19 | LL | const X1: usize = 42 || 39; - | ^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:19:19 + --> $DIR/const-integer-bool-ops.rs:21:19 | LL | const X2: usize = -42 || -39; | ^^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:19:26 + --> $DIR/const-integer-bool-ops.rs:21:26 | LL | const X2: usize = -42 || -39; | ^^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:19:19 + --> $DIR/const-integer-bool-ops.rs:21:19 | LL | const X2: usize = -42 || -39; - | ^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:28:19 + --> $DIR/const-integer-bool-ops.rs:31:19 | LL | const X3: usize = -42 && -39; | ^^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:28:26 + --> $DIR/const-integer-bool-ops.rs:31:26 | LL | const X3: usize = -42 && -39; | ^^^ expected `bool`, found integer error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:28:19 + --> $DIR/const-integer-bool-ops.rs:31:19 | LL | const X3: usize = -42 && -39; - | ^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:37:18 + --> $DIR/const-integer-bool-ops.rs:41:18 | LL | const Y: usize = 42.0 == 42.0; - | ^^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:42:19 + --> $DIR/const-integer-bool-ops.rs:47:19 | LL | const Y1: usize = 42.0 >= 42.0; - | ^^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:47:19 + --> $DIR/const-integer-bool-ops.rs:53:19 | LL | const Y2: usize = 42.0 <= 42.0; - | ^^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:52:19 + --> $DIR/const-integer-bool-ops.rs:59:19 | LL | const Y3: usize = 42.0 > 42.0; - | ^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:57:19 + --> $DIR/const-integer-bool-ops.rs:65:19 | LL | const Y4: usize = 42.0 < 42.0; - | ^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:62:19 + --> $DIR/const-integer-bool-ops.rs:71:19 | LL | const Y5: usize = 42.0 != 42.0; - | ^^^^^^^^^^^^ expected `usize`, found `bool` + | ----- ^^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant error: aborting due to 18 previous errors diff --git a/tests/ui/consts/const-result-no-expect-suggestion.stderr b/tests/ui/consts/const-result-no-expect-suggestion.stderr index 70aa306ae3c88..337065f9f5e01 100644 --- a/tests/ui/consts/const-result-no-expect-suggestion.stderr +++ b/tests/ui/consts/const-result-no-expect-suggestion.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/const-result-no-expect-suggestion.rs:5:19 | LL | const TEST: u32 = f(2); - | ^^^^ expected `u32`, found `Result` + | --- ^^^^ expected `u32`, found `Result` + | | + | expected because of the type of the constant | = note: expected type `u32` found enum `Result` diff --git a/tests/ui/consts/const-slice-array-deref.stderr b/tests/ui/consts/const-slice-array-deref.stderr index b1d069280885d..e7513d01cd0e9 100644 --- a/tests/ui/consts/const-slice-array-deref.stderr +++ b/tests/ui/consts/const-slice-array-deref.stderr @@ -11,7 +11,9 @@ error[E0308]: mismatched types --> $DIR/const-slice-array-deref.rs:1:20 | LL | const ONE: [u16] = [1]; - | ^^^ expected `[u16]`, found `[u16; 1]` + | ----- ^^^ expected `[u16]`, found `[u16; 1]` + | | + | expected because of the type of the constant error[E0161]: cannot move a value of type `[u16]` --> $DIR/const-slice-array-deref.rs:5:28 diff --git a/tests/ui/consts/const-tup-index-span.rs b/tests/ui/consts/const-tup-index-span.rs index 4cb7143b4351f..6896625c3785f 100644 --- a/tests/ui/consts/const-tup-index-span.rs +++ b/tests/ui/consts/const-tup-index-span.rs @@ -1,9 +1,10 @@ // Test spans of errors const TUP: (usize,) = 5usize << 64; -//~^ ERROR mismatched types -//~| NOTE expected `(usize,)`, found `usize` -//~| NOTE expected tuple `(usize,)` +//~^ ERROR: mismatched types +//~| NOTE: expected `(usize,)`, found `usize` +//~| NOTE: expected tuple `(usize,)` +//~| NOTE: expected because const ARR: [i32; TUP.0] = []; fn main() { diff --git a/tests/ui/consts/const-tup-index-span.stderr b/tests/ui/consts/const-tup-index-span.stderr index 792e18aa8fd4b..fe42909618160 100644 --- a/tests/ui/consts/const-tup-index-span.stderr +++ b/tests/ui/consts/const-tup-index-span.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/const-tup-index-span.rs:3:23 | LL | const TUP: (usize,) = 5usize << 64; - | ^^^^^^^^^^^^ expected `(usize,)`, found `usize` + | -------- ^^^^^^^^^^^^ expected `(usize,)`, found `usize` + | | + | expected because of the type of the constant | = note: expected tuple `(usize,)` found type `usize` diff --git a/tests/ui/consts/const-type-mismatch.stderr b/tests/ui/consts/const-type-mismatch.stderr index 17bb27d4b72fa..d36ef1188f416 100644 --- a/tests/ui/consts/const-type-mismatch.stderr +++ b/tests/ui/consts/const-type-mismatch.stderr @@ -2,13 +2,17 @@ error[E0308]: mismatched types --> $DIR/const-type-mismatch.rs:4:21 | LL | const TWELVE: u16 = TEN + 2; - | ^^^^^^^ expected `u16`, found `u8` + | --- ^^^^^^^ expected `u16`, found `u8` + | | + | expected because of the type of the constant error[E0308]: mismatched types --> $DIR/const-type-mismatch.rs:9:27 | LL | const ALSO_TEN: u16 = TEN; - | ^^^ expected `u16`, found `u8` + | --- ^^^ expected `u16`, found `u8` + | | + | expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/consts/enum-discr-type-err.stderr b/tests/ui/consts/enum-discr-type-err.stderr index 9a09d6a96f1a0..c676a96ad34a0 100644 --- a/tests/ui/consts/enum-discr-type-err.stderr +++ b/tests/ui/consts/enum-discr-type-err.stderr @@ -10,6 +10,7 @@ LL | | B = T, LL | | } | |_- in this macro invocation | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types @@ -24,6 +25,7 @@ LL | | B = T, LL | | } | |_- in this macro invocation | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/consts/issue-104768.stderr b/tests/ui/consts/issue-104768.stderr index bd4a54de0ae45..81b4575b361b7 100644 --- a/tests/ui/consts/issue-104768.stderr +++ b/tests/ui/consts/issue-104768.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/issue-104768.rs:1:15 | LL | const A: &_ = 0_u32; - | ^^^^^ expected `&_`, found `u32` + | -- ^^^^^ expected `&_`, found `u32` + | | + | expected because of the type of the constant | = note: expected reference `&'static _` found type `u32` diff --git a/tests/ui/consts/issue-39974.rs b/tests/ui/consts/issue-39974.rs index adc65d9be0d04..7d9f1b6cf474c 100644 --- a/tests/ui/consts/issue-39974.rs +++ b/tests/ui/consts/issue-39974.rs @@ -1,11 +1,13 @@ const LENGTH: f64 = 2; -//~^ ERROR mismatched types -//~| NOTE expected `f64`, found integer +//~^ ERROR: mismatched types +//~| NOTE: expected `f64`, found integer +//~| NOTE: expected because struct Thing { f: [[f64; 2]; LENGTH], - //~^ ERROR mismatched types - //~| NOTE expected `usize`, found `f64` + //~^ ERROR: mismatched types + //~| NOTE: expected `usize`, found `f64` + //~| NOTE: array length } fn main() { diff --git a/tests/ui/consts/issue-39974.stderr b/tests/ui/consts/issue-39974.stderr index 1c15debb1199c..784a19445055a 100644 --- a/tests/ui/consts/issue-39974.stderr +++ b/tests/ui/consts/issue-39974.stderr @@ -1,14 +1,18 @@ error[E0308]: mismatched types - --> $DIR/issue-39974.rs:6:19 + --> $DIR/issue-39974.rs:7:19 | LL | f: [[f64; 2]; LENGTH], | ^^^^^^ expected `usize`, found `f64` + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/issue-39974.rs:1:21 | LL | const LENGTH: f64 = 2; - | ^ expected `f64`, found integer + | --- ^ expected `f64`, found integer + | | + | expected because of the type of the constant | help: use a float literal | diff --git a/tests/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr b/tests/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr index 7078b4bd7be1d..1210ae87642dd 100644 --- a/tests/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr +++ b/tests/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr @@ -3,12 +3,16 @@ error[E0308]: mismatched types | LL | const A: [(); 0.1] = [()]; | ^^^ expected `usize`, found floating-point number + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/issue-69310-array-size-lit-wrong-ty.rs:11:15 | LL | const B: [(); b"a"] = [()]; | ^^^^ expected `usize`, found `&[u8; 1]` + | + = note: array length can only be `usize` error: aborting due to 2 previous errors diff --git a/tests/ui/consts/nested_erroneous_ctfe.stderr b/tests/ui/consts/nested_erroneous_ctfe.stderr index db298246e7cf1..b13a6dca2b38c 100644 --- a/tests/ui/consts/nested_erroneous_ctfe.stderr +++ b/tests/ui/consts/nested_erroneous_ctfe.stderr @@ -6,6 +6,7 @@ LL | [9; || [9; []]]; | = note: expected type `usize` found array `[_; 0]` + = note: array length can only be `usize` error: aborting due to 1 previous error diff --git a/tests/ui/consts/promoted-type-error-issue-133968.stderr b/tests/ui/consts/promoted-type-error-issue-133968.stderr index 24f1268e4b6e9..a6f67a2056da7 100644 --- a/tests/ui/consts/promoted-type-error-issue-133968.stderr +++ b/tests/ui/consts/promoted-type-error-issue-133968.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/promoted-type-error-issue-133968.rs:4:29 | LL | static STR: &'static [u8] = "a b"; - | ^^^^^ expected `&[u8]`, found `&str` + | ------------- ^^^^^ expected `&[u8]`, found `&str` + | | + | expected because of the type of the static | = note: expected reference `&'static [u8]` found reference `&'static str` diff --git a/tests/ui/diagnostic-width/long-span.long.stderr b/tests/ui/diagnostic-width/long-span.long.stderr index 252b17912dee2..526719678afeb 100644 --- a/tests/ui/diagnostic-width/long-span.long.stderr +++ b/tests/ui/diagnostic-width/long-span.long.stderr @@ -9,8 +9,10 @@ LL │ …u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, …, 0, 0, 0, 0, 0, 0, 0] + [0, 0, 0, error[E0308]: mismatched types ╭▸ $DIR/long-span.rs:9:15 │ -LL │ …u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, …, 0, 0, 0, 0, 0, 0, 0]; - ╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━…━━━━━━━━━━━━━━━━━━━━━━ expected `u8`, found `[{integer}; 1680]` +LL │ …t D: u8 = [0, 0, 0, 0, 0, 0, 0, 0… 0, 0, 0, 0, 0, 0, 0, 0, 0]; + │ ┬─ ━━━━━━━━━━━━━━━━━━━━━━━…━━━━━━━━━━━━━━━━━━━━━━━━━━━ expected `u8`, found `[{integer}; 1680]` + │ │ + ╰╴ expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/diagnostic-width/long-span.longest.stderr b/tests/ui/diagnostic-width/long-span.longest.stderr index 2e77c36892231..0b1ca9a22fd6d 100644 --- a/tests/ui/diagnostic-width/long-span.longest.stderr +++ b/tests/ui/diagnostic-width/long-span.longest.stderr @@ -9,8 +9,10 @@ LL | ... = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0, 0, 0, 0, 0, 0, 0, 0, 0 error[E0308]: mismatched types --> $DIR/long-span.rs:9:15 | -LL | ... = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `[{integer}; 1680]` +LL | ...D: u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,..., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `[{integer}; 1680]` + | | + | expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/diagnostic-width/long-span.short.stderr b/tests/ui/diagnostic-width/long-span.short.stderr index b4803e31aaab8..bd86a048c434f 100644 --- a/tests/ui/diagnostic-width/long-span.short.stderr +++ b/tests/ui/diagnostic-width/long-span.short.stderr @@ -9,8 +9,10 @@ LL │ …u8 = [0, 0, 0…0] + [0, 0, 0…0]; error[E0308]: mismatched types ╭▸ $DIR/long-span.rs:9:15 │ -LL │ …u8 = [0, 0, 0…0]; - ╰╴ ━━━━━━━━…━━ expected `u8`, found `[{integer}; 1680]` +LL │ …t D: u8 = [0,…, 0, 0]; + │ ┬─ ━━━…━━━━━━━ expected `u8`, found `[{integer}; 1680]` + │ │ + ╰╴ expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/diagnostic-width/long-span.shortest.stderr b/tests/ui/diagnostic-width/long-span.shortest.stderr index 1de1a4acd9291..4d9e413287b65 100644 --- a/tests/ui/diagnostic-width/long-span.shortest.stderr +++ b/tests/ui/diagnostic-width/long-span.shortest.stderr @@ -9,8 +9,10 @@ LL | ... = [0, 0, 0...0] + [0, 0, 0...0]; error[E0308]: mismatched types --> $DIR/long-span.rs:9:15 | -LL | ... = [0, 0, 0...0]; - | ^^^^^^^^...^^ expected `u8`, found `[{integer}; 1680]` +LL | ...D: u8 = [0,..., 0, 0]; + | -- ^^^...^^^^^^^ expected `u8`, found `[{integer}; 1680]` + | | + | expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/did_you_mean/brackets-to-braces-single-element.stderr b/tests/ui/did_you_mean/brackets-to-braces-single-element.stderr index d4aeb1eee96a1..83a34e2bcd076 100644 --- a/tests/ui/did_you_mean/brackets-to-braces-single-element.stderr +++ b/tests/ui/did_you_mean/brackets-to-braces-single-element.stderr @@ -14,7 +14,9 @@ error[E0308]: mismatched types --> $DIR/brackets-to-braces-single-element.rs:4:19 | LL | const B: &[u32] = &{ 1 }; - | ^^^^^^ expected `&[u32]`, found `&{integer}` + | ------ ^^^^^^ expected `&[u32]`, found `&{integer}` + | | + | expected because of the type of the constant | = note: expected reference `&'static [u32]` found reference `&{integer}` diff --git a/tests/ui/enum-discriminant/discriminant-ill-typed.rs b/tests/ui/enum-discriminant/discriminant-ill-typed.rs index e3cbd01a1ddf7..1e456425cdd8b 100644 --- a/tests/ui/enum-discriminant/discriminant-ill-typed.rs +++ b/tests/ui/enum-discriminant/discriminant-ill-typed.rs @@ -13,8 +13,9 @@ fn f_i8() { Ok = i8::MAX - 1, Ok2, OhNo = 0_u8, - //~^ ERROR mismatched types - //~| NOTE expected `i8`, found `u8` + //~^ ERROR: mismatched types + //~| NOTE: expected `i8`, found `u8` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -26,8 +27,9 @@ fn f_u8() { Ok = u8::MAX - 1, Ok2, OhNo = 0_i8, - //~^ ERROR mismatched types - //~| NOTE expected `u8`, found `i8` + //~^ ERROR: mismatched types + //~| NOTE: expected `u8`, found `i8` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -39,8 +41,9 @@ fn f_i16() { Ok = i16::MAX - 1, Ok2, OhNo = 0_u16, - //~^ ERROR mismatched types - //~| NOTE expected `i16`, found `u16` + //~^ ERROR: mismatched types + //~| NOTE: expected `i16`, found `u16` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -52,8 +55,9 @@ fn f_u16() { Ok = u16::MAX - 1, Ok2, OhNo = 0_i16, - //~^ ERROR mismatched types - //~| NOTE expected `u16`, found `i16` + //~^ ERROR: mismatched types + //~| NOTE: expected `u16`, found `i16` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -65,8 +69,9 @@ fn f_i32() { Ok = i32::MAX - 1, Ok2, OhNo = 0_u32, - //~^ ERROR mismatched types - //~| NOTE expected `i32`, found `u32` + //~^ ERROR: mismatched types + //~| NOTE: expected `i32`, found `u32` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -78,8 +83,9 @@ fn f_u32() { Ok = u32::MAX - 1, Ok2, OhNo = 0_i32, - //~^ ERROR mismatched types - //~| NOTE expected `u32`, found `i32` + //~^ ERROR: mismatched types + //~| NOTE: expected `u32`, found `i32` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -91,8 +97,9 @@ fn f_i64() { Ok = i64::MAX - 1, Ok2, OhNo = 0_u64, - //~^ ERROR mismatched types - //~| NOTE expected `i64`, found `u64` + //~^ ERROR: mismatched types + //~| NOTE: expected `i64`, found `u64` + //~| NOTE: enum variant discriminant } let x = A::Ok; @@ -104,8 +111,9 @@ fn f_u64() { Ok = u64::MAX - 1, Ok2, OhNo = 0_i64, - //~^ ERROR mismatched types - //~| NOTE expected `u64`, found `i64` + //~^ ERROR: mismatched types + //~| NOTE: expected `u64`, found `i64` + //~| NOTE: enum variant discriminant } let x = A::Ok; diff --git a/tests/ui/enum-discriminant/discriminant-ill-typed.stderr b/tests/ui/enum-discriminant/discriminant-ill-typed.stderr index e9508b7fe962d..794447295320e 100644 --- a/tests/ui/enum-discriminant/discriminant-ill-typed.stderr +++ b/tests/ui/enum-discriminant/discriminant-ill-typed.stderr @@ -4,6 +4,7 @@ error[E0308]: mismatched types LL | OhNo = 0_u8, | ^^^^ expected `i8`, found `u8` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `u8` to `i8` | LL - OhNo = 0_u8, @@ -11,11 +12,12 @@ LL + OhNo = 0_i8, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:28:16 + --> $DIR/discriminant-ill-typed.rs:29:16 | LL | OhNo = 0_i8, | ^^^^ expected `u8`, found `i8` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `i8` to `u8` | LL - OhNo = 0_i8, @@ -23,11 +25,12 @@ LL + OhNo = 0_u8, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:41:16 + --> $DIR/discriminant-ill-typed.rs:43:16 | LL | OhNo = 0_u16, | ^^^^^ expected `i16`, found `u16` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `u16` to `i16` | LL - OhNo = 0_u16, @@ -35,11 +38,12 @@ LL + OhNo = 0_i16, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:54:16 + --> $DIR/discriminant-ill-typed.rs:57:16 | LL | OhNo = 0_i16, | ^^^^^ expected `u16`, found `i16` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `i16` to `u16` | LL - OhNo = 0_i16, @@ -47,11 +51,12 @@ LL + OhNo = 0_u16, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:67:16 + --> $DIR/discriminant-ill-typed.rs:71:16 | LL | OhNo = 0_u32, | ^^^^^ expected `i32`, found `u32` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `u32` to `i32` | LL - OhNo = 0_u32, @@ -59,11 +64,12 @@ LL + OhNo = 0_i32, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:80:16 + --> $DIR/discriminant-ill-typed.rs:85:16 | LL | OhNo = 0_i32, | ^^^^^ expected `u32`, found `i32` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `i32` to `u32` | LL - OhNo = 0_i32, @@ -71,11 +77,12 @@ LL + OhNo = 0_u32, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:93:16 + --> $DIR/discriminant-ill-typed.rs:99:16 | LL | OhNo = 0_u64, | ^^^^^ expected `i64`, found `u64` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `u64` to `i64` | LL - OhNo = 0_u64, @@ -83,11 +90,12 @@ LL + OhNo = 0_i64, | error[E0308]: mismatched types - --> $DIR/discriminant-ill-typed.rs:106:16 + --> $DIR/discriminant-ill-typed.rs:113:16 | LL | OhNo = 0_i64, | ^^^^^ expected `u64`, found `i64` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `i64` to `u64` | LL - OhNo = 0_i64, diff --git a/tests/ui/enum/closure-in-enum-issue-48838.stderr b/tests/ui/enum/closure-in-enum-issue-48838.stderr index 17e6c3433343f..6c84efe73e42b 100644 --- a/tests/ui/enum/closure-in-enum-issue-48838.stderr +++ b/tests/ui/enum/closure-in-enum-issue-48838.stderr @@ -6,6 +6,7 @@ LL | Square = |x| x, | = note: expected type `isize` found closure `{closure@$DIR/closure-in-enum-issue-48838.rs:2:14: 2:17}` + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` error: aborting due to 1 previous error diff --git a/tests/ui/enum/enum-discriminant-type-mismatch-8761.rs b/tests/ui/enum/enum-discriminant-type-mismatch-8761.rs index ae09b919dc152..63973be837747 100644 --- a/tests/ui/enum/enum-discriminant-type-mismatch-8761.rs +++ b/tests/ui/enum/enum-discriminant-type-mismatch-8761.rs @@ -1,11 +1,13 @@ // https://github.com/rust-lang/rust/issues/8761 enum Foo { A = 1i64, - //~^ ERROR mismatched types - //~| NOTE expected `isize`, found `i64` + //~^ ERROR: mismatched types + //~| NOTE: expected `isize`, found `i64` + //~| NOTE: enum variant discriminant B = 2u8 - //~^ ERROR mismatched types - //~| NOTE expected `isize`, found `u8` + //~^ ERROR: mismatched types + //~| NOTE: expected `isize`, found `u8` + //~| NOTE: enum variant discriminant } fn main() {} diff --git a/tests/ui/enum/enum-discriminant-type-mismatch-8761.stderr b/tests/ui/enum/enum-discriminant-type-mismatch-8761.stderr index f1645183e176b..d256a2ed644b5 100644 --- a/tests/ui/enum/enum-discriminant-type-mismatch-8761.stderr +++ b/tests/ui/enum/enum-discriminant-type-mismatch-8761.stderr @@ -4,6 +4,7 @@ error[E0308]: mismatched types LL | A = 1i64, | ^^^^ expected `isize`, found `i64` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `i64` to `isize` | LL - A = 1i64, @@ -11,11 +12,12 @@ LL + A = 1isize, | error[E0308]: mismatched types - --> $DIR/enum-discriminant-type-mismatch-8761.rs:6:9 + --> $DIR/enum-discriminant-type-mismatch-8761.rs:7:9 | LL | B = 2u8 | ^^^ expected `isize`, found `u8` | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` help: change the type of the numeric literal from `u8` to `isize` | LL - B = 2u8 diff --git a/tests/ui/generic-const-items/assoc-const-missing-type.stderr b/tests/ui/generic-const-items/assoc-const-missing-type.stderr index 7c79133d64ec3..b7fb625a9ea53 100644 --- a/tests/ui/generic-const-items/assoc-const-missing-type.stderr +++ b/tests/ui/generic-const-items/assoc-const-missing-type.stderr @@ -2,8 +2,9 @@ error[E0308]: mismatched types --> $DIR/assoc-const-missing-type.rs:12:18 | LL | const K = (); - | - ^^ expected type parameter `T`, found `()` - | | + | - - ^^ expected type parameter `T`, found `()` + | | | + | | expected because of the type of the associated constant | expected this type parameter | = note: expected type parameter `T` diff --git a/tests/ui/generics/generic-struct-self-unconstrained-inference-vars-69306.stderr b/tests/ui/generics/generic-struct-self-unconstrained-inference-vars-69306.stderr index f2fd4340a5804..8bc0f0a5e92fd 100644 --- a/tests/ui/generics/generic-struct-self-unconstrained-inference-vars-69306.stderr +++ b/tests/ui/generics/generic-struct-self-unconstrained-inference-vars-69306.stderr @@ -22,7 +22,9 @@ error[E0308]: mismatched types LL | impl S0 { | - found this type parameter LL | const C: S0 = Self(0); - | ^^^^^^^ expected `S0`, found `S0` + | ------ ^^^^^^^ expected `S0`, found `S0` + | | + | expected because of the type of the associated constant | = note: expected struct `S0` found struct `S0` @@ -89,7 +91,9 @@ error[E0308]: mismatched types LL | impl S1 { | - found this type parameter LL | const C: S1 = Self(0, 1); - | ^^^^^^^^^^ expected `S1`, found `S1` + | ---------- ^^^^^^^^^^ expected `S1`, found `S1` + | | + | expected because of the type of the associated constant | = note: expected struct `S1` found struct `S1` diff --git a/tests/ui/issues/issue-31910.rs b/tests/ui/issues/issue-31910.rs index fc82fda0ccd87..697bbf6fe6d12 100644 --- a/tests/ui/issues/issue-31910.rs +++ b/tests/ui/issues/issue-31910.rs @@ -1,9 +1,10 @@ enum Enum { - //~^ ERROR `T` is never used - //~| NOTE unused type parameter + //~^ ERROR: `T` is never used + //~| NOTE: unused type parameter X = Trait::Number, - //~^ ERROR mismatched types - //~| NOTE expected `isize`, found `i32` + //~^ ERROR: mismatched types + //~| NOTE: expected `isize`, found `i32` + //~| NOTE: enum variant discriminant } trait Trait { diff --git a/tests/ui/issues/issue-31910.stderr b/tests/ui/issues/issue-31910.stderr index 56e4cee53d63e..765db15e8285c 100644 --- a/tests/ui/issues/issue-31910.stderr +++ b/tests/ui/issues/issue-31910.stderr @@ -3,6 +3,8 @@ error[E0308]: mismatched types | LL | X = Trait::Number, | ^^^^^^^^^^^^^ expected `isize`, found `i32` + | + = note: enum variant discriminant can only be of a primitive type compatible with the enum's `repr` error[E0392]: type parameter `T` is never used --> $DIR/issue-31910.rs:1:11 diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 7f44ab2ed6b43..1ce50903ff10c 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -37,6 +37,8 @@ error[E0308]: mismatched types | LL | fn a() -> [u8; foo()] { | ^^^^^ expected `usize`, found `()` + | + = note: array length can only be `usize` error: aborting due to 6 previous errors diff --git a/tests/ui/mismatched_types/array-len-is-closure.stderr b/tests/ui/mismatched_types/array-len-is-closure.stderr index db5d801871bc5..a6f9518c3e63b 100644 --- a/tests/ui/mismatched_types/array-len-is-closure.stderr +++ b/tests/ui/mismatched_types/array-len-is-closure.stderr @@ -6,6 +6,7 @@ LL | [1; || {}]; | = note: expected type `usize` found closure `{closure@$DIR/array-len-is-closure.rs:4:9: 4:11}` + = note: array length can only be `usize` error: aborting due to 1 previous error diff --git a/tests/ui/mismatched_types/array-repeat-unit-struct.rs b/tests/ui/mismatched_types/array-repeat-unit-struct.rs index db05e1daedbd1..f92f97ed587ba 100644 --- a/tests/ui/mismatched_types/array-repeat-unit-struct.rs +++ b/tests/ui/mismatched_types/array-repeat-unit-struct.rs @@ -4,6 +4,7 @@ struct S; fn main() { let b = [0; S]; - //~^ ERROR mismatched types - //~| NOTE expected `usize`, found `S` + //~^ ERROR: mismatched types + //~| NOTE: expected `usize`, found `S` + //~| NOTE: array length } diff --git a/tests/ui/mismatched_types/array-repeat-unit-struct.stderr b/tests/ui/mismatched_types/array-repeat-unit-struct.stderr index 9a9cc946f82a1..155adb5363a2e 100644 --- a/tests/ui/mismatched_types/array-repeat-unit-struct.stderr +++ b/tests/ui/mismatched_types/array-repeat-unit-struct.stderr @@ -3,6 +3,8 @@ error[E0308]: mismatched types | LL | let b = [0; S]; | ^ expected `usize`, found `S` + | + = note: array length can only be `usize` error: aborting due to 1 previous error diff --git a/tests/ui/never_type/regress/loop-in-array-length.stderr b/tests/ui/never_type/regress/loop-in-array-length.stderr index a51eb46fb244a..fc0a670d08dc5 100644 --- a/tests/ui/never_type/regress/loop-in-array-length.stderr +++ b/tests/ui/never_type/regress/loop-in-array-length.stderr @@ -14,6 +14,7 @@ LL | [(); & { loop { continue } } ]; | = note: expected type `usize` found reference `&_` + = note: array length can only be `usize` help: consider removing the borrow | LL - [(); & { loop { continue } } ]; diff --git a/tests/ui/numeric/const-scope.stderr b/tests/ui/numeric/const-scope.stderr index 2c8d4da9d2182..4851a20fcf0ee 100644 --- a/tests/ui/numeric/const-scope.stderr +++ b/tests/ui/numeric/const-scope.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/const-scope.rs:1:16 | LL | const C: i32 = 1i8; - | ^^^ expected `i32`, found `i8` + | --- ^^^ expected `i32`, found `i8` + | | + | expected because of the type of the constant | help: change the type of the numeric literal from `i8` to `i32` | @@ -14,7 +16,9 @@ error[E0308]: mismatched types --> $DIR/const-scope.rs:2:15 | LL | const D: i8 = C; - | ^ expected `i8`, found `i32` + | -- ^ expected `i8`, found `i32` + | | + | expected because of the type of the constant error[E0308]: mismatched types --> $DIR/const-scope.rs:5:18 diff --git a/tests/ui/parser/pat-lt-bracket-6.stderr b/tests/ui/parser/pat-lt-bracket-6.stderr index 83c88d1085ef8..6f91967b8b82a 100644 --- a/tests/ui/parser/pat-lt-bracket-6.stderr +++ b/tests/ui/parser/pat-lt-bracket-6.stderr @@ -24,7 +24,9 @@ error[E0308]: mismatched types --> $DIR/pat-lt-bracket-6.rs:10:30 | LL | const RECOVERY_WITNESS: () = 0; - | ^ expected `()`, found integer + | -- ^ expected `()`, found integer + | | + | expected because of the type of the constant error: aborting due to 3 previous errors diff --git a/tests/ui/parser/pat-lt-bracket-7.stderr b/tests/ui/parser/pat-lt-bracket-7.stderr index cc457a4e64e24..5cdb94cb8176a 100644 --- a/tests/ui/parser/pat-lt-bracket-7.stderr +++ b/tests/ui/parser/pat-lt-bracket-7.stderr @@ -11,7 +11,9 @@ error[E0308]: mismatched types --> $DIR/pat-lt-bracket-7.rs:9:30 | LL | const RECOVERY_WITNESS: () = 0; - | ^ expected `()`, found integer + | -- ^ expected `()`, found integer + | | + | expected because of the type of the constant error: aborting due to 2 previous errors diff --git a/tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr b/tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr index 2bc7952def79b..8b784d02a01d3 100644 --- a/tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr +++ b/tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr @@ -14,7 +14,9 @@ error[E0308]: mismatched types --> $DIR/recover-for-loop-parens-around-head.rs:13:40 | LL | const _RECOVERY_WITNESS: u32 = 0u8; - | ^^^ expected `u32`, found `u8` + | --- ^^^ expected `u32`, found `u8` + | | + | expected because of the type of the constant | help: change the type of the numeric literal from `u8` to `u32` | diff --git a/tests/ui/proc-macro/macro-brackets.stderr b/tests/ui/proc-macro/macro-brackets.stderr index f14b5fed6b9eb..00c1c6b0f4cf3 100644 --- a/tests/ui/proc-macro/macro-brackets.stderr +++ b/tests/ui/proc-macro/macro-brackets.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/macro-brackets.rs:11:21 | LL | id![static X: u32 = 'a';]; - | ^^^ expected `u32`, found `char` + | --- ^^^ expected `u32`, found `char` + | | + | expected because of the type of the static | help: you can cast a `char` to a `u32`, since a `char` always occupies 4 bytes | diff --git a/tests/ui/repeat-expr/repeat_count.stderr b/tests/ui/repeat-expr/repeat_count.stderr index eb9581b8f7ae4..e2cecf9973b8b 100644 --- a/tests/ui/repeat-expr/repeat_count.stderr +++ b/tests/ui/repeat-expr/repeat_count.stderr @@ -15,24 +15,32 @@ error[E0308]: mismatched types | LL | let b = [0; ()]; | ^^ expected `usize`, found `()` + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:12:17 | LL | let c = [0; true]; | ^^^^ expected `usize`, found `bool` + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:15:17 | LL | let d = [0; 0.5]; | ^^^ expected `usize`, found floating-point number + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:18:17 | LL | let e = [0; "foo"]; | ^^^^^ expected `usize`, found `&str` + | + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:21:17 @@ -41,6 +49,7 @@ LL | let f = [0; -4_isize]; | ^^^^^^^^ expected `usize`, found `isize` | = note: `-4_isize` cannot fit into type `usize` + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:25:23 @@ -49,6 +58,7 @@ LL | let g = [0_usize; -1_isize]; | ^^^^^^^^ expected `usize`, found `isize` | = note: `-1_isize` cannot fit into type `usize` + = note: array length can only be `usize` error[E0308]: mismatched types --> $DIR/repeat_count.rs:29:17 @@ -56,6 +66,7 @@ error[E0308]: mismatched types LL | let h = [0; 4u8]; | ^^^ expected `usize`, found `u8` | + = note: array length can only be `usize` help: change the type of the numeric literal from `u8` to `usize` | LL - let h = [0; 4u8]; @@ -67,6 +78,8 @@ error[E0308]: mismatched types | LL | let i = [0; I { i: () }]; | ^^^^^^^^^^^ expected `usize`, found `I` + | + = note: array length can only be `usize` error: aborting due to 9 previous errors diff --git a/tests/ui/self/issue-61882.stderr b/tests/ui/self/issue-61882.stderr index 96f4e41de174b..867e3e97ac374 100644 --- a/tests/ui/self/issue-61882.stderr +++ b/tests/ui/self/issue-61882.stderr @@ -16,7 +16,9 @@ error[E0308]: mismatched types --> $DIR/issue-61882.rs:4:22 | LL | const B: A = Self(0); - | ^^^^^^^ expected `A`, found `A` + | ----- ^^^^^^^ expected `A`, found `A` + | | + | expected because of the type of the associated constant | = note: expected struct `A` found struct `A` diff --git a/tests/ui/static/bad-const-type.rs b/tests/ui/static/bad-const-type.rs index d4e6352d7c1c9..696fa295af419 100644 --- a/tests/ui/static/bad-const-type.rs +++ b/tests/ui/static/bad-const-type.rs @@ -1,4 +1,5 @@ static i: String = 10; -//~^ ERROR mismatched types -//~| NOTE expected `String`, found integer +//~^ ERROR: mismatched types +//~| NOTE: expected `String`, found integer +//~| NOTE: expected because fn main() { println!("{}", i); } diff --git a/tests/ui/static/bad-const-type.stderr b/tests/ui/static/bad-const-type.stderr index 8573a11ef2912..12ecb73d94daf 100644 --- a/tests/ui/static/bad-const-type.stderr +++ b/tests/ui/static/bad-const-type.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/bad-const-type.rs:1:20 | LL | static i: String = 10; - | ^^ expected `String`, found integer + | ------ ^^ expected `String`, found integer + | | + | expected because of the type of the static | help: try using a conversion method | diff --git a/tests/ui/static/issue-5216.stderr b/tests/ui/static/issue-5216.stderr index 99c8b1aa131a7..9748223e3d1df 100644 --- a/tests/ui/static/issue-5216.stderr +++ b/tests/ui/static/issue-5216.stderr @@ -18,7 +18,9 @@ error[E0308]: mismatched types --> $DIR/issue-5216.rs:8:19 | LL | pub static D: T = g; - | ^ expected `Box`, found fn item + | - ^ expected `Box`, found fn item + | | + | expected because of the type of the static | = note: expected struct `Box<(dyn FnMut() + Sync + 'static)>` found fn item `fn() {g}` diff --git a/tests/ui/transmutability/arrays/issue-103783-array-length.stderr b/tests/ui/transmutability/arrays/issue-103783-array-length.stderr index 02ac40741cb7f..18f6e9b4ed108 100644 --- a/tests/ui/transmutability/arrays/issue-103783-array-length.stderr +++ b/tests/ui/transmutability/arrays/issue-103783-array-length.stderr @@ -3,6 +3,8 @@ error[E0308]: mismatched types | LL | type NaughtyLenArray = [u32; 3.14159]; | ^^^^^^^ expected `usize`, found floating-point number + | + = note: array length can only be `usize` error: aborting due to 1 previous error diff --git a/tests/ui/type/pattern_types/nested.stderr b/tests/ui/type/pattern_types/nested.stderr index 7893cc8492484..cb491a78945cf 100644 --- a/tests/ui/type/pattern_types/nested.stderr +++ b/tests/ui/type/pattern_types/nested.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/nested.rs:10:63 | LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); - | ^ expected `(u32) is 1..`, found integer + | ------------------------- ^ expected `(u32) is 1..`, found integer + | | + | the pattern must match the type | = note: expected pattern type `(u32) is 1..` found type `{integer}` diff --git a/tests/ui/type/pattern_types/pattern_type_mismatch.stderr b/tests/ui/type/pattern_types/pattern_type_mismatch.stderr index 4af92a89c445a..129e4b5cdc7be 100644 --- a/tests/ui/type/pattern_types/pattern_type_mismatch.stderr +++ b/tests/ui/type/pattern_types/pattern_type_mismatch.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/pattern_type_mismatch.rs:8:41 | LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); - | ^^^ expected `u8`, found `char` + | -- ^^^ expected `u8`, found `char` + | | + | the pattern must match the type | help: if you meant to write a byte literal, prefix with `b` | @@ -13,7 +15,9 @@ error[E0308]: mismatched types --> $DIR/pattern_type_mismatch.rs:8:47 | LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); - | ^^^ expected `u8`, found `char` + | -- ^^^ expected `u8`, found `char` + | | + | the pattern must match the type | help: if you meant to write a byte literal, prefix with `b` | @@ -24,13 +28,17 @@ error[E0308]: mismatched types --> $DIR/pattern_type_mismatch.rs:12:43 | LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); - | ^ expected `char`, found `u8` + | ---- ^ expected `char`, found `u8` + | | + | the pattern must match the type error[E0308]: mismatched types --> $DIR/pattern_type_mismatch.rs:12:47 | LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); - | ^ expected `char`, found `u8` + | ---- ^ expected `char`, found `u8` + | | + | the pattern must match the type error: aborting due to 4 previous errors diff --git a/tests/ui/wf/range-expr-root-of-constant-issue-40749.rs b/tests/ui/wf/range-expr-root-of-constant-issue-40749.rs index bec92448d1c8c..07e4b9addaa14 100644 --- a/tests/ui/wf/range-expr-root-of-constant-issue-40749.rs +++ b/tests/ui/wf/range-expr-root-of-constant-issue-40749.rs @@ -1,9 +1,11 @@ fn main() { [0; ..10]; - //~^ ERROR mismatched types - //~| NOTE expected type `usize` - //~| NOTE found struct `RangeTo<{integer}>` - //~| NOTE expected `usize`, found `RangeTo<{integer}> - //~| NOTE in this expansion of desugaring of range expression - //~| NOTE in this expansion of desugaring of range expression + //~^ ERROR: mismatched types + //~| NOTE: expected type `usize` + //~| NOTE: found struct `RangeTo<{integer}>` + //~| NOTE: expected `usize`, found `RangeTo<{integer}> + //~| NOTE: array length can only be `usize` + //~| NOTE: in this expansion of desugaring of range expression + //~| NOTE: in this expansion of desugaring of range expression + //~| NOTE: in this expansion of desugaring of range expression } diff --git a/tests/ui/wf/range-expr-root-of-constant-issue-40749.stderr b/tests/ui/wf/range-expr-root-of-constant-issue-40749.stderr index 482773a39440f..daddbe9fa4697 100644 --- a/tests/ui/wf/range-expr-root-of-constant-issue-40749.stderr +++ b/tests/ui/wf/range-expr-root-of-constant-issue-40749.stderr @@ -6,6 +6,7 @@ LL | [0; ..10]; | = note: expected type `usize` found struct `RangeTo<{integer}>` + = note: array length can only be `usize` error: aborting due to 1 previous error From 2e4a420db08a0bb5a43834227aef532a9de3b3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 18:02:00 +0000 Subject: [PATCH 02/12] Explain that default field values aren't compatible with type parameters unless going through the type parameter ``` error[E0308]: mismatched types --> $DIR/struct-type-parameter-with-default.rs:5:12 | LL | struct Foo { | ---------- expected this type parameter LL | x: T = String::new(), | ^^^^^^^^^^^^^ expected type parameter `T`, found `String` | = note: expected type parameter `T` found struct `String` = note: the type of default fields referencing type parameters can't be assumed inside the struct defining them ``` --- compiler/rustc_hir_typeck/src/lib.rs | 18 ++++++++++++++++-- .../struct-type-parameter-with-default.rs | 11 +++++++++++ .../struct-type-parameter-with-default.stderr | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/ui/structs/default-field-values/struct-type-parameter-with-default.rs create mode 100644 tests/ui/structs/default-field-values/struct-type-parameter-with-default.stderr diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 200cef49f35d6..734e5136f8806 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -205,7 +205,7 @@ fn typeck_with_inspect<'tcx>( } fcx.check_expr_coercible_to_type_or_error(body.value, expected_type, None, |err, _| { - extend_err_with_const_context(err, tcx, node); + extend_err_with_const_context(err, tcx, node, expected_type); }); fcx.write_ty(id, expected_type); @@ -276,7 +276,12 @@ fn typeck_with_inspect<'tcx>( typeck_results } -fn extend_err_with_const_context(err: &mut Diag<'_>, tcx: TyCtxt<'_>, node: hir::Node<'_>) { +fn extend_err_with_const_context( + err: &mut Diag<'_>, + tcx: TyCtxt<'_>, + node: hir::Node<'_>, + expected_ty: Ty<'_>, +) { match node { hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), .. }) | hir::Node::TraitItem(hir::TraitItem { @@ -378,6 +383,15 @@ fn extend_err_with_const_context(err: &mut Diag<'_>, tcx: TyCtxt<'_>, node: hir: // Point at `char` in `pattern_type!(char is 1..=1)`. err.span_label(ty.span, "the pattern must match the type"); } + hir::Node::AnonConst(anon) + if let hir::Node::Field(_) = tcx.parent_hir_node(anon.hir_id) + && let ty::Param(_) = expected_ty.kind() => + { + err.note( + "the type of default fields referencing type parameters can't be assumed inside \ + the struct defining them", + ); + } _ => {} } } diff --git a/tests/ui/structs/default-field-values/struct-type-parameter-with-default.rs b/tests/ui/structs/default-field-values/struct-type-parameter-with-default.rs new file mode 100644 index 0000000000000..c9e5aa9afb41f --- /dev/null +++ b/tests/ui/structs/default-field-values/struct-type-parameter-with-default.rs @@ -0,0 +1,11 @@ +// Test for #147748, providing additional clarification that default field values aren't compatible +// with type parameters unless going through the type parameter. +#![feature(default_field_values)] +struct Foo { //~ NOTE: expected this type parameter + x: T = String::new(), + //~^ ERROR: mismatched types + //~| NOTE: expected type parameter + //~| NOTE: expected type parameter + //~| NOTE: the type of default fields referencing type parameters can't be assumed inside the struct defining them +} +fn main() {} diff --git a/tests/ui/structs/default-field-values/struct-type-parameter-with-default.stderr b/tests/ui/structs/default-field-values/struct-type-parameter-with-default.stderr new file mode 100644 index 0000000000000..553b49023835f --- /dev/null +++ b/tests/ui/structs/default-field-values/struct-type-parameter-with-default.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/struct-type-parameter-with-default.rs:5:12 + | +LL | struct Foo { + | ---------- expected this type parameter +LL | x: T = String::new(), + | ^^^^^^^^^^^^^ expected type parameter `T`, found `String` + | + = note: expected type parameter `T` + found struct `String` + = note: the type of default fields referencing type parameters can't be assumed inside the struct defining them + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. From 724c1a02e11e3b7d3f18a99bea11d450ebd82c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 19:15:56 +0000 Subject: [PATCH 03/12] Update rustdoc-ui test --- tests/rustdoc-ui/track-diagnostics.rs | 1 + tests/rustdoc-ui/track-diagnostics.stderr | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/rustdoc-ui/track-diagnostics.rs b/tests/rustdoc-ui/track-diagnostics.rs index f8e710659a5c8..6a5d1b53b3c7f 100644 --- a/tests/rustdoc-ui/track-diagnostics.rs +++ b/tests/rustdoc-ui/track-diagnostics.rs @@ -11,3 +11,4 @@ pub const S: A = B; //~^ ERROR mismatched types //~| NOTE created at //~| NOTE expected `A`, found `B` +//~| NOTE expected because of the type of the const diff --git a/tests/rustdoc-ui/track-diagnostics.stderr b/tests/rustdoc-ui/track-diagnostics.stderr index a25fd2862aaf0..c7dfe07c596f4 100644 --- a/tests/rustdoc-ui/track-diagnostics.stderr +++ b/tests/rustdoc-ui/track-diagnostics.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/track-diagnostics.rs:LL:CC | LL | pub const S: A = B; - | ^ expected `A`, found `B` + | - ^ expected `A`, found `B` + | | + | expected because of the type of the constant | = note: -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs:LL:CC From ff0ce4f5fa83a03082ed6efb3f0088dcd935be92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 20:12:18 +0000 Subject: [PATCH 04/12] Make some suggestions verbose --- compiler/rustc_trait_selection/src/errors.rs | 9 ++++++--- .../consts/array-literal-len-mismatch.stderr | 9 +++++++-- tests/ui/consts/const-array-oob-arith.stderr | 18 ++++++++++++++---- tests/ui/inference/array-len-mismatch.stderr | 18 ++++++++++++++---- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 6f63c1d663f13..34b9c9988f35c 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1707,7 +1707,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "if you meant to write a byte literal, prefix with `b`", code = "b'{code}'", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] MeantByteLiteral { #[primary_span] @@ -1717,7 +1718,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "if you meant to write a `char` literal, use single quotes", code = "'{code}'", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] MeantCharLiteral { #[primary_span] @@ -1737,7 +1739,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "consider specifying the actual array length", code = "{length}", - applicability = "maybe-incorrect" + applicability = "maybe-incorrect", + style = "verbose" )] ConsiderSpecifyingLength { #[primary_span] diff --git a/tests/ui/consts/array-literal-len-mismatch.stderr b/tests/ui/consts/array-literal-len-mismatch.stderr index 782d059a294c2..bf828ff5acf5e 100644 --- a/tests/ui/consts/array-literal-len-mismatch.stderr +++ b/tests/ui/consts/array-literal-len-mismatch.stderr @@ -3,9 +3,14 @@ error[E0308]: mismatched types | LL | const NUMBERS: [u8; 3] = [10, 20]; | ------- ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const NUMBERS: [u8; 3] = [10, 20]; +LL + const NUMBERS: [u8; 2] = [10, 20]; + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-array-oob-arith.stderr b/tests/ui/consts/const-array-oob-arith.stderr index d37ae5e4a7b30..0cb654237ab55 100644 --- a/tests/ui/consts/const-array-oob-arith.stderr +++ b/tests/ui/consts/const-array-oob-arith.stderr @@ -3,18 +3,28 @@ error[E0308]: mismatched types | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; | ----------------------------- ^^^ expected an array with a size of 2, found one with a size of 1 - | | | - | | help: consider specifying the actual array length: `1` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; +LL + const BLUB: [i32; 1] = [5]; + | error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:9:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; | ----------------------------- ^^^^^^^ expected an array with a size of 1, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; +LL + const BOO: [i32; 2] = [5, 99]; + | error: aborting due to 2 previous errors diff --git a/tests/ui/inference/array-len-mismatch.stderr b/tests/ui/inference/array-len-mismatch.stderr index 7146e3803d536..94813d404b2b1 100644 --- a/tests/ui/inference/array-len-mismatch.stderr +++ b/tests/ui/inference/array-len-mismatch.stderr @@ -3,18 +3,28 @@ error[E0308]: mismatched types | LL | let wrong: [u8; 3] = [10, 20]; | ------- ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected due to this + | +help: consider specifying the actual array length + | +LL - let wrong: [u8; 3] = [10, 20]; +LL + let wrong: [u8; 2] = [10, 20]; + | error[E0308]: mismatched types --> $DIR/array-len-mismatch.rs:9:26 | LL | let wrong: [u8; 3] = returns_arr(); | ------- ^^^^^^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected due to this + | +help: consider specifying the actual array length + | +LL - let wrong: [u8; 3] = returns_arr(); +LL + let wrong: [u8; 2] = returns_arr(); + | error: aborting due to 2 previous errors From bfca1f1187bdcf653f744e382a129889dc743204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 20:43:57 +0000 Subject: [PATCH 05/12] fix clippy test --- src/tools/clippy/tests/ui/track-diagnostics.stderr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tools/clippy/tests/ui/track-diagnostics.stderr b/src/tools/clippy/tests/ui/track-diagnostics.stderr index 45262ba618f21..438d3ac378e1a 100644 --- a/src/tools/clippy/tests/ui/track-diagnostics.stderr +++ b/src/tools/clippy/tests/ui/track-diagnostics.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> tests/ui/track-diagnostics.rs:LL:CC | LL | const S: A = B; - | ^ expected `A`, found `B` + | - ^ expected `A`, found `B` + | | + | expected because of the type of the constant | = note: -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs:LL:CC From 75511819a482f25f5cd221f68b60f80b866c0644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 22:40:28 +0000 Subject: [PATCH 06/12] Turn label into structured suggestion for `.as_ref()` and `.as_mut()` ``` error[E0382]: use of moved value: `foo` --> $DIR/as-ref-2.rs:10:14 | LL | let foo = Some(Struct); | --- move occurs because `foo` has type `Option`, which does not implement the `Copy` trait LL | let _x: Option = foo.map(|s| bar(&s)); | ---------------- `foo` moved due to this method call LL | let _y = foo; | ^^^ value used here after move | note: `Option::::map` takes ownership of the receiver `self`, which moves `foo` --> $SRC_DIR/core/src/option.rs:LL:COL help: consider calling `.as_ref()` to borrow the value's contents | LL | let _x: Option = foo.as_ref().map(|s| bar(&s)); | +++++++++ help: consider calling `.as_mut()` to mutably borrow the value's contents | LL | let _x: Option = foo.as_mut().map(|s| bar(&s)); | +++++++++ ``` --- compiler/rustc_borrowck/src/diagnostics/mod.rs | 4 +++- .../rustc_borrowck/src/session_diagnostics.rs | 13 ++++++++++++- .../suggest-as-ref-on-mut-closure.stderr | 9 ++++++++- tests/ui/suggestions/as-ref-2.stderr | 12 +++++++++--- tests/ui/suggestions/option-content-move.fixed | 4 ++-- .../ui/suggestions/option-content-move.stderr | 18 ++++++++++++++++-- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index cb11d35c44b66..8b4bda8f7fefc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1377,7 +1377,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result)) }); if is_option_or_result && maybe_reinitialized_locations_is_empty { - err.subdiagnostic(CaptureReasonLabel::BorrowContent { var_span }); + err.subdiagnostic(CaptureReasonLabel::BorrowContent { + var_span: var_span.shrink_to_hi(), + }); } if let Some((CallDesugaringKind::ForLoopIntoIter, _)) = desugaring { let ty = moved_place.ty(self.body, tcx).ty; diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index b2f33d64f0d9e..cd4d1f16b21af 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -456,7 +456,18 @@ pub(crate) enum CaptureReasonLabel<'a> { is_move_msg: bool, is_loop_message: bool, }, - #[label("help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents")] + #[suggestion( + "consider calling `.as_ref()` to borrow the value's contents", + applicability = "maybe-incorrect", + code = ".as_ref()", + style = "verbose" + )] + #[suggestion( + "consider calling `.as_mut()` to mutably borrow the value's contents", + applicability = "maybe-incorrect", + code = ".as_mut()", + style = "verbose" + )] BorrowContent { #[primary_span] var_span: Span, diff --git a/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr b/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr index 9b4061af967ed..e2199fa90f263 100644 --- a/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr +++ b/tests/ui/borrowck/suggest-as-ref-on-mut-closure.stderr @@ -4,11 +4,18 @@ error[E0507]: cannot move out of `*cb` which is behind a mutable reference LL | cb.map(|cb| cb()); | ^^ -------------- `*cb` moved due to this method call | | - | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents | move occurs because `*cb` has type `Option<&mut dyn FnMut()>`, which does not implement the `Copy` trait | note: `Option::::map` takes ownership of the receiver `self`, which moves `*cb` --> $SRC_DIR/core/src/option.rs:LL:COL +help: consider calling `.as_ref()` to borrow the value's contents + | +LL | cb.as_ref().map(|cb| cb()); + | +++++++++ +help: consider calling `.as_mut()` to mutably borrow the value's contents + | +LL | cb.as_mut().map(|cb| cb()); + | +++++++++ help: you could `clone` the value and consume it, if the `&mut dyn FnMut(): Clone` trait bound could be satisfied | LL | as Clone>::clone(&cb).map(|cb| cb()); diff --git a/tests/ui/suggestions/as-ref-2.stderr b/tests/ui/suggestions/as-ref-2.stderr index 309285775374b..b183c8b2faee4 100644 --- a/tests/ui/suggestions/as-ref-2.stderr +++ b/tests/ui/suggestions/as-ref-2.stderr @@ -4,14 +4,20 @@ error[E0382]: use of moved value: `foo` LL | let foo = Some(Struct); | --- move occurs because `foo` has type `Option`, which does not implement the `Copy` trait LL | let _x: Option = foo.map(|s| bar(&s)); - | --- ---------------- `foo` moved due to this method call - | | - | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents + | ---------------- `foo` moved due to this method call LL | let _y = foo; | ^^^ value used here after move | note: `Option::::map` takes ownership of the receiver `self`, which moves `foo` --> $SRC_DIR/core/src/option.rs:LL:COL +help: consider calling `.as_ref()` to borrow the value's contents + | +LL | let _x: Option = foo.as_ref().map(|s| bar(&s)); + | +++++++++ +help: consider calling `.as_mut()` to mutably borrow the value's contents + | +LL | let _x: Option = foo.as_mut().map(|s| bar(&s)); + | +++++++++ help: you could `clone` the value and consume it, if the `Struct: Clone` trait bound could be satisfied | LL | let _x: Option = foo.clone().map(|s| bar(&s)); diff --git a/tests/ui/suggestions/option-content-move.fixed b/tests/ui/suggestions/option-content-move.fixed index 4a5a9483c20c8..0720146280f90 100644 --- a/tests/ui/suggestions/option-content-move.fixed +++ b/tests/ui/suggestions/option-content-move.fixed @@ -7,7 +7,7 @@ impl LipogramCorpora { pub fn validate_all(&mut self) -> Result<(), char> { for selection in &self.selections { if selection.1.is_some() { - if as Clone>::clone(&selection.1.clone()).unwrap().contains(selection.0) { + if as Clone>::clone(&selection.1.clone()).as_mut().as_ref().unwrap().contains(selection.0) { //~^ ERROR cannot move out of `selection.1` return Err(selection.0); } @@ -25,7 +25,7 @@ impl LipogramCorpora2 { pub fn validate_all(&mut self) -> Result<(), char> { for selection in &self.selections { if selection.1.is_ok() { - if as Clone>::clone(&selection.1.clone()).unwrap().contains(selection.0) { + if as Clone>::clone(&selection.1.clone()).as_mut().as_ref().unwrap().contains(selection.0) { //~^ ERROR cannot move out of `selection.1` return Err(selection.0); } diff --git a/tests/ui/suggestions/option-content-move.stderr b/tests/ui/suggestions/option-content-move.stderr index a382a04344aeb..09c6f39fd803d 100644 --- a/tests/ui/suggestions/option-content-move.stderr +++ b/tests/ui/suggestions/option-content-move.stderr @@ -4,11 +4,18 @@ error[E0507]: cannot move out of `selection.1` which is behind a shared referenc LL | if selection.1.unwrap().contains(selection.0) { | ^^^^^^^^^^^ -------- `selection.1` moved due to this method call | | - | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents | move occurs because `selection.1` has type `Option`, which does not implement the `Copy` trait | note: `Option::::unwrap` takes ownership of the receiver `self`, which moves `selection.1` --> $SRC_DIR/core/src/option.rs:LL:COL +help: consider calling `.as_ref()` to borrow the value's contents + | +LL | if selection.1.as_ref().unwrap().contains(selection.0) { + | +++++++++ +help: consider calling `.as_mut()` to mutably borrow the value's contents + | +LL | if selection.1.as_mut().unwrap().contains(selection.0) { + | +++++++++ help: you can `clone` the value and consume it, but this might not be your desired behavior | LL | if as Clone>::clone(&selection.1).unwrap().contains(selection.0) { @@ -24,11 +31,18 @@ error[E0507]: cannot move out of `selection.1` which is behind a shared referenc LL | if selection.1.unwrap().contains(selection.0) { | ^^^^^^^^^^^ -------- `selection.1` moved due to this method call | | - | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents | move occurs because `selection.1` has type `Result`, which does not implement the `Copy` trait | note: `Result::::unwrap` takes ownership of the receiver `self`, which moves `selection.1` --> $SRC_DIR/core/src/result.rs:LL:COL +help: consider calling `.as_ref()` to borrow the value's contents + | +LL | if selection.1.as_ref().unwrap().contains(selection.0) { + | +++++++++ +help: consider calling `.as_mut()` to mutably borrow the value's contents + | +LL | if selection.1.as_mut().unwrap().contains(selection.0) { + | +++++++++ help: you can `clone` the value and consume it, but this might not be your desired behavior | LL | if as Clone>::clone(&selection.1).unwrap().contains(selection.0) { From 249f52c1e0189479db18c61eff75b0b5926aa525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 23:24:23 +0000 Subject: [PATCH 07/12] Fix 32bit test --- .../invalid-patterns.32bit.stderr | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/ui/const-generics/min_const_generics/invalid-patterns.32bit.stderr b/tests/ui/const-generics/min_const_generics/invalid-patterns.32bit.stderr index df7c2a0a86292..9392a171510d7 100644 --- a/tests/ui/const-generics/min_const_generics/invalid-patterns.32bit.stderr +++ b/tests/ui/const-generics/min_const_generics/invalid-patterns.32bit.stderr @@ -3,24 +3,48 @@ error[E0308]: mismatched types | LL | get_flag::(); | ^^^^ expected `char`, found `u8` + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:34 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:33:14 | LL | get_flag::<7, 'c'>(); | ^ expected `bool`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:13 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:35:14 | LL | get_flag::<42, 0x5ad>(); | ^^ expected `bool`, found integer + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:13 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-patterns.rs:35:18 | LL | get_flag::<42, 0x5ad>(); | ^^^^^ expected `char`, found `u8` + | +note: expected because of the type of the const parameter + --> $DIR/invalid-patterns.rs:6:34 + | +LL | fn get_flag() -> Option { + | ^^^^^^^^^^^^^^^^^^^^^ error[E0080]: reading memory at ALLOC0[0x0..0x4], but memory is uninitialized at [0x1..0x4], and this operation requires initialized memory --> $DIR/invalid-patterns.rs:40:32 From 1038ed1bbc4fac855578e2f4f8302ca6a48e3156 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sat, 14 Mar 2026 16:36:41 +1100 Subject: [PATCH 08/12] Use less `#[macro_use]` in the query system --- compiler/rustc_macros/src/query.rs | 3 +++ compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 +- compiler/rustc_middle/src/lib.rs | 11 ++++------- compiler/rustc_middle/src/queries.rs | 1 + compiler/rustc_middle/src/query/mod.rs | 3 +-- compiler/rustc_middle/src/query/plumbing.rs | 4 ++++ 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index a0c5b38d01362..bd6ccf29b1fef 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -510,6 +510,9 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream { } } } + // Re-export the macro as a normal item, so that other modules in `rustc_middle` + // can import it normally, without `#[macro_use]`. + pub(crate) use rustc_with_all_queries; // Add hints for rust-analyzer mod _analyzer_hints { diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 6f85dba23dd49..49ad6bbf85773 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -331,7 +331,7 @@ macro_rules! define_dep_nodes { } // Create various data structures for each query, and also for a few things that aren't queries. -rustc_with_all_queries! { define_dep_nodes! } +crate::queries::rustc_with_all_queries! { define_dep_nodes! } // WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys. // Be very careful changing this type signature! diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 84fe59b3f7115..c8702c42c47f6 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -67,6 +67,8 @@ mod macros; #[macro_use] pub mod arena; + +pub mod dep_graph; pub mod error; pub mod hir; pub mod hooks; @@ -76,18 +78,13 @@ pub mod lint; pub mod metadata; pub mod middle; pub mod mir; +pub mod queries; +pub mod query; pub mod thir; pub mod traits; pub mod ty; pub mod util; pub mod verify_ich; -#[macro_use] -pub mod query; -#[macro_use] -pub mod queries; -#[macro_use] -pub mod dep_graph; - // Allows macros to refer to this crate as `::rustc_middle` extern crate self as rustc_middle; diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index ffe96c9db3da6..4dd68db4f9135 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -101,6 +101,7 @@ use crate::mir::mono::{ CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions, NormalizationErrorInMono, }; use crate::query::describe_as_module; +use crate::query::plumbing::{define_callbacks, query_helper_param_ty}; use crate::traits::query::{ CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal, CanonicalMethodAutoderefStepsGoal, CanonicalPredicateGoal, CanonicalTypeOpAscribeUserTypeGoal, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index b8fd88f2af17d..e6b8a931071f5 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -17,10 +17,9 @@ pub mod erase; pub(crate) mod inner; mod job; mod keys; +pub(crate) mod modifiers; pub mod on_disk_cache; -#[macro_use] pub mod plumbing; -pub(crate) mod modifiers; mod stack; pub fn describe_as_module(def_id: impl Into, tcx: TyCtxt<'_>) -> String { diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 128350a89ecf1..90491bc402fb9 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -630,6 +630,10 @@ macro_rules! define_callbacks { }; } +// Re-export `macro_rules!` macros as normal items, so that they can be imported normally. +pub(crate) use define_callbacks; +pub(crate) use query_helper_param_ty; + mod sealed { use rustc_hir::def_id::{LocalModDefId, ModDefId}; From e8ebfcaa2eaa1a5ee63328181c7b587cec2fcf78 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 15 Mar 2026 13:17:09 +1100 Subject: [PATCH 09/12] Declare `rustc_with_all_queries!` as macros-2.0 Unlike `macro_rules!`, macros-2.0 macros have sensible item-like namespacing and visibility by default, which avoids the need for `#[macro_export]` and makes it easier to import the macro. The tradeoff is having to use `#[rustc_macro_transparency = "semiopaque"]` to still get macro-rules hygiene, because macros-2.0 hygiene is too strict here. --- compiler/rustc_macros/src/query.rs | 7 ++----- compiler/rustc_query_impl/src/dep_kind_vtables.rs | 2 +- compiler/rustc_query_impl/src/query_impl.rs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index bd6ccf29b1fef..a803d86f27715 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -498,8 +498,8 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream { /// Higher-order macro that invokes the specified macro with (a) a list of all query /// signatures (including modifiers), and (b) a list of non-query names. This allows /// multiple simpler macros to each have access to these lists. - #[macro_export] - macro_rules! rustc_with_all_queries { + #[rustc_macro_transparency = "semiopaque"] // Use `macro_rules!` hygiene. + pub macro rustc_with_all_queries { ( // The macro to invoke once, on all queries and non-queries. $macro:ident! @@ -510,9 +510,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream { } } } - // Re-export the macro as a normal item, so that other modules in `rustc_middle` - // can import it normally, without `#[macro_use]`. - pub(crate) use rustc_with_all_queries; // Add hints for rust-analyzer mod _analyzer_hints { diff --git a/compiler/rustc_query_impl/src/dep_kind_vtables.rs b/compiler/rustc_query_impl/src/dep_kind_vtables.rs index 34ef70f141b94..597c8b2a9e742 100644 --- a/compiler/rustc_query_impl/src/dep_kind_vtables.rs +++ b/compiler/rustc_query_impl/src/dep_kind_vtables.rs @@ -179,7 +179,7 @@ macro_rules! define_dep_kind_vtables { // Create an array of vtables, one for each dep kind (non-query and query). pub fn make_dep_kind_vtables<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindVTable<'tcx>] { let (nq_vtables, q_vtables) = - rustc_middle::rustc_with_all_queries! { define_dep_kind_vtables! }; + rustc_middle::queries::rustc_with_all_queries! { define_dep_kind_vtables! }; // Non-query vtables must come before query vtables, to match the order of `DepKind`. arena.alloc_from_iter(nq_vtables.into_iter().chain(q_vtables.into_iter())) diff --git a/compiler/rustc_query_impl/src/query_impl.rs b/compiler/rustc_query_impl/src/query_impl.rs index d5fb90871e76e..23f678e1c9f73 100644 --- a/compiler/rustc_query_impl/src/query_impl.rs +++ b/compiler/rustc_query_impl/src/query_impl.rs @@ -272,4 +272,4 @@ macro_rules! define_queries { } } -rustc_middle::rustc_with_all_queries! { define_queries! } +rustc_middle::queries::rustc_with_all_queries! { define_queries! } From 50d4943d449f608bd156968938d43952c1847cc1 Mon Sep 17 00:00:00 2001 From: Misaka_15535 <46892084+Misaka299@users.noreply.github.com> Date: Sat, 14 Mar 2026 22:11:52 +0800 Subject: [PATCH 10/12] docs: remove stale reference to `check_let_chain` The function `check_let_chain` was removed previously, but it was still referenced in a comment in `check_match.rs`. This commit cleans it up. --- compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index e844f1114d61e..6a79401af24ea 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -101,8 +101,7 @@ struct MatchVisitor<'p, 'tcx> { error: Result<(), ErrorGuaranteed>, } -// Visitor for a thir body. This calls `check_match`, `check_let` and `check_let_chain` as -// appropriate. +// Visitor for a thir body. This calls `check_match` and `check_let` as appropriate. impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> { fn thir(&self) -> &'p Thir<'tcx> { self.thir From a0c174fe8a5e57fadb021a745859ef045a849a77 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sun, 15 Mar 2026 12:06:32 +0100 Subject: [PATCH 11/12] add test for param-env shadowing --- ...le-impls-shadowed-in-trait-def.next.stderr | 19 +++++++++++++++ ...ble-impls-shadowed-in-trait-def.old.stderr | 19 +++++++++++++++ ...-applicable-impls-shadowed-in-trait-def.rs | 23 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.next.stderr create mode 100644 tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.old.stderr create mode 100644 tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.rs diff --git a/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.next.stderr b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.next.stderr new file mode 100644 index 0000000000000..30eccc3a72d51 --- /dev/null +++ b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.next.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `Self: Eq<::Assoc>` is not satisfied + --> $DIR/always-applicable-impls-shadowed-in-trait-def.rs:13:17 + | +LL | fn foo() -> IsEqual { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<::Assoc>` is not implemented for `Self` + | +note: required by a bound in `IsEqual` + --> $DIR/always-applicable-impls-shadowed-in-trait-def.rs:9:19 + | +LL | struct IsEqual, U>(T, U); + | ^^^^^ required by this bound in `IsEqual` +help: consider further restricting `Self` + | +LL | fn foo() -> IsEqual where Self: Eq<::Assoc> { + | ++++++++++++++++++++++++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.old.stderr b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.old.stderr new file mode 100644 index 0000000000000..30eccc3a72d51 --- /dev/null +++ b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.old.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `Self: Eq<::Assoc>` is not satisfied + --> $DIR/always-applicable-impls-shadowed-in-trait-def.rs:13:17 + | +LL | fn foo() -> IsEqual { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<::Assoc>` is not implemented for `Self` + | +note: required by a bound in `IsEqual` + --> $DIR/always-applicable-impls-shadowed-in-trait-def.rs:9:19 + | +LL | struct IsEqual, U>(T, U); + | ^^^^^ required by this bound in `IsEqual` +help: consider further restricting `Self` + | +LL | fn foo() -> IsEqual where Self: Eq<::Assoc> { + | ++++++++++++++++++++++++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.rs b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.rs new file mode 100644 index 0000000000000..2f8abb6a70d86 --- /dev/null +++ b/tests/ui/associated-types/always-applicable-impls-shadowed-in-trait-def.rs @@ -0,0 +1,23 @@ +//@ revisions: old next +//@[next] compile-flags: -Znext-solver + +// Testing that even if there's an always applicable blanket impl, the trait +// definition cannot use that impl to normalize its own associated types. + +trait Eq {} +impl Eq for T {} +struct IsEqual, U>(T, U); + +trait Trait: Sized { + type Assoc; + fn foo() -> IsEqual { + //~^ ERROR the trait bound `Self: Eq<::Assoc>` is not satisfied + todo!() + } +} + +impl Trait for T { + type Assoc = T; +} + +fn main() {} From 823517c41c9df058612f5da8db9dafc8d46e05cc Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sun, 15 Mar 2026 21:12:28 +0800 Subject: [PATCH 12/12] compiletest: show rustdoc logs when `--no-capture` --- src/tools/compiletest/src/runtest/rustdoc_json.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tools/compiletest/src/runtest/rustdoc_json.rs b/src/tools/compiletest/src/runtest/rustdoc_json.rs index 89e9f31688379..d6afb77c2e8df 100644 --- a/src/tools/compiletest/src/runtest/rustdoc_json.rs +++ b/src/tools/compiletest/src/runtest/rustdoc_json.rs @@ -14,6 +14,11 @@ impl TestCx<'_> { }); let proc_res = self.document(&out_dir, DocKind::Json); + + if !self.config.capture { + writeln!(self.stdout, "{}", proc_res.format_info()); + } + if !proc_res.status.success() { self.fatal_proc_rec("rustdoc failed!", &proc_res); }