Evaluate repeat expression lengths as late as possible

This commit is contained in:
Oliver Scherer 2020-03-14 15:30:35 +01:00
parent 8ff785011b
commit 799b15ed96
46 changed files with 279 additions and 264 deletions

View file

@ -7,10 +7,5 @@ fn main() {
//~^ ERROR `while` is not allowed in a `const`
//~| WARN denote infinite loops with
[(); { for _ in 0usize.. {}; 0}];
//~^ ERROR calls in constants are limited to constant functions
//~| ERROR calls in constants are limited to constant functions
//~| ERROR `for` is not allowed in a `const`
//~| ERROR references in constants may only refer to immutable values
//~| ERROR evaluation of constant value failed
//~| ERROR constant contains unimplemented expression type
//~^ ERROR `for` is not allowed in a `const`
}

View file

@ -3,4 +3,5 @@ fn main() {
//~^ ERROR: invalid label name `'static`
//~| ERROR: `loop` is not allowed in a `const`
//~| ERROR: type annotations needed
//~| ERROR mismatched types
}

View file

@ -19,7 +19,15 @@ error[E0282]: type annotations needed
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
| ^ consider giving this closure parameter a type
error: aborting due to 3 previous errors
error[E0308]: mismatched types
--> $DIR/issue-52437.rs:2:5
|
LL | fn main() {
| - expected `()` because of default return type
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[(); _]`
Some errors have detailed explanations: E0282, E0658.
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0282, E0308, E0658.
For more information about an error, try `rustc --explain E0282`.

View file

@ -1,9 +1,10 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
// build-pass
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; N]
//~^ ERROR array lengths can't depend on generic parameters
}
fn main() {

View file

@ -6,11 +6,3 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error: array lengths can't depend on generic parameters
--> $DIR/issue-61336-1.rs:5:9
|
LL | [x; N]
| ^
error: aborting due to previous error

View file

@ -2,13 +2,12 @@
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; {N}]
//~^ ERROR array lengths can't depend on generic parameters
[x; { N }]
}
fn g<T, const N: usize>(x: T) -> [T; N] {
[x; {N}]
//~^ ERROR array lengths can't depend on generic parameters
[x; { N }]
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied
}
fn main() {

View file

@ -6,17 +6,19 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error: array lengths can't depend on generic parameters
--> $DIR/issue-61336-2.rs:5:9
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-61336-2.rs:9:5
|
LL | [x; {N}]
| ^^^
error: array lengths can't depend on generic parameters
--> $DIR/issue-61336-2.rs:10:9
LL | [x; { N }]
| ^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
LL | [x; {N}]
| ^^^
help: consider restricting this type parameter with `T: std::marker::Copy`
--> $DIR/issue-61336-2.rs:8:6
|
LL | fn g<T, const N: usize>(x: T) -> [T; N] {
| ^
= note: the `Copy` trait is required because the repeated element will be copied
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -3,12 +3,11 @@
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; N]
//~^ ERROR array lengths can't depend on generic parameters
}
fn g<T, const N: usize>(x: T) -> [T; N] {
[x; N]
//~^ ERROR array lengths can't depend on generic parameters
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied
}
fn main() {

View file

@ -6,17 +6,19 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error: array lengths can't depend on generic parameters
--> $DIR/issue-61336.rs:5:9
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-61336.rs:9:5
|
LL | [x; N]
| ^
error: array lengths can't depend on generic parameters
--> $DIR/issue-61336.rs:10:9
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
LL | [x; N]
| ^
help: consider restricting this type parameter with `T: std::marker::Copy`
--> $DIR/issue-61336.rs:8:6
|
LL | fn g<T, const N: usize>(x: T) -> [T; N] {
| ^
= note: the `Copy` trait is required because the repeated element will be copied
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,9 +1,10 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
// build-pass
fn foo<const N: usize>() {
let _ = [0u64; N + 1];
//~^ ERROR array lengths can't depend on generic parameters
}
fn main() {}

View file

@ -6,11 +6,3 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error: array lengths can't depend on generic parameters
--> $DIR/issue-62456.rs:5:20
|
LL | let _ = [0u64; N + 1];
| ^^^^^
error: aborting due to previous error

View file

@ -16,7 +16,7 @@ struct ArrayHolder<const X: usize>([u32; X]);
impl<const X: usize> ArrayHolder<{ X }> {
pub const fn new() -> Self {
ArrayHolder([0; Self::SIZE])
//~^ ERROR: array lengths can't depend on generic parameters
//~^ ERROR: mismatched types
}
}

View file

@ -1,8 +1,12 @@
error: array lengths can't depend on generic parameters
--> $DIR/issue-62504.rs:18:25
error[E0308]: mismatched types
--> $DIR/issue-62504.rs:18:21
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^
| ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE`
|
= note: expected array `[u32; _]`
found array `[u32; _]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,5 +1,7 @@
// Regression test for #67739
// check-pass
#![allow(incomplete_features)]
#![feature(const_generics)]
@ -10,7 +12,6 @@ pub trait Trait {
fn associated_size(&self) -> usize {
[0u8; mem::size_of::<Self::Associated>()];
//~^ ERROR: array lengths can't depend on generic parameters
0
}
}

View file

@ -1,8 +0,0 @@
error: array lengths can't depend on generic parameters
--> $DIR/issue-67739.rs:12:15
|
LL | [0u8; mem::size_of::<Self::Associated>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -19,6 +19,7 @@ const A_I8_I
: [u32; (i8::MAX as usize) + 1]
= [0; (i8::MAX + 1) as usize];
//~^ ERROR evaluation of constant value failed
//~| ERROR mismatched types
fn main() {
foo(&A_I8_I[..]);

View file

@ -4,6 +4,16 @@ error[E0080]: evaluation of constant value failed
LL | = [0; (i8::MAX + 1) as usize];
| ^^^^^^^^^^^^^ attempt to add with overflow
error: aborting due to previous error
error[E0308]: mismatched types
--> $DIR/const-eval-overflow-3.rs:20:7
|
LL | = [0; (i8::MAX + 1) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1) as usize`
|
= note: expected array `[u32; 128]`
found array `[u32; _]`
For more information about this error, try `rustc --explain E0080`.
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0308.
For more information about an error, try `rustc --explain E0080`.

View file

@ -18,6 +18,7 @@ const A_I8_I
= [0; (i8::MAX + 1u8) as usize];
//~^ ERROR mismatched types
//~| ERROR cannot add `u8` to `i8`
//~| ERROR mismatched types
fn main() {
foo(&A_I8_I[..]);

View file

@ -12,7 +12,16 @@ LL | = [0; (i8::MAX + 1u8) as usize];
|
= help: the trait `std::ops::Add<u8>` is not implemented for `i8`
error: aborting due to 2 previous errors
error[E0308]: mismatched types
--> $DIR/const-eval-overflow-3b.rs:18:7
|
LL | = [0; (i8::MAX + 1u8) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1u8) as usize`
|
= note: expected array `[u32; 128]`
found array `[u32; _]`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,6 +1,4 @@
fn main() {
[(); { &loop { break } as *const _ as usize } ];
//~^ ERROR casting pointers to integers in constants is unstable
//~| ERROR `loop` is not allowed in a `const`
//~| ERROR evaluation of constant value failed
//~^ ERROR `loop` is not allowed in a `const`
}

View file

@ -7,22 +7,6 @@ LL | [(); { &loop { break } as *const _ as usize } ];
= note: see issue #52000 <https://github.com/rust-lang/rust/issues/52000> for more information
= help: add `#![feature(const_loop)]` to the crate attributes to enable
error[E0658]: casting pointers to integers in constants is unstable
--> $DIR/issue-52442.rs:2:13
|
LL | [(); { &loop { break } as *const _ as usize } ];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
error: aborting due to previous error
error[E0080]: evaluation of constant value failed
--> $DIR/issue-52442.rs:2:13
|
LL | [(); { &loop { break } as *const _ as usize } ];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0080, E0658.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0658`.

View file

@ -2,7 +2,7 @@ fn main() {
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
// bytes.
let _: [u8; 0] = [4; {
let _: [u8; 0] = [4; { //~ ERROR mismatched types
match &1 as *const i32 as usize {
//~^ ERROR casting pointers to integers in constants
//~| ERROR `match` is not allowed in a `const`

View file

@ -28,7 +28,30 @@ error[E0080]: evaluation of constant value failed
LL | match &1 as *const i32 as usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: aborting due to 3 previous errors
error[E0308]: mismatched types
--> $DIR/match-test-ptr-null.rs:5:22
|
LL | let _: [u8; 0] = [4; {
| ____________-------___^
| | |
| | expected due to this
LL | | match &1 as *const i32 as usize {
LL | |
LL | |
... |
LL | | }
LL | | }];
| |______^ expected `0usize`, found `{
match &1 as *const i32 as usize {
0 => 42,
n => n,
}
}`
|
= note: expected array `[u8; 0]`
found array `[u8; _]`
Some errors have detailed explanations: E0080, E0658.
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0080, E0308, E0658.
For more information about an error, try `rustc --explain E0080`.

View file

@ -6,5 +6,4 @@ fn main() {
//~| ERROR: type annotations needed
[(); &(static || {}) as *const _ as usize];
//~^ ERROR: closures cannot be static
//~| ERROR: evaluation of constant value failed
}

View file

@ -16,13 +16,7 @@ error[E0282]: type annotations needed
LL | [(); &(static |x| {}) as *const _ as usize];
| ^ consider giving this closure parameter a type
error[E0080]: evaluation of constant value failed
--> $DIR/issue-52432.rs:7:10
|
LL | [(); &(static || {}) as *const _ as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0080, E0282, E0697.
For more information about an error, try `rustc --explain E0080`.
Some errors have detailed explanations: E0282, E0697.
For more information about an error, try `rustc --explain E0282`.

View file

@ -7,6 +7,7 @@ impl<A, B> Foo<A, B> {
[5; Self::HOST_SIZE] == [6; 0] //~ ERROR no associated item named `HOST_SIZE`
//~^ the size for values of type `A` cannot be known
//~| the size for values of type `B` cannot be known
//~| binary operation `==` cannot be applied to type `[{integer}; _]`
}
}

View file

@ -41,7 +41,15 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
= help: the trait `std::marker::Sized` is not implemented for `B`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
error: aborting due to 3 previous errors
error[E0369]: binary operation `==` cannot be applied to type `[{integer}; _]`
--> $DIR/too_generic_eval_ice.rs:7:30
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| -------------------- ^^ ------ [{integer}; 0]
| |
| [{integer}; _]
Some errors have detailed explanations: E0277, E0599.
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0369, E0599.
For more information about an error, try `rustc --explain E0277`.

View file

@ -17,4 +17,5 @@ fn main() {
= [0; Dim3::dim()];
//~^ ERROR E0015
//~| ERROR E0080
//~| ERROR mismatched types
}

View file

@ -22,7 +22,19 @@ error[E0080]: evaluation of constant value failed
LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
error: aborting due to 4 previous errors
error[E0308]: mismatched types
--> $DIR/issue-39559-2.rs:17:11
|
LL | let array: [usize; Dim3::dim()]
| -------------------- expected due to this
...
LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^^^^^^ expected `Dim3::dim()`, found `Dim3::dim()`
|
= note: expected array `[usize; _]`
found array `[usize; _]`
Some errors have detailed explanations: E0015, E0080.
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0015, E0080, E0308.
For more information about an error, try `rustc --explain E0015`.

View file

@ -4,5 +4,6 @@ static A: &'static [u32] = &[1];
static B: [u32; 1] = [0; A.len()];
//~^ ERROR [E0013]
//~| ERROR evaluation of constant value failed
//~| ERROR mismatched types
fn main() {}

View file

@ -12,7 +12,16 @@ error[E0080]: evaluation of constant value failed
LL | static B: [u32; 1] = [0; A.len()];
| ^ constant accesses static
error: aborting due to 2 previous errors
error[E0308]: mismatched types
--> $DIR/issue-52060.rs:4:22
|
LL | static B: [u32; 1] = [0; A.len()];
| ^^^^^^^^^^^^ expected `1usize`, found `A.len()`
|
= note: expected array `[u32; 1]`
found array `[u32; _]`
Some errors have detailed explanations: E0013, E0080.
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0013, E0080, E0308.
For more information about an error, try `rustc --explain E0013`.

View file

@ -19,5 +19,4 @@ impl TraitB for B { //~ ERROR not all trait items implemented, missing: `MyA`
fn main() {
let _ = [0; B::VALUE];
//~^ ERROR array lengths can't depend on generic parameters
}

View file

@ -13,13 +13,7 @@ LL | type MyA: TraitA;
LL | impl TraitB for B {
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation
error: array lengths can't depend on generic parameters
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:21:17
|
LL | let _ = [0; B::VALUE];
| ^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0046, E0437.
For more information about an error, try `rustc --explain E0046`.

View file

@ -28,6 +28,12 @@ error[E0308]: mismatched types
LL | let e = [0; "foo"];
| ^^^^^ expected `usize`, found `&str`
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:28:17
|
LL | let g = [0; G { g: () }];
| ^^^^^^^^^^^ expected `usize`, found struct `main::G`
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:19:17
|
@ -50,12 +56,6 @@ help: you can convert an `isize` to `usize` and panic if the converted value wou
LL | let f = [0_usize; (-1_isize).try_into().unwrap()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:28:17
|
LL | let g = [0; G { g: () }];
| ^^^^^^^^^^^ expected `usize`, found struct `main::G`
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0308, E0435.

View file

@ -24,6 +24,7 @@ fn i<const N: usize>() {
static a: [u8; N] = [0; N];
//~^ ERROR can't use generic parameters from outer function
//~^^ ERROR can't use generic parameters from outer function
//~| ERROR mismatched types
}
fn main() {}

View file

@ -48,6 +48,16 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error: aborting due to 5 previous errors
error[E0308]: mismatched types
--> $DIR/issue-65035-static-with-parent-generics.rs:24:25
|
LL | static a: [u8; N] = [0; N];
| ^^^^^^ expected `N`, found `N`
|
= note: expected array `[u8; _]`
found array `[u8; _]`
For more information about this error, try `rustc --explain E0401`.
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0308, E0401.
For more information about an error, try `rustc --explain E0308`.