diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 77c95fd55be3..200cef49f35d 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -41,7 +41,7 @@ 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 decdde042c6f..04841f1d1f66 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 4d6078788b22..d665125608af 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 3b89ed66b355..50bafc96acaa 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 3de64e0d0db6..7b3e7f96acb5 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 56abd6ebf73b..fe9023e52324 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 5fb1a4ef3f5f..798f0eb392c4 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 140f24982140..a70c761201b6 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 d49fb49d253c..5d6e34804c5c 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 @@ //~^ 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 1273a74102a2..34c65af7cd97 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 d7eec45bae0f..14afd18f82a7 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 967166856147..bc8feaf5214a 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 daea55efbbc7..4125461f92b2 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 14a41e87e4aa..9e22119cf87f 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 d9a13976d68a..d81eeb465d6f 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 fbd546d42fb5..c2cf80f38eca 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 58f0d31b0960..e10ea5a44b26 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 1d0ab56519cf..c90feb404181 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 9f48a8563c8a..fd597cbde193 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 df7c2a0a8629..9392a171510d 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 ce4e8eb1471c..b1808deacd27 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 f67e1c8ce699..d49a643e0d87 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 63d7b0c89fa1..ae08cad556fc 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 39b8a647324b..782d059a294c 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 8e5c56e0ea82..97f8406a10f0 100644 --- a/tests/ui/consts/const-array-oob-arith.rs +++ b/tests/ui/consts/const-array-oob-arith.rs @@ -4,10 +4,12 @@ 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 d3299082aa14..d37ae5e4a7b3 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 ce641f4a74b9..915fc8e394b3 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 f1904c76b6c1..1846da22cd3d 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 @@ 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 ba11759a7106..ff17da5a04d7 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 fbbd51adfe88..e1da3e750876 100644 --- a/tests/ui/consts/const-integer-bool-ops.rs +++ b/tests/ui/consts/const-integer-bool-ops.rs @@ -5,6 +5,7 @@ //~| 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 @@ //~| 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 @@ //~| 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 @@ //~| 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 4e503e5a5c0a..5212a5cfeb1e 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` - -error[E0308]: mismatched types - --> $DIR/const-integer-bool-ops.rs:42: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 | -LL | const Y2: usize = 42.0 <= 42.0; - | ^^^^^^^^^^^^ expected `usize`, found `bool` +LL | const Y1: usize = 42.0 >= 42.0; + | ----- ^^^^^^^^^^^^ 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:53:19 + | +LL | const Y2: usize = 42.0 <= 42.0; + | ----- ^^^^^^^^^^^^ expected `usize`, found `bool` + | | + | expected because of the type of the constant + +error[E0308]: mismatched types + --> $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 70aa306ae3c8..337065f9f5e0 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 b1d069280885..e7513d01cd0e 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 4cb7143b4351..6896625c3785 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 792e18aa8fd4..fe4290961816 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 17bb27d4b72f..d36ef1188f41 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 9a09d6a96f1a..c676a96ad34a 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 bd4a54de0ae4..81b4575b361b 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 adc65d9be0d0..7d9f1b6cf474 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 1c15debb1199..784a19445055 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 7078b4bd7be1..1210ae87642d 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 db298246e7cf..b13a6dca2b38 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 24f1268e4b6e..a6f67a2056da 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 252b17912dee..526719678afe 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 2e77c3689223..0b1ca9a22fd6 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 b4803e31aaab..bd86a048c434 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 1de1a4acd929..4d9e413287b6 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 d4aeb1eee96a..83a34e2bcd07 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 e3cbd01a1ddf..1e456425cdd8 100644 --- a/tests/ui/enum-discriminant/discriminant-ill-typed.rs +++ b/tests/ui/enum-discriminant/discriminant-ill-typed.rs @@ -13,8 +13,9 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 @@ enum A { 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 e9508b7fe962..794447295320 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 17e6c3433343..6c84efe73e42 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 ae09b919dc15..63973be83774 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 f1645183e176..d256a2ed644b 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 7c79133d64ec..b7fb625a9ea5 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 f2fd4340a580..8bc0f0a5e92f 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 fc82fda0ccd8..697bbf6fe6d1 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 56e4cee53d63..765db15e8285 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 7f44ab2ed6b4..1ce50903ff10 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 db5d801871bc..a6f9518c3e63 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 db05e1daedbd..f92f97ed587b 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 @@ 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 9a9cc946f82a..155adb5363a2 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 a51eb46fb244..fc0a670d08dc 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 2c8d4da9d218..4851a20fcf0e 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 83c88d1085ef..6f91967b8b82 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 cc457a4e64e2..5cdb94cb8176 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 2bc7952def79..8b784d02a01d 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 f14b5fed6b9e..00c1c6b0f4cf 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 eb9581b8f7ae..e2cecf9973b8 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 96f4e41de174..867e3e97ac37 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 d4e6352d7c1c..696fa295af41 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 8573a11ef291..12ecb73d94da 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 99c8b1aa131a..9748223e3d1d 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 02ac40741cb7..18f6e9b4ed10 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 7893cc849248..cb491a78945c 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 4af92a89c445..129e4b5cdc7b 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 bec92448d1c8..07e4b9addaa1 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 482773a39440..daddbe9fa469 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