Skip to content

Commit 77f38dc

Browse files
committed
ty: convert ErrorHandled::Reported to ConstKind::Error.
1 parent d7c4081 commit 77f38dc

29 files changed

+54
-295
lines changed

src/librustc_middle/ty/sty.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::ty::{List, ParamEnv, ParamEnvAnd, TyS};
1818
use polonius_engine::Atom;
1919
use rustc_ast::ast::{self, Ident};
2020
use rustc_data_structures::captures::Captures;
21+
use rustc_errors::ErrorReported;
2122
use rustc_hir as hir;
2223
use rustc_hir::def_id::{DefId, LocalDefId};
2324
use rustc_index::vec::Idx;
@@ -2340,6 +2341,8 @@ impl<'tcx> Const<'tcx> {
23402341
/// unevaluated constant.
23412342
pub fn eval(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> &Const<'tcx> {
23422343
if let ConstKind::Unevaluated(did, substs, promoted) = self.val {
2344+
use crate::mir::interpret::ErrorHandled;
2345+
23432346
let param_env_and_substs = param_env.with_reveal_all().and(substs);
23442347

23452348
// HACK(eddyb) this erases lifetimes even though `const_eval_resolve`
@@ -2369,8 +2372,10 @@ impl<'tcx> Const<'tcx> {
23692372
// (which may be identity substs, see above),
23702373
// can leak through `val` into the const we return.
23712374
Ok(val) => Const::from_value(tcx, val, self.ty),
2372-
2373-
Err(_) => self,
2375+
Err(ErrorHandled::TooGeneric | ErrorHandled::Linted) => self,
2376+
Err(ErrorHandled::Reported(ErrorReported)) => {
2377+
tcx.mk_const(ty::Const { val: ty::ConstKind::Error, ty: self.ty })
2378+
}
23742379
}
23752380
} else {
23762381
self

src/test/ui/array-break-length.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
fn main() {
22
loop {
33
|_: [_; break]| {} //~ ERROR: `break` outside of a loop
4-
//~^ ERROR mismatched types
54
}
65

76
loop {
87
|_: [_; continue]| {} //~ ERROR: `continue` outside of a loop
9-
//~^ ERROR mismatched types
108
}
119
}

src/test/ui/array-break-length.stderr

+3-22
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,11 @@ LL | |_: [_; break]| {}
55
| ^^^^^ cannot `break` outside of a loop
66

77
error[E0268]: `continue` outside of a loop
8-
--> $DIR/array-break-length.rs:8:17
8+
--> $DIR/array-break-length.rs:7:17
99
|
1010
LL | |_: [_; continue]| {}
1111
| ^^^^^^^^ cannot `continue` outside of a loop
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/array-break-length.rs:3:9
15-
|
16-
LL | |_: [_; break]| {}
17-
| ^^^^^^^^^^^^^^^^^^ expected `()`, found closure
18-
|
19-
= note: expected unit type `()`
20-
found closure `[closure@$DIR/array-break-length.rs:3:9: 3:27]`
21-
22-
error[E0308]: mismatched types
23-
--> $DIR/array-break-length.rs:8:9
24-
|
25-
LL | |_: [_; continue]| {}
26-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure
27-
|
28-
= note: expected unit type `()`
29-
found closure `[closure@$DIR/array-break-length.rs:8:9: 8:30]`
30-
31-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
3214

33-
Some errors have detailed explanations: E0268, E0308.
34-
For more information about an error, try `rustc --explain E0268`.
15+
For more information about this error, try `rustc --explain E0268`.

src/test/ui/closures/closure-array-break-length.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ fn main() {
22
|_: [_; continue]| {}; //~ ERROR: `continue` outside of a loop
33

44
while |_: [_; continue]| {} {} //~ ERROR: `continue` outside of a loop
5-
//~^ ERROR mismatched types
65

76
while |_: [_; break]| {} {} //~ ERROR: `break` outside of a loop
8-
//~^ ERROR mismatched types
97
}

src/test/ui/closures/closure-array-break-length.stderr

+3-22
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,11 @@ LL | while |_: [_; continue]| {} {}
1111
| ^^^^^^^^ cannot `continue` outside of a loop
1212

1313
error[E0268]: `break` outside of a loop
14-
--> $DIR/closure-array-break-length.rs:7:19
14+
--> $DIR/closure-array-break-length.rs:6:19
1515
|
1616
LL | while |_: [_; break]| {} {}
1717
| ^^^^^ cannot `break` outside of a loop
1818

19-
error[E0308]: mismatched types
20-
--> $DIR/closure-array-break-length.rs:4:11
21-
|
22-
LL | while |_: [_; continue]| {} {}
23-
| ^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found closure
24-
|
25-
= note: expected type `bool`
26-
found closure `[closure@$DIR/closure-array-break-length.rs:4:11: 4:32]`
27-
28-
error[E0308]: mismatched types
29-
--> $DIR/closure-array-break-length.rs:7:11
30-
|
31-
LL | while |_: [_; break]| {} {}
32-
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found closure
33-
|
34-
= note: expected type `bool`
35-
found closure `[closure@$DIR/closure-array-break-length.rs:7:11: 7:29]`
36-
37-
error: aborting due to 5 previous errors
19+
error: aborting due to 3 previous errors
3820

39-
Some errors have detailed explanations: E0268, E0308.
40-
For more information about an error, try `rustc --explain E0268`.
21+
For more information about this error, try `rustc --explain E0268`.

src/test/ui/consts/const-eval/const-eval-overflow-3.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const A_I8_I
1919
: [u32; (i8::MAX as usize) + 1]
2020
= [0; (i8::MAX + 1) as usize];
2121
//~^ ERROR evaluation of constant value failed
22-
//~| ERROR mismatched types
2322

2423
fn main() {
2524
foo(&A_I8_I[..]);

src/test/ui/consts/const-eval/const-eval-overflow-3.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ error[E0080]: evaluation of constant value failed
44
LL | = [0; (i8::MAX + 1) as usize];
55
| ^^^^^^^^^^^^^ attempt to add with overflow
66

7-
error[E0308]: mismatched types
8-
--> $DIR/const-eval-overflow-3.rs:20:7
9-
|
10-
LL | = [0; (i8::MAX + 1) as usize];
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1) as usize`
12-
|
13-
= note: expected array `[u32; 128]`
14-
found array `[u32; _]`
15-
16-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
178

18-
Some errors have detailed explanations: E0080, E0308.
19-
For more information about an error, try `rustc --explain E0080`.
9+
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/const-eval-overflow-3b.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const A_I8_I
1818
= [0; (i8::MAX + 1u8) as usize];
1919
//~^ ERROR mismatched types
2020
//~| ERROR cannot add `u8` to `i8`
21-
//~| ERROR mismatched types
2221

2322
fn main() {
2423
foo(&A_I8_I[..]);

src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ LL | = [0; (i8::MAX + 1u8) as usize];
1212
|
1313
= help: the trait `std::ops::Add<u8>` is not implemented for `i8`
1414

15-
error[E0308]: mismatched types
16-
--> $DIR/const-eval-overflow-3b.rs:18:7
17-
|
18-
LL | = [0; (i8::MAX + 1u8) as usize];
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1u8) as usize`
20-
|
21-
= note: expected array `[u32; 128]`
22-
found array `[u32; _]`
23-
24-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2516

2617
Some errors have detailed explanations: E0277, E0308.
2718
For more information about an error, try `rustc --explain E0277`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
33
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
44
// bytes.
5-
let _: [u8; 0] = [4; { //~ ERROR mismatched types
5+
let _: [u8; 0] = [4; {
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`

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

+2-25
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,7 @@ error[E0080]: evaluation of constant value failed
2828
LL | match &1 as *const i32 as usize {
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
3030

31-
error[E0308]: mismatched types
32-
--> $DIR/match-test-ptr-null.rs:5:22
33-
|
34-
LL | let _: [u8; 0] = [4; {
35-
| ____________-------___^
36-
| | |
37-
| | expected due to this
38-
LL | | match &1 as *const i32 as usize {
39-
LL | |
40-
LL | |
41-
... |
42-
LL | | }
43-
LL | | }];
44-
| |______^ expected `0usize`, found `{
45-
match &1 as *const i32 as usize {
46-
0 => 42,
47-
n => n,
48-
}
49-
}`
50-
|
51-
= note: expected array `[u8; 0]`
52-
found array `[u8; _]`
53-
54-
error: aborting due to 4 previous errors
31+
error: aborting due to 3 previous errors
5532

56-
Some errors have detailed explanations: E0080, E0308, E0658.
33+
Some errors have detailed explanations: E0080, E0658.
5734
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/const-integer-bool-ops.rs

-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const X: usize = 42 && 39;
66
//~| ERROR mismatched types
77
//~| expected `usize`, found `bool`
88
const ARR: [i32; X] = [99; 34];
9-
//~^ ERROR evaluation of constant value failed
109

1110
const X1: usize = 42 || 39;
1211
//~^ ERROR mismatched types
@@ -16,7 +15,6 @@ const X1: usize = 42 || 39;
1615
//~| ERROR mismatched types
1716
//~| expected `usize`, found `bool`
1817
const ARR1: [i32; X1] = [99; 47];
19-
//~^ ERROR evaluation of constant value failed
2018

2119
const X2: usize = -42 || -39;
2220
//~^ ERROR mismatched types
@@ -26,7 +24,6 @@ const X2: usize = -42 || -39;
2624
//~| ERROR mismatched types
2725
//~| expected `usize`, found `bool`
2826
const ARR2: [i32; X2] = [99; 18446744073709551607];
29-
//~^ ERROR evaluation of constant value failed
3027

3128
const X3: usize = -42 && -39;
3229
//~^ ERROR mismatched types
@@ -36,43 +33,36 @@ const X3: usize = -42 && -39;
3633
//~| ERROR mismatched types
3734
//~| expected `usize`, found `bool`
3835
const ARR3: [i32; X3] = [99; 6];
39-
//~^ ERROR evaluation of constant value failed
4036

4137
const Y: usize = 42.0 == 42.0;
4238
//~^ ERROR mismatched types
4339
//~| expected `usize`, found `bool`
4440
const ARRR: [i32; Y] = [99; 1];
45-
//~^ ERROR evaluation of constant value failed
4641

4742
const Y1: usize = 42.0 >= 42.0;
4843
//~^ ERROR mismatched types
4944
//~| expected `usize`, found `bool`
5045
const ARRR1: [i32; Y1] = [99; 1];
51-
//~^ ERROR evaluation of constant value failed
5246

5347
const Y2: usize = 42.0 <= 42.0;
5448
//~^ ERROR mismatched types
5549
//~| expected `usize`, found `bool`
5650
const ARRR2: [i32; Y2] = [99; 1];
57-
//~^ ERROR evaluation of constant value failed
5851

5952
const Y3: usize = 42.0 > 42.0;
6053
//~^ ERROR mismatched types
6154
//~| expected `usize`, found `bool`
6255
const ARRR3: [i32; Y3] = [99; 0];
63-
//~^ ERROR evaluation of constant value failed
6456

6557
const Y4: usize = 42.0 < 42.0;
6658
//~^ ERROR mismatched types
6759
//~| expected `usize`, found `bool`
6860
const ARRR4: [i32; Y4] = [99; 0];
69-
//~^ ERROR evaluation of constant value failed
7061

7162
const Y5: usize = 42.0 != 42.0;
7263
//~^ ERROR mismatched types
7364
//~| expected `usize`, found `bool`
7465
const ARRR5: [i32; Y5] = [99; 0];
75-
//~^ ERROR evaluation of constant value failed
7666

7767
fn main() {
7868
let _ = ARR;

0 commit comments

Comments
 (0)