mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
modify error comment and bless test, delete tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
//@ known-bug: #133966
|
||||
pub struct Data([[&'static str]; 5_i32]);
|
||||
const _: &'static Data = unsafe { &*(&[] as *const Data) };
|
||||
@@ -9,10 +9,12 @@
|
||||
//~^ 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: [] }
|
||||
|
||||
where
|
||||
ConstBytes<b"AAA">: Sized;
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected `&[*mut u8; 3]`, found `&[u8; 3]`
|
||||
//~| NOTE expected reference `&'static [*mut u8; 3]`
|
||||
//~| NOTE found reference `&'static [u8; 3]`
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/byte-string-u8-validation.rs:13:16
|
||||
--> $DIR/byte-string-u8-validation.rs:14:16
|
||||
|
|
||||
LL | ConstBytes<b"AAA">: Sized;
|
||||
| ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]`
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#![expect(incomplete_features)]
|
||||
|
||||
trait Trait<T> {
|
||||
fn fnc<const N: usize = "">(&self) {} //~ERROR defaults for generic parameters are not allowed here
|
||||
//~^ ERROR: mismatched types
|
||||
fn foo<const N: usize = { std::mem::size_of::<T>() }>(&self) {} //~ERROR defaults for generic parameters are not allowed here
|
||||
fn fnc<const N: usize = "">(&self) {} //~ ERROR defaults for generic parameters are not allowed here
|
||||
//~^ ERROR mismatched types
|
||||
fn foo<const N: usize = { std::mem::size_of::<T>() }>(&self) {} //~ ERROR defaults for generic parameters are not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
//! ICE regression test for #114317 and #126182
|
||||
//! Type mismatches of literals cause errors int typeck,
|
||||
//! but those errors cannot be propagated to the various
|
||||
//! `lit_to_const` call sites. Now `lit_to_const` just delays
|
||||
//! a bug and produces an error constant on its own.
|
||||
|
||||
#![feature(adt_const_params)]
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct A<const B: () = 1, C>(C);
|
||||
//~^ ERROR: generic parameters with a default must be trailing
|
||||
//~| ERROR: mismatched types
|
||||
|
||||
struct Cond<const B: bool>;
|
||||
|
||||
struct Thing<T = Cond<0>>(T);
|
||||
//~^ ERROR: mismatched types
|
||||
|
||||
impl Thing {}
|
||||
|
||||
fn main() {}
|
||||
@@ -1,21 +0,0 @@
|
||||
error: generic parameters with a default must be trailing
|
||||
--> $DIR/lit_type_mismatch.rs:11:16
|
||||
|
|
||||
LL | struct A<const B: () = 1, C>(C);
|
||||
| ^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/lit_type_mismatch.rs:11:24
|
||||
|
|
||||
LL | struct A<const B: () = 1, C>(C);
|
||||
| ^ expected `()`, found integer
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/lit_type_mismatch.rs:17:23
|
||||
|
|
||||
LL | struct Thing<T = Cond<0>>(T);
|
||||
| ^ expected `bool`, found integer
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Regression test for <https://github.com/rust-lang/rust/issues/150983>
|
||||
#![expect(incomplete_features)]
|
||||
#![feature(
|
||||
adt_const_params,
|
||||
generic_const_items,
|
||||
generic_const_parameter_types,
|
||||
min_generic_const_args,
|
||||
@@ -12,9 +13,7 @@ struct Foo<T> {
|
||||
field: T,
|
||||
}
|
||||
|
||||
#[type_const]
|
||||
const WRAP<T : ConstParamTy_> : T = {
|
||||
Foo::<T>{field : 1} //~ ERROR: type annotations needed for the literal
|
||||
};
|
||||
type const WRAP<T : ConstParamTy_> : T = Foo::<T>{field : 1};
|
||||
//~^ ERROR: type annotations needed for the literal
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error: type annotations needed for the literal
|
||||
--> $DIR/generic_const_type_mismatch.rs:17:22
|
||||
--> $DIR/generic_const_type_mismatch.rs:16:59
|
||||
|
|
||||
LL | Foo::<T>{field : 1}
|
||||
| ^
|
||||
LL | type const WRAP<T : ConstParamTy_> : T = Foo::<T>{field : 1};
|
||||
| ^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
@@ -12,11 +12,9 @@ fn qux<const Z: (char, i32)>() {}
|
||||
fn main() {
|
||||
foo::<{ (1, true) }>();
|
||||
//~^ ERROR: type annotations needed for the literal
|
||||
//~| ERROR: mismatched types: expected `i32`, found `bool`
|
||||
bar::<{ (1_u32, [1, 2]) }>();
|
||||
//~^ ERROR: expected `i32`, found const array
|
||||
//~| ERROR: mismatched types: expected `[u8; 2]`, found `u32`
|
||||
qux::<{ (1i32, 'a') }>();
|
||||
//~^ ERROR: mismatched types: expected `char`, found `i32`
|
||||
//~| ERROR: mismatched types: expected `i32`, found `char`
|
||||
//~^ ERROR: the constant `1` is not of type `char`
|
||||
//~| ERROR: the constant `'a'` is not of type `i32
|
||||
}
|
||||
|
||||
@@ -4,35 +4,23 @@ error: type annotations needed for the literal
|
||||
LL | foo::<{ (1, true) }>();
|
||||
| ^
|
||||
|
||||
error: mismatched types: expected `i32`, found `bool`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:13:17
|
||||
|
|
||||
LL | foo::<{ (1, true) }>();
|
||||
| ^^^^
|
||||
|
||||
error: mismatched types: expected `[u8; 2]`, found `u32`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:16:14
|
||||
|
|
||||
LL | bar::<{ (1_u32, [1, 2]) }>();
|
||||
| ^^^^^
|
||||
|
||||
error: expected `i32`, found const array
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:16:21
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:15:21
|
||||
|
|
||||
LL | bar::<{ (1_u32, [1, 2]) }>();
|
||||
| ^^^^^^
|
||||
|
||||
error: mismatched types: expected `char`, found `i32`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:19:14
|
||||
error: the constant `1` is not of type `char`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:17:13
|
||||
|
|
||||
LL | qux::<{ (1i32, 'a') }>();
|
||||
| ^^^^
|
||||
| ^^^^^^^^^^^ expected `char`, found `i32`
|
||||
|
||||
error: mismatched types: expected `i32`, found `char`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:19:20
|
||||
error: the constant `'a'` is not of type `i32`
|
||||
--> $DIR/tuple_expr_type_mismatch.rs:17:13
|
||||
|
|
||||
LL | qux::<{ (1i32, 'a') }>();
|
||||
| ^^^
|
||||
| ^^^^^^^^^^^ expected `i32`, found `char`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#![feature(min_generic_const_args)]
|
||||
|
||||
type const FREE: u32 = 5_usize;
|
||||
//~^ ERROR mismatched types
|
||||
//~^ ERROR the constant `5` is not of type `u32`
|
||||
//~| ERROR mismatched types
|
||||
|
||||
type const FREE2: isize = FREE;
|
||||
//~^ ERROR the constant `5` is not of type `isize`
|
||||
|
||||
trait Tr {
|
||||
type const N: usize;
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
error: the constant `5` is not of type `u32`
|
||||
--> $DIR/type_const-mismatched-types.rs:4:1
|
||||
|
|
||||
LL | type const FREE: u32 = 5_usize;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize`
|
||||
|
||||
error: the constant `5` is not of type `isize`
|
||||
--> $DIR/type_const-mismatched-types.rs:8:1
|
||||
|
|
||||
LL | type const FREE2: isize = FREE;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type_const-mismatched-types.rs:16:27
|
||||
|
|
||||
LL | type const N: usize = false;
|
||||
| ^^^^^ expected `usize`, found `bool`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type_const-mismatched-types.rs:4:24
|
||||
|
|
||||
@@ -10,12 +28,6 @@ LL - type const FREE: u32 = 5_usize;
|
||||
LL + type const FREE: u32 = 5_u32;
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type_const-mismatched-types.rs:18:22
|
||||
|
|
||||
LL | type const N: usize = false;
|
||||
| ^^^^^ expected `usize`, found `bool`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
||||
@@ -22,7 +22,7 @@ error[E0308]: mismatched types
|
||||
LL | get_flag::<42, 0x5ad>();
|
||||
| ^^^^^ expected `char`, found `u8`
|
||||
|
||||
error[E0080]: reading memory at ALLOC6[0x0..0x4], but memory is uninitialized at [0x1..0x4], and this operation requires initialized memory
|
||||
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
|
||||
|
|
||||
LL | get_flag::<false, { unsafe { char_raw.character } }>();
|
||||
@@ -54,7 +54,7 @@ LL | get_flag::<{ unsafe { bool_raw.boolean } }, { unsafe { char_raw.character
|
||||
42 │ B
|
||||
}
|
||||
|
||||
error[E0080]: reading memory at ALLOC12[0x0..0x4], but memory is uninitialized at [0x1..0x4], and this operation requires initialized memory
|
||||
error[E0080]: reading memory at ALLOC1[0x0..0x4], but memory is uninitialized at [0x1..0x4], and this operation requires initialized memory
|
||||
--> $DIR/invalid-patterns.rs:44:58
|
||||
|
|
||||
LL | get_flag::<{ unsafe { bool_raw.boolean } }, { unsafe { char_raw.character } }>();
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
error: the constant `1` is not of type `u8`
|
||||
--> $DIR/type-mismatch.rs:8:27
|
||||
|
|
||||
LL | assert_eq!(R.method::<1u16>(), 1);
|
||||
| ^^^^ expected `u8`, found `u16`
|
||||
|
|
||||
note: required by a const generic parameter in `R::method`
|
||||
--> $DIR/type-mismatch.rs:5:15
|
||||
|
|
||||
LL | fn method<const N: u8>(&self) -> u8 { N }
|
||||
| ^^^^^^^^^^^ required by this const generic parameter in `R::method`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch.rs:8:27
|
||||
|
|
||||
@@ -10,6 +22,6 @@ LL - assert_eq!(R.method::<1u16>(), 1);
|
||||
LL + assert_eq!(R.method::<1u8>(), 1);
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
error: the constant `1` is not of type `u8`
|
||||
--> $DIR/type-mismatch.rs:8:27
|
||||
|
|
||||
LL | assert_eq!(R.method::<1u16>(), 1);
|
||||
| ^^^^ expected `u8`, found `u16`
|
||||
|
|
||||
note: required by a const generic parameter in `R::method`
|
||||
--> $DIR/type-mismatch.rs:5:15
|
||||
|
|
||||
LL | fn method<const N: u8>(&self) -> u8 { N }
|
||||
| ^^^^^^^^^^^ required by this const generic parameter in `R::method`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch.rs:8:27
|
||||
|
|
||||
@@ -10,6 +22,6 @@ LL - assert_eq!(R.method::<1u16>(), 1);
|
||||
LL + assert_eq!(R.method::<1u8>(), 1);
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
||||
@@ -6,5 +6,6 @@ fn method<const N: u8>(&self) -> u8 { N }
|
||||
}
|
||||
fn main() {
|
||||
assert_eq!(R.method::<1u16>(), 1);
|
||||
//~^ ERROR mismatched types
|
||||
//~^ ERROR the constant `1` is not of type `u8`
|
||||
//~| ERROR mismatched types
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//! Regression test for <https://github.com/rust-lang/rust/issues/133966>
|
||||
pub struct Data([[&'static str]; 5_i32]);
|
||||
//~^ ERROR the constant `5` is not of type `usize`
|
||||
//~| ERROR the size for values of type `[&'static str]` cannot be known at compilation time
|
||||
//~| ERROR mismatched types
|
||||
const _: &'static Data = unsafe { &*(&[] as *const Data) };
|
||||
//~^ ERROR the type `[[&str]; 5]` has an unknown layout
|
||||
fn main() {}
|
||||
@@ -0,0 +1,39 @@
|
||||
error: the constant `5` is not of type `usize`
|
||||
--> $DIR/array-len-mismatch-type.rs:2:17
|
||||
|
|
||||
LL | pub struct Data([[&'static str]; 5_i32]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32`
|
||||
|
|
||||
= note: the length of array `[[&'static str]; 5]` must be type `usize`
|
||||
|
||||
error[E0277]: the size for values of type `[&'static str]` cannot be known at compilation time
|
||||
--> $DIR/array-len-mismatch-type.rs:2:17
|
||||
|
|
||||
LL | pub struct Data([[&'static str]; 5_i32]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[&'static str]`
|
||||
= note: slice and array elements must have `Sized` type
|
||||
|
||||
error[E0080]: the type `[[&str]; 5]` has an unknown layout
|
||||
--> $DIR/array-len-mismatch-type.rs:6:39
|
||||
|
|
||||
LL | const _: &'static Data = unsafe { &*(&[] as *const Data) };
|
||||
| ^^ evaluation of `_` failed here
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/array-len-mismatch-type.rs:2:34
|
||||
|
|
||||
LL | pub struct Data([[&'static str]; 5_i32]);
|
||||
| ^^^^^ expected `usize`, found `i32`
|
||||
|
|
||||
help: change the type of the numeric literal from `i32` to `usize`
|
||||
|
|
||||
LL - pub struct Data([[&'static str]; 5_i32]);
|
||||
LL + pub struct Data([[&'static str]; 5_usize]);
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0080, E0277, E0308.
|
||||
For more information about an error, try `rustc --explain E0080`.
|
||||
@@ -4,9 +4,9 @@ trait Trait<T> {
|
||||
fn foo(_: T) {}
|
||||
}
|
||||
|
||||
pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>; //~ ERROR cycle detected
|
||||
//~^ ERROR `T` is never used
|
||||
//~| ERROR cycle detected
|
||||
pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
|
||||
//~^ ERROR cycle detected when computing type of `Foo::T`
|
||||
//~| ERROR type parameter `T` is never used
|
||||
type DefaultFoo = Foo;
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
error[E0391]: cycle detected when computing type of `Foo::T`
|
||||
--> $DIR/issue-34373.rs:7:34
|
||||
|
|
||||
LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires expanding type alias `DefaultFoo`...
|
||||
--> $DIR/issue-34373.rs:10:1
|
||||
|
|
||||
LL | type DefaultFoo = Foo;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: ...which again requires computing type of `Foo::T`, completing the cycle
|
||||
note: cycle used when checking that `Foo` is well-formed
|
||||
--> $DIR/issue-34373.rs:7:1
|
||||
|
|
||||
LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||
|
||||
error[E0391]: cycle detected when computing type of `Foo::T`
|
||||
--> $DIR/issue-34373.rs:7:34
|
||||
|
|
||||
@@ -45,7 +26,7 @@ LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
|
||||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0391, E0392.
|
||||
For more information about an error, try `rustc --explain E0391`.
|
||||
|
||||
@@ -21,16 +21,21 @@ fn main() {
|
||||
let f = [0; -4_isize];
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected `usize`, found `isize`
|
||||
let f = [0_usize; -1_isize];
|
||||
//~| NOTE `-4_isize` cannot fit into type `usize`
|
||||
let g = [0_usize; -1_isize];
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected `usize`, found `isize`
|
||||
let f = [0; 4u8];
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE `-1_isize` cannot fit into type `usize`
|
||||
let h = [0; 4u8];
|
||||
//~^ ERROR the constant `4` is not of type `usize`
|
||||
//~| NOTE expected `usize`, found `u8`
|
||||
struct G {
|
||||
g: (),
|
||||
//~| NOTE the length of array `[{integer}; 4]` must be type `usize`
|
||||
//~| ERROR mismatched types
|
||||
//~| NOTE expected `usize`, found `u8`
|
||||
struct I {
|
||||
i: (),
|
||||
}
|
||||
let g = [0; G { g: () }];
|
||||
let i = [0; I { i: () }];
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected `usize`, found `G`
|
||||
//~| NOTE expected `usize`, found `I`
|
||||
}
|
||||
|
||||
@@ -43,32 +43,40 @@ LL | let f = [0; -4_isize];
|
||||
= note: `-4_isize` cannot fit into type `usize`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:24:23
|
||||
--> $DIR/repeat_count.rs:25:23
|
||||
|
|
||||
LL | let f = [0_usize; -1_isize];
|
||||
LL | let g = [0_usize; -1_isize];
|
||||
| ^^^^^^^^ expected `usize`, found `isize`
|
||||
|
|
||||
= note: `-1_isize` cannot fit into type `usize`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:27:17
|
||||
error: the constant `4` is not of type `usize`
|
||||
--> $DIR/repeat_count.rs:29:13
|
||||
|
|
||||
LL | let f = [0; 4u8];
|
||||
LL | let h = [0; 4u8];
|
||||
| ^^^^^^^^ expected `usize`, found `u8`
|
||||
|
|
||||
= note: the length of array `[{integer}; 4]` must be type `usize`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:38:17
|
||||
|
|
||||
LL | let i = [0; I { i: () }];
|
||||
| ^^^^^^^^^^^ expected `usize`, found `I`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:29:17
|
||||
|
|
||||
LL | let h = [0; 4u8];
|
||||
| ^^^ expected `usize`, found `u8`
|
||||
|
|
||||
help: change the type of the numeric literal from `u8` to `usize`
|
||||
|
|
||||
LL - let f = [0; 4u8];
|
||||
LL + let f = [0; 4usize];
|
||||
LL - let h = [0; 4u8];
|
||||
LL + let h = [0; 4usize];
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/repeat_count.rs:33:17
|
||||
|
|
||||
LL | let g = [0; G { g: () }];
|
||||
| ^^^^^^^^^^^ expected `usize`, found `G`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0435.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
|
||||
Reference in New Issue
Block a user