mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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`
This commit is contained in:
@@ -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<N>()` 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<N>` 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<const N: usize = ()>` 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<Ty<'tcx>> {
|
||||
let tcx = fcx.tcx;
|
||||
let def_id = fcx.body_id;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+3
-1
@@ -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 `<C as O>::M`
|
||||
found type `u8`
|
||||
|
||||
@@ -37,6 +37,7 @@ trait AssocConst {
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected associated type, found `u8`
|
||||
//~| NOTE expected associated type `<Self as AssocConst>::Ty`
|
||||
//~| NOTE expected because
|
||||
}
|
||||
|
||||
// An impl can, however
|
||||
|
||||
@@ -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 `<Self as AssocConst>::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
|
||||
|
||||
@@ -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: <Self::Fv as Foo>::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 `<<Self as Baz>::Fv as Foo>::Bar`
|
||||
found type `{integer}`
|
||||
|
||||
@@ -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)()]))
|
||||
|
||||
@@ -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(<ConstBytes<b"AAA"> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
|
||||
//~| NOTE expected because of the type of the const parameter
|
||||
|
||||
where
|
||||
ConstBytes<b"AAA">: Sized;
|
||||
|
||||
@@ -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<b"AAA">: 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<const T: &'static [*mut u8; 3]>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: rustc_dump_predicates
|
||||
--> $DIR/byte-string-u8-validation.rs:8:1
|
||||
|
||||
@@ -15,6 +15,11 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
|
||||
|
|
||||
= 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<const T: &'static [*mut u8; 3]>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:46
|
||||
@@ -24,6 +29,11 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
|
||||
|
|
||||
= 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<const T: &'static [*mut u8; 3]>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ error[E0308]: mismatched types
|
||||
--> $DIR/transmutable-ice-110969.rs:25:29
|
||||
|
|
||||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
||||
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
||||
| |
|
||||
| expected because of the type of the associated constant
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<const z: [usize; x]> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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<const z: [usize; x]> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0592]: duplicate definitions with name `B`
|
||||
--> $DIR/error_in_ty.rs:12:5
|
||||
|
||||
@@ -14,7 +14,9 @@ error[E0308]: mismatched types
|
||||
--> $DIR/issue-105257.rs:5:29
|
||||
|
|
||||
LL | fn fnc<const N: usize = "">(&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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,24 +3,48 @@ error[E0308]: mismatched types
|
||||
|
|
||||
LL | get_flag::<false, 0xFF>();
|
||||
| ^^^^ expected `char`, found `u8`
|
||||
|
|
||||
note: expected because of the type of the const parameter
|
||||
--> $DIR/invalid-patterns.rs:6:34
|
||||
|
|
||||
LL | fn get_flag<const FlagSet: bool, const ShortName: char>() -> Option<char> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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<const FlagSet: bool, const ShortName: char>() -> Option<char> {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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<const FlagSet: bool, const ShortName: char>() -> Option<char> {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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<const FlagSet: bool, const ShortName: char>() -> Option<char> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<const C: Foo>() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
||||
@@ -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<_>`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<u32, ()>`
|
||||
| --- ^^^^ expected `u32`, found `Result<u32, ()>`
|
||||
| |
|
||||
| expected because of the type of the constant
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found enum `Result<u32, ()>`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}`
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,8 +2,9 @@ error[E0308]: mismatched types
|
||||
--> $DIR/assoc-const-missing-type.rs:12:18
|
||||
|
|
||||
LL | const K<T> = ();
|
||||
| - ^^ 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`
|
||||
|
||||
@@ -22,7 +22,9 @@ error[E0308]: mismatched types
|
||||
LL | impl<T> S0<T> {
|
||||
| - found this type parameter
|
||||
LL | const C: S0<u8> = Self(0);
|
||||
| ^^^^^^^ expected `S0<u8>`, found `S0<T>`
|
||||
| ------ ^^^^^^^ expected `S0<u8>`, found `S0<T>`
|
||||
| |
|
||||
| expected because of the type of the associated constant
|
||||
|
|
||||
= note: expected struct `S0<u8>`
|
||||
found struct `S0<T>`
|
||||
@@ -89,7 +91,9 @@ error[E0308]: mismatched types
|
||||
LL | impl<T> S1<T, u8> {
|
||||
| - found this type parameter
|
||||
LL | const C: S1<u8, u8> = Self(0, 1);
|
||||
| ^^^^^^^^^^ expected `S1<u8, u8>`, found `S1<T, u8>`
|
||||
| ---------- ^^^^^^^^^^ expected `S1<u8, u8>`, found `S1<T, u8>`
|
||||
| |
|
||||
| expected because of the type of the associated constant
|
||||
|
|
||||
= note: expected struct `S1<u8, _>`
|
||||
found struct `S1<T, _>`
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
enum Enum<T: Trait> {
|
||||
//~^ 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 } } ];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
|
||||
|
||||
@@ -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
|
||||
|
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ error[E0308]: mismatched types
|
||||
--> $DIR/issue-61882.rs:4:22
|
||||
|
|
||||
LL | const B: A<u8> = Self(0);
|
||||
| ^^^^^^^ expected `A<u8>`, found `A<bool>`
|
||||
| ----- ^^^^^^^ expected `A<u8>`, found `A<bool>`
|
||||
| |
|
||||
| expected because of the type of the associated constant
|
||||
|
|
||||
= note: expected struct `A<u8>`
|
||||
found struct `A<bool>`
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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
|
||||
|
|
||||
|
||||
@@ -18,7 +18,9 @@ error[E0308]: mismatched types
|
||||
--> $DIR/issue-5216.rs:8:19
|
||||
|
|
||||
LL | pub static D: T = g;
|
||||
| ^ expected `Box<dyn FnMut() + Sync>`, found fn item
|
||||
| - ^ expected `Box<dyn FnMut() + Sync>`, found fn item
|
||||
| |
|
||||
| expected because of the type of the static
|
||||
|
|
||||
= note: expected struct `Box<(dyn FnMut() + Sync + 'static)>`
|
||||
found fn item `fn() {g}`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user