Skip to content

Commit 5e81914

Browse files
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.
1 parent d28d5c4 commit 5e81914

13 files changed

+68
-168
lines changed

src/test/compile-fail/consts/const-fn-error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const fn f(x: usize) -> usize {
77
for i in 0..x {
88
//~^ ERROR E0015
99
//~| ERROR E0017
10-
//~| ERROR E0019
11-
//~| ERROR E0019
1210
//~| ERROR E0080
1311
//~| ERROR E0744
1412
sum += i;

src/test/compile-fail/issue-52443.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ fn main() {
44
[(); loop { break }]; //~ ERROR mismatched types
55
//~^ ERROR `loop` is not allowed in a `const`
66
[(); {while true {break}; 0}];
7-
//~^ ERROR constant contains unimplemented expression type
8-
//~| ERROR constant contains unimplemented expression type
9-
//~| ERROR `while` is not allowed in a `const`
7+
//~^ ERROR `while` is not allowed in a `const`
108
//~| WARN denote infinite loops with
119
[(); { for _ in 0usize.. {}; 0}];
1210
//~^ ERROR calls in constants are limited to constant functions
1311
//~| ERROR `for` is not allowed in a `const`
1412
//~| ERROR references in constants may only refer to immutable values
15-
//~| ERROR constant contains unimplemented expression type
16-
//~| ERROR constant contains unimplemented expression type
1713
//~| ERROR evaluation of constant value failed
1814
}

src/test/ui/consts/const-eval/infinite_loop.rs

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

src/test/ui/consts/const-eval/infinite_loop.stderr

+6-25
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,18 @@ error[E0744]: `while` is not allowed in a `const`
33
|
44
LL | / while n != 0 {
55
LL | |
6+
LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
67
LL | |
78
LL | |
8-
... |
9-
LL | |
109
LL | | }
1110
| |_________^
1211

1312
error[E0744]: `if` is not allowed in a `const`
14-
--> $DIR/infinite_loop.rs:11:17
13+
--> $DIR/infinite_loop.rs:9:17
1514
|
1615
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
1716
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1817

19-
error[E0019]: constant contains unimplemented expression type
20-
--> $DIR/infinite_loop.rs:7:15
21-
|
22-
LL | while n != 0 {
23-
| ^^^^^^
24-
25-
error[E0019]: constant contains unimplemented expression type
26-
--> $DIR/infinite_loop.rs:7:9
27-
|
28-
LL | / while n != 0 {
29-
LL | |
30-
LL | |
31-
LL | |
32-
... |
33-
LL | |
34-
LL | | }
35-
| |_________^
36-
3718
warning: Constant evaluating a complex constant, this might take some time
3819
--> $DIR/infinite_loop.rs:4:18
3920
|
@@ -48,12 +29,12 @@ LL | | }];
4829
| |_____^
4930

5031
error[E0080]: evaluation of constant value failed
51-
--> $DIR/infinite_loop.rs:11:20
32+
--> $DIR/infinite_loop.rs:9:20
5233
|
5334
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
5435
| ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
5536

56-
error: aborting due to 5 previous errors
37+
error: aborting due to 3 previous errors
5738

58-
Some errors have detailed explanations: E0019, E0080, E0744.
59-
For more information about an error, try `rustc --explain E0019`.
39+
Some errors have detailed explanations: E0080, E0744.
40+
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/issue-52475.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ fn main() {
55
let mut n = 0;
66
while n < 5 {
77
//~^ ERROR `while` is not allowed in a `const`
8-
//~| ERROR constant contains unimplemented expression type
9-
//~| ERROR constant contains unimplemented expression type
108
n = (n + 1) % 5; //~ ERROR evaluation of constant value failed
119
x = &0; // Materialize a new AllocId
1210
}

src/test/ui/consts/const-eval/issue-52475.stderr

+4-24
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,6 @@ error[E0744]: `while` is not allowed in a `const`
33
|
44
LL | / while n < 5 {
55
LL | |
6-
LL | |
7-
LL | |
8-
LL | | n = (n + 1) % 5;
9-
LL | | x = &0; // Materialize a new AllocId
10-
LL | | }
11-
| |_________^
12-
13-
error[E0019]: constant contains unimplemented expression type
14-
--> $DIR/issue-52475.rs:6:15
15-
|
16-
LL | while n < 5 {
17-
| ^^^^^
18-
19-
error[E0019]: constant contains unimplemented expression type
20-
--> $DIR/issue-52475.rs:6:9
21-
|
22-
LL | / while n < 5 {
23-
LL | |
24-
LL | |
25-
LL | |
266
LL | | n = (n + 1) % 5;
277
LL | | x = &0; // Materialize a new AllocId
288
LL | | }
@@ -42,12 +22,12 @@ LL | | }];
4222
| |_____^
4323

4424
error[E0080]: evaluation of constant value failed
45-
--> $DIR/issue-52475.rs:10:17
25+
--> $DIR/issue-52475.rs:8:17
4626
|
4727
LL | n = (n + 1) % 5;
4828
| ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
4929

50-
error: aborting due to 4 previous errors
30+
error: aborting due to 2 previous errors
5131

52-
Some errors have detailed explanations: E0019, E0080, E0744.
53-
For more information about an error, try `rustc --explain E0019`.
32+
Some errors have detailed explanations: E0080, E0744.
33+
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/match-test-ptr-null.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ fn main() {
66
match &1 as *const i32 as usize {
77
//~^ ERROR casting pointers to integers in constants
88
//~| ERROR `match` is not allowed in a `const`
9-
//~| ERROR constant contains unimplemented expression type
109
//~| ERROR evaluation of constant value failed
11-
0 => 42, //~ ERROR constant contains unimplemented expression type
10+
0 => 42,
1211
n => n,
1312
}
1413
}];

src/test/ui/consts/const-eval/match-test-ptr-null.stderr

+4-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | / match &1 as *const i32 as usize {
55
LL | |
66
LL | |
77
LL | |
8-
... |
8+
LL | | 0 => 42,
99
LL | | n => n,
1010
LL | | }
1111
| |_________^
@@ -19,25 +19,13 @@ LL | match &1 as *const i32 as usize {
1919
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
2020
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
2121

22-
error[E0019]: constant contains unimplemented expression type
23-
--> $DIR/match-test-ptr-null.rs:6:15
24-
|
25-
LL | match &1 as *const i32 as usize {
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
27-
28-
error[E0019]: constant contains unimplemented expression type
29-
--> $DIR/match-test-ptr-null.rs:11:13
30-
|
31-
LL | 0 => 42,
32-
| ^
33-
3422
error[E0080]: evaluation of constant value failed
3523
--> $DIR/match-test-ptr-null.rs:6:15
3624
|
3725
LL | match &1 as *const i32 as usize {
3826
| ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
3927

40-
error: aborting due to 5 previous errors
28+
error: aborting due to 3 previous errors
4129

42-
Some errors have detailed explanations: E0019, E0080, E0658, E0744.
43-
For more information about an error, try `rustc --explain E0019`.
30+
Some errors have detailed explanations: E0080, E0658, E0744.
31+
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/const-loop.rs

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ fn main() {
3030
let x = [0; {
3131
while false {}
3232
//~^ ERROR `while` is not allowed in a `const`
33-
//~| ERROR constant contains unimplemented expression type
34-
//~| ERROR constant contains unimplemented expression type
3533
4
3634
}];
3735
}

src/test/ui/consts/const-loop.stderr

+12-25
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,39 @@ LL | while false {}
2929
| ^^^^^^^^^^^^^^
3030

3131
error[E0744]: `while` is not allowed in a `const`
32-
--> $DIR/const-loop.rs:42:5
32+
--> $DIR/const-loop.rs:40:5
3333
|
3434
LL | / while x < 4 {
3535
LL | | x += 1;
3636
LL | | }
3737
| |_____^
3838

3939
error[E0744]: `while` is not allowed in a `const`
40-
--> $DIR/const-loop.rs:46:5
40+
--> $DIR/const-loop.rs:44:5
4141
|
4242
LL | / while x < 8 {
4343
LL | | x += 1;
4444
LL | | }
4545
| |_____^
4646

4747
error[E0744]: `for` is not allowed in a `const`
48-
--> $DIR/const-loop.rs:56:5
48+
--> $DIR/const-loop.rs:54:5
4949
|
5050
LL | / for i in 0..4 {
5151
LL | | x += i;
5252
LL | | }
5353
| |_____^
5454

5555
error[E0744]: `for` is not allowed in a `const`
56-
--> $DIR/const-loop.rs:60:5
56+
--> $DIR/const-loop.rs:58:5
5757
|
5858
LL | / for i in 0..4 {
5959
LL | | x += i;
6060
LL | | }
6161
| |_____^
6262

6363
error[E0744]: `loop` is not allowed in a `const`
64-
--> $DIR/const-loop.rs:70:5
64+
--> $DIR/const-loop.rs:68:5
6565
|
6666
LL | / loop {
6767
LL | | x += 1;
@@ -72,15 +72,15 @@ LL | | }
7272
| |_____^
7373

7474
error[E0744]: `if` is not allowed in a `const`
75-
--> $DIR/const-loop.rs:72:9
75+
--> $DIR/const-loop.rs:70:9
7676
|
7777
LL | / if x == 4 {
7878
LL | | break;
7979
LL | | }
8080
| |_________^
8181

8282
error[E0744]: `loop` is not allowed in a `const`
83-
--> $DIR/const-loop.rs:77:5
83+
--> $DIR/const-loop.rs:75:5
8484
|
8585
LL | / loop {
8686
LL | | x += 1;
@@ -91,21 +91,21 @@ LL | | }
9191
| |_____^
9292

9393
error[E0744]: `if` is not allowed in a `const`
94-
--> $DIR/const-loop.rs:79:9
94+
--> $DIR/const-loop.rs:77:9
9595
|
9696
LL | / if x == 8 {
9797
LL | | break;
9898
LL | | }
9999
| |_________^
100100

101101
error[E0744]: `while let` is not allowed in a `const`
102-
--> $DIR/const-loop.rs:89:5
102+
--> $DIR/const-loop.rs:87:5
103103
|
104104
LL | while let None = Some(x) { }
105105
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106106

107107
error[E0744]: `while let` is not allowed in a `const`
108-
--> $DIR/const-loop.rs:90:5
108+
--> $DIR/const-loop.rs:88:5
109109
|
110110
LL | while let None = Some(x) { }
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -122,19 +122,6 @@ error[E0744]: `loop` is not allowed in a `const`
122122
LL | const BAR: i32 = loop { break 4; };
123123
| ^^^^^^^^^^^^^^^^^
124124

125-
error[E0019]: constant contains unimplemented expression type
126-
--> $DIR/const-loop.rs:31:15
127-
|
128-
LL | while false {}
129-
| ^^^^^
130-
131-
error[E0019]: constant contains unimplemented expression type
132-
--> $DIR/const-loop.rs:31:9
133-
|
134-
LL | while false {}
135-
| ^^^^^^^^^^^^^^
136-
137-
error: aborting due to 19 previous errors
125+
error: aborting due to 17 previous errors
138126

139-
Some errors have detailed explanations: E0019, E0744.
140-
For more information about an error, try `rustc --explain E0019`.
127+
For more information about this error, try `rustc --explain E0744`.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
warning: skipping const checks
2-
--> $DIR/enum_discriminants.rs:23:13
2+
--> $DIR/enum_discriminants.rs:24:5
33
|
4-
LL | let x = Foo::B;
5-
| ^^^^^^
4+
LL | / match x {
5+
LL | | Foo::B => 0,
6+
LL | | _ => panic!(),
7+
LL | | }
8+
| |_____^
69

710
warning: skipping const checks
8-
--> $DIR/enum_discriminants.rs:25:9
11+
--> $DIR/enum_discriminants.rs:88:5
912
|
10-
LL | Foo::B => 0,
11-
| ^^^^^^
13+
LL | / if let E1::V2 { .. } = (E1::V1 { f: true }) {
14+
LL | | unreachable!()
15+
LL | | }
16+
| |_____^
1217

1318
warning: skipping const checks
14-
--> $DIR/enum_discriminants.rs:88:28
19+
--> $DIR/enum_discriminants.rs:91:5
1520
|
16-
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
17-
| ^^^^^^^^^^^^^^^^^^^^
21+
LL | / if let E1::V1 { .. } = (E1::V1 { f: true }) {
22+
LL | | } else {
23+
LL | | unreachable!()
24+
LL | | }
25+
| |_____^
1826

1927
warning: skipping const checks
20-
--> $DIR/enum_discriminants.rs:88:12
28+
--> $DIR/enum_discriminants.rs:96:5
2129
|
22-
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
23-
| ^^^^^^^^^^^^^
30+
LL | / if let E2::V1 { .. } = E2::V3::<Infallible> {
31+
LL | | unreachable!()
32+
LL | | }
33+
| |_____^
34+
35+
warning: skipping const checks
36+
--> $DIR/enum_discriminants.rs:99:5
37+
|
38+
LL | / if let E2::V3 { .. } = E2::V3::<Infallible> {
39+
LL | | } else {
40+
LL | | unreachable!()
41+
LL | | }
42+
| |_____^
2443

src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs

-6
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,16 @@ fn inside_const_generic_arguments() {
216216

217217
if let A::<{
218218
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
219-
//~^ ERROR constant contains unimplemented expression type
220-
//~| ERROR constant contains unimplemented expression type
221219
//~| ERROR `match` is not allowed in a `const`
222220
}>::O = 5 {}
223221

224222
while let A::<{
225223
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
226-
//~^ ERROR constant contains unimplemented expression type
227-
//~| ERROR constant contains unimplemented expression type
228224
//~| ERROR `match` is not allowed in a `const`
229225
}>::O = 5 {}
230226

231227
if A::<{
232228
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
233-
//~^ ERROR constant contains unimplemented expression type
234-
//~| ERROR constant contains unimplemented expression type
235229
//~| ERROR `match` is not allowed in a `const`
236230
}>::O == 5 {}
237231

0 commit comments

Comments
 (0)