Bless less verbose error messages

The MIR const-checker errors for if/match/loop are now delay span bugs,
so nothing will be emitted unless the HIR checker misses something.
This commit is contained in:
Dylan MacKenzie 2019-11-09 09:29:57 -08:00
parent 70aa781c2d
commit 86734b13bb
13 changed files with 68 additions and 168 deletions

View file

@ -7,8 +7,6 @@ const fn f(x: usize) -> usize {
for i in 0..x {
//~^ ERROR E0015
//~| ERROR E0017
//~| ERROR E0019
//~| ERROR E0019
//~| ERROR E0080
//~| ERROR E0744
sum += i;

View file

@ -4,15 +4,11 @@ fn main() {
[(); loop { break }]; //~ ERROR mismatched types
//~^ ERROR `loop` is not allowed in a `const`
[(); {while true {break}; 0}];
//~^ ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR `while` is not allowed in a `const`
//~^ 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 `for` is not allowed in a `const`
//~| ERROR references in constants may only refer to immutable values
//~| ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR evaluation of constant value failed
}

View file

@ -5,9 +5,7 @@ fn main() {
//~^ WARNING Constant evaluating a complex constant, this might take some time
let mut n = 113383; // #20 in https://oeis.org/A006884
while n != 0 {
//~^ ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR `while` is not allowed in a `const`
//~^ ERROR `while` is not allowed in a `const`
n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
//~^ ERROR evaluation of constant value failed
//~| ERROR `if` is not allowed in a `const`

View file

@ -3,37 +3,18 @@ error[E0744]: `while` is not allowed in a `const`
|
LL | / while n != 0 {
LL | |
LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
LL | |
LL | |
... |
LL | |
LL | | }
| |_________^
error[E0744]: `if` is not allowed in a `const`
--> $DIR/infinite_loop.rs:11:17
--> $DIR/infinite_loop.rs:9:17
|
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0019]: constant contains unimplemented expression type
--> $DIR/infinite_loop.rs:7:15
|
LL | while n != 0 {
| ^^^^^^
error[E0019]: constant contains unimplemented expression type
--> $DIR/infinite_loop.rs:7:9
|
LL | / while n != 0 {
LL | |
LL | |
LL | |
... |
LL | |
LL | | }
| |_________^
warning: Constant evaluating a complex constant, this might take some time
--> $DIR/infinite_loop.rs:4:18
|
@ -48,12 +29,12 @@ LL | | }];
| |_____^
error[E0080]: evaluation of constant value failed
--> $DIR/infinite_loop.rs:11:20
--> $DIR/infinite_loop.rs:9:20
|
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
| ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
error: aborting due to 5 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0019, E0080, E0744.
For more information about an error, try `rustc --explain E0019`.
Some errors have detailed explanations: E0080, E0744.
For more information about an error, try `rustc --explain E0080`.

View file

@ -5,8 +5,6 @@ fn main() {
let mut n = 0;
while n < 5 {
//~^ ERROR `while` is not allowed in a `const`
//~| ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
n = (n + 1) % 5; //~ ERROR evaluation of constant value failed
x = &0; // Materialize a new AllocId
}

View file

@ -3,26 +3,6 @@ error[E0744]: `while` is not allowed in a `const`
|
LL | / while n < 5 {
LL | |
LL | |
LL | |
LL | | n = (n + 1) % 5;
LL | | x = &0; // Materialize a new AllocId
LL | | }
| |_________^
error[E0019]: constant contains unimplemented expression type
--> $DIR/issue-52475.rs:6:15
|
LL | while n < 5 {
| ^^^^^
error[E0019]: constant contains unimplemented expression type
--> $DIR/issue-52475.rs:6:9
|
LL | / while n < 5 {
LL | |
LL | |
LL | |
LL | | n = (n + 1) % 5;
LL | | x = &0; // Materialize a new AllocId
LL | | }
@ -42,12 +22,12 @@ LL | | }];
| |_____^
error[E0080]: evaluation of constant value failed
--> $DIR/issue-52475.rs:10:17
--> $DIR/issue-52475.rs:8:17
|
LL | n = (n + 1) % 5;
| ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
error: aborting due to 4 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0019, E0080, E0744.
For more information about an error, try `rustc --explain E0019`.
Some errors have detailed explanations: E0080, E0744.
For more information about an error, try `rustc --explain E0080`.

View file

@ -6,9 +6,8 @@ fn main() {
match &1 as *const i32 as usize {
//~^ ERROR casting pointers to integers in constants
//~| ERROR `match` is not allowed in a `const`
//~| ERROR constant contains unimplemented expression type
//~| ERROR evaluation of constant value failed
0 => 42, //~ ERROR constant contains unimplemented expression type
0 => 42,
n => n,
}
}];

View file

@ -5,7 +5,7 @@ LL | / match &1 as *const i32 as usize {
LL | |
LL | |
LL | |
... |
LL | | 0 => 42,
LL | | n => n,
LL | | }
| |_________^
@ -19,25 +19,13 @@ LL | match &1 as *const i32 as usize {
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
error[E0019]: constant contains unimplemented expression type
--> $DIR/match-test-ptr-null.rs:6:15
|
LL | match &1 as *const i32 as usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0019]: constant contains unimplemented expression type
--> $DIR/match-test-ptr-null.rs:11:13
|
LL | 0 => 42,
| ^
error[E0080]: evaluation of constant value failed
--> $DIR/match-test-ptr-null.rs:6:15
|
LL | match &1 as *const i32 as usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: aborting due to 5 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0019, E0080, E0658, E0744.
For more information about an error, try `rustc --explain E0019`.
Some errors have detailed explanations: E0080, E0658, E0744.
For more information about an error, try `rustc --explain E0080`.

View file

@ -30,8 +30,6 @@ fn main() {
let x = [0; {
while false {}
//~^ ERROR `while` is not allowed in a `const`
//~| ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
4
}];
}

View file

@ -29,7 +29,7 @@ LL | while false {}
| ^^^^^^^^^^^^^^
error[E0744]: `while` is not allowed in a `const`
--> $DIR/const-loop.rs:42:5
--> $DIR/const-loop.rs:40:5
|
LL | / while x < 4 {
LL | | x += 1;
@ -37,7 +37,7 @@ LL | | }
| |_____^
error[E0744]: `while` is not allowed in a `const`
--> $DIR/const-loop.rs:46:5
--> $DIR/const-loop.rs:44:5
|
LL | / while x < 8 {
LL | | x += 1;
@ -45,7 +45,7 @@ LL | | }
| |_____^
error[E0744]: `for` is not allowed in a `const`
--> $DIR/const-loop.rs:56:5
--> $DIR/const-loop.rs:54:5
|
LL | / for i in 0..4 {
LL | | x += i;
@ -53,7 +53,7 @@ LL | | }
| |_____^
error[E0744]: `for` is not allowed in a `const`
--> $DIR/const-loop.rs:60:5
--> $DIR/const-loop.rs:58:5
|
LL | / for i in 0..4 {
LL | | x += i;
@ -61,7 +61,7 @@ LL | | }
| |_____^
error[E0744]: `loop` is not allowed in a `const`
--> $DIR/const-loop.rs:70:5
--> $DIR/const-loop.rs:68:5
|
LL | / loop {
LL | | x += 1;
@ -72,7 +72,7 @@ LL | | }
| |_____^
error[E0744]: `if` is not allowed in a `const`
--> $DIR/const-loop.rs:72:9
--> $DIR/const-loop.rs:70:9
|
LL | / if x == 4 {
LL | | break;
@ -80,7 +80,7 @@ LL | | }
| |_________^
error[E0744]: `loop` is not allowed in a `const`
--> $DIR/const-loop.rs:77:5
--> $DIR/const-loop.rs:75:5
|
LL | / loop {
LL | | x += 1;
@ -91,7 +91,7 @@ LL | | }
| |_____^
error[E0744]: `if` is not allowed in a `const`
--> $DIR/const-loop.rs:79:9
--> $DIR/const-loop.rs:77:9
|
LL | / if x == 8 {
LL | | break;
@ -99,13 +99,13 @@ LL | | }
| |_________^
error[E0744]: `while let` is not allowed in a `const`
--> $DIR/const-loop.rs:89:5
--> $DIR/const-loop.rs:87:5
|
LL | while let None = Some(x) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0744]: `while let` is not allowed in a `const`
--> $DIR/const-loop.rs:90:5
--> $DIR/const-loop.rs:88:5
|
LL | while let None = Some(x) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -122,19 +122,6 @@ error[E0744]: `loop` is not allowed in a `const`
LL | const BAR: i32 = loop { break 4; };
| ^^^^^^^^^^^^^^^^^
error[E0019]: constant contains unimplemented expression type
--> $DIR/const-loop.rs:31:15
|
LL | while false {}
| ^^^^^
error: aborting due to 17 previous errors
error[E0019]: constant contains unimplemented expression type
--> $DIR/const-loop.rs:31:9
|
LL | while false {}
| ^^^^^^^^^^^^^^
error: aborting due to 19 previous errors
Some errors have detailed explanations: E0019, E0744.
For more information about an error, try `rustc --explain E0019`.
For more information about this error, try `rustc --explain E0744`.

View file

@ -1,24 +1,43 @@
warning: skipping const checks
--> $DIR/enum_discriminants.rs:23:13
--> $DIR/enum_discriminants.rs:24:5
|
LL | let x = Foo::B;
| ^^^^^^
LL | / match x {
LL | | Foo::B => 0,
LL | | _ => panic!(),
LL | | }
| |_____^
warning: skipping const checks
--> $DIR/enum_discriminants.rs:25:9
--> $DIR/enum_discriminants.rs:88:5
|
LL | Foo::B => 0,
| ^^^^^^
LL | / if let E1::V2 { .. } = (E1::V1 { f: true }) {
LL | | unreachable!()
LL | | }
| |_____^
warning: skipping const checks
--> $DIR/enum_discriminants.rs:88:28
--> $DIR/enum_discriminants.rs:91:5
|
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
| ^^^^^^^^^^^^^^^^^^^^
LL | / if let E1::V1 { .. } = (E1::V1 { f: true }) {
LL | | } else {
LL | | unreachable!()
LL | | }
| |_____^
warning: skipping const checks
--> $DIR/enum_discriminants.rs:88:12
--> $DIR/enum_discriminants.rs:96:5
|
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
| ^^^^^^^^^^^^^
LL | / if let E2::V1 { .. } = E2::V3::<Infallible> {
LL | | unreachable!()
LL | | }
| |_____^
warning: skipping const checks
--> $DIR/enum_discriminants.rs:99:5
|
LL | / if let E2::V3 { .. } = E2::V3::<Infallible> {
LL | | } else {
LL | | unreachable!()
LL | | }
| |_____^

View file

@ -216,22 +216,16 @@ fn inside_const_generic_arguments() {
if let A::<{
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
//~^ ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR `match` is not allowed in a `const`
}>::O = 5 {}
while let A::<{
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
//~^ ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR `match` is not allowed in a `const`
}>::O = 5 {}
if A::<{
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
//~^ ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
//~| ERROR `match` is not allowed in a `const`
}>::O == 5 {}

View file

@ -1,5 +1,5 @@
error: expected one of `,` or `>`, found `&&`
--> $DIR/disallowed-positions.rs:245:14
--> $DIR/disallowed-positions.rs:239:14
|
LL | true && let 1 = 1
| ^^ expected one of `,` or `>`
@ -482,7 +482,7 @@ LL | true && let 1 = 1
= note: as well as when nested within `&&` and parenthesis in those conditions
error: `let` expressions are not supported here
--> $DIR/disallowed-positions.rs:225:17
--> $DIR/disallowed-positions.rs:223:17
|
LL | true && let 1 = 1
| ^^^^^^^^^
@ -491,7 +491,7 @@ LL | true && let 1 = 1
= note: as well as when nested within `&&` and parenthesis in those conditions
error: `let` expressions are not supported here
--> $DIR/disallowed-positions.rs:232:17
--> $DIR/disallowed-positions.rs:228:17
|
LL | true && let 1 = 1
| ^^^^^^^^^
@ -520,13 +520,13 @@ LL | true && let 1 = 1
| ^^^^^^^^^
error[E0744]: `match` is not allowed in a `const`
--> $DIR/disallowed-positions.rs:225:17
--> $DIR/disallowed-positions.rs:223:17
|
LL | true && let 1 = 1
| ^^^^^^^^^
error[E0744]: `match` is not allowed in a `const`
--> $DIR/disallowed-positions.rs:232:17
--> $DIR/disallowed-positions.rs:228:17
|
LL | true && let 1 = 1
| ^^^^^^^^^
@ -971,43 +971,7 @@ LL | let 0 = 0?;
= help: the trait `std::ops::Try` is not implemented for `{integer}`
= note: required by `std::ops::Try::into_result`
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:218:25
|
LL | true && let 1 = 1
| ^
error: aborting due to 106 previous errors
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:218:21
|
LL | true && let 1 = 1
| ^
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:225:25
|
LL | true && let 1 = 1
| ^
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:225:21
|
LL | true && let 1 = 1
| ^
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:232:25
|
LL | true && let 1 = 1
| ^
error[E0019]: constant contains unimplemented expression type
--> $DIR/disallowed-positions.rs:232:21
|
LL | true && let 1 = 1
| ^
error: aborting due to 112 previous errors
Some errors have detailed explanations: E0019, E0277, E0308, E0600, E0614, E0744.
For more information about an error, try `rustc --explain E0019`.
Some errors have detailed explanations: E0277, E0308, E0600, E0614, E0744.
For more information about an error, try `rustc --explain E0277`.