Skip to content

Commit b3fc46c

Browse files
committed
check mir exists before validation; fix tests
1 parent b57fe64 commit b3fc46c

15 files changed

+25
-90
lines changed

compiler/rustc_mir/src/const_eval/eval_queries.rs

+7
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
275275
return Err(ErrorHandled::Reported(error_reported));
276276
}
277277
}
278+
if !tcx.is_mir_available(def.did) {
279+
tcx.sess.delay_span_bug(
280+
tcx.def_span(def.did),
281+
&format!("no MIR body is available for {:?}", def.did),
282+
);
283+
return Err(ErrorHandled::Reported(ErrorReported {}));
284+
}
278285
let qualif = tcx.mir_const_qualif_opt_const_arg(def);
279286
if qualif.error_occured {
280287
return Err(ErrorHandled::Reported(ErrorReported {}));

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ fn main() {
1111
//~| ERROR calls in constants are limited to constant functions
1212
//~| ERROR mutable references are not allowed in constants
1313
//~| ERROR calls in constants are limited to constant functions
14-
//~| ERROR evaluation of constant value failed
1514
}

src/test/ui/const-generics/nested-type.full.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
44
LL | Foo::<17>::value()
55
| ^^^^^^^^^^^^^^^^^^
66

7-
error[E0080]: evaluation of constant value failed
8-
--> $DIR/nested-type.rs:16:5
9-
|
10-
LL | Foo::<17>::value()
11-
| ^^^^^^^^^^^^^^^^^^ calling non-const function `Foo::{constant#0}::Foo::<17_usize>::value`
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

15-
Some errors have detailed explanations: E0015, E0080.
16-
For more information about an error, try `rustc --explain E0015`.
9+
For more information about this error, try `rustc --explain E0015`.

src/test/ui/const-generics/nested-type.min.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
2020
LL | Foo::<17>::value()
2121
| ^^^^^^^^^^^^^^^^^^
2222

23-
error[E0080]: evaluation of constant value failed
24-
--> $DIR/nested-type.rs:16:5
25-
|
26-
LL | Foo::<17>::value()
27-
| ^^^^^^^^^^^^^^^^^^ calling non-const function `Foo::{constant#0}::Foo::<17_usize>::value`
28-
29-
error: aborting due to 3 previous errors
23+
error: aborting due to 2 previous errors
3024

31-
Some errors have detailed explanations: E0015, E0080.
32-
For more information about an error, try `rustc --explain E0015`.
25+
For more information about this error, try `rustc --explain E0015`.

src/test/ui/const-generics/nested-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ struct Foo<const N: [u8; { //[min]~ ERROR `[u8; _]` is forbidden
1515

1616
Foo::<17>::value()
1717
//~^ ERROR calls in constants are limited to constant functions
18-
//~| ERROR evaluation of constant value failed
1918
}]>;
2019

2120
fn main() {}

src/test/ui/issues/issue-39559-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ impl Dim for Dim3 {
1313
fn main() {
1414
let array: [usize; Dim3::dim()]
1515
//~^ ERROR E0015
16-
//~| ERROR E0080
1716
= [0; Dim3::dim()];
1817
//~^ ERROR E0015
19-
//~| ERROR E0080
2018
}

src/test/ui/issues/issue-39559-2.stderr

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,12 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
44
LL | let array: [usize; Dim3::dim()]
55
| ^^^^^^^^^^^
66

7-
error[E0080]: evaluation of constant value failed
8-
--> $DIR/issue-39559-2.rs:14:24
9-
|
10-
LL | let array: [usize; Dim3::dim()]
11-
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
12-
137
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
14-
--> $DIR/issue-39559-2.rs:17:15
8+
--> $DIR/issue-39559-2.rs:16:15
159
|
1610
LL | = [0; Dim3::dim()];
1711
| ^^^^^^^^^^^
1812

19-
error[E0080]: evaluation of constant value failed
20-
--> $DIR/issue-39559-2.rs:17:15
21-
|
22-
LL | = [0; Dim3::dim()];
23-
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
24-
25-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
2614

27-
Some errors have detailed explanations: E0015, E0080.
28-
For more information about an error, try `rustc --explain E0015`.
15+
For more information about this error, try `rustc --explain E0015`.

src/test/ui/issues/issue-43105.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ fn xyz() -> u8 { 42 }
22

33
const NUM: u8 = xyz();
44
//~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants
5-
//~| ERROR any use of this value will cause an error [const_err]
65

76
fn main() {
87
match 1 {

src/test/ui/issues/issue-43105.stderr

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,18 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
44
LL | const NUM: u8 = xyz();
55
| ^^^^^
66

7-
error: any use of this value will cause an error
8-
--> $DIR/issue-43105.rs:3:17
9-
|
10-
LL | const NUM: u8 = xyz();
11-
| ----------------^^^^^-
12-
| |
13-
| calling non-const function `xyz`
14-
|
15-
= note: `#[deny(const_err)]` on by default
16-
177
error: could not evaluate constant pattern
18-
--> $DIR/issue-43105.rs:9:9
8+
--> $DIR/issue-43105.rs:8:9
199
|
2010
LL | NUM => unimplemented!(),
2111
| ^^^
2212

2313
error: could not evaluate constant pattern
24-
--> $DIR/issue-43105.rs:9:9
14+
--> $DIR/issue-43105.rs:8:9
2515
|
2616
LL | NUM => unimplemented!(),
2717
| ^^^
2818

29-
error: aborting due to 4 previous errors
19+
error: aborting due to 3 previous errors
3020

3121
For more information about this error, try `rustc --explain E0015`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
fn main() {
22
let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants
3-
//~^ ERROR evaluation of constant value failed
43
}

src/test/ui/issues/issue-52023-array-size-pointer-cast.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ LL | let _ = [0; (&0 as *const i32) as usize];
77
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
88
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
99

10-
error[E0080]: evaluation of constant value failed
11-
--> $DIR/issue-52023-array-size-pointer-cast.rs:2:17
12-
|
13-
LL | let _ = [0; (&0 as *const i32) as usize];
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
15-
16-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
1711

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

src/test/ui/issues/issue-52060.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
static A: &'static [u32] = &[1];
44
static B: [u32; 1] = [0; A.len()];
55
//~^ ERROR [E0013]
6-
//~| ERROR evaluation of constant value failed
76

87
fn main() {}

src/test/ui/issues/issue-52060.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ LL | static B: [u32; 1] = [0; A.len()];
66
|
77
= help: consider extracting the value of the `static` to a `const`, and referring to that
88

9-
error[E0080]: evaluation of constant value failed
10-
--> $DIR/issue-52060.rs:4:26
11-
|
12-
LL | static B: [u32; 1] = [0; A.len()];
13-
| ^ constant accesses static
14-
15-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1610

17-
Some errors have detailed explanations: E0013, E0080.
18-
For more information about an error, try `rustc --explain E0013`.
11+
For more information about this error, try `rustc --explain E0013`.

src/test/ui/issues/issue-77919.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
2-
[1; <Multiply<Five, Five>>::VAL]; //~ ERROR evaluation of constant value failed
2+
[1; <Multiply<Five, Five>>::VAL];
33
}
44
trait TypeVal<T> {
5-
const VAL: T; //~ ERROR any use of this value will cause an error
5+
const VAL: T;
66
}
77
struct Five;
88
struct Multiply<N, M> {

src/test/ui/issues/issue-77919.stderr

+2-16
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,7 @@ LL | const VAL: T;
2626
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
2828

29-
error: any use of this value will cause an error
30-
--> $DIR/issue-77919.rs:5:5
31-
|
32-
LL | const VAL: T;
33-
| ^^^^^^^^^^^^^ no MIR body is available for DefId(0:7 ~ issue_77919[317d]::TypeVal::VAL)
34-
|
35-
= note: `#[deny(const_err)]` on by default
36-
37-
error[E0080]: evaluation of constant value failed
38-
--> $DIR/issue-77919.rs:2:9
39-
|
40-
LL | [1; <Multiply<Five, Five>>::VAL];
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
42-
43-
error: aborting due to 5 previous errors
29+
error: aborting due to 3 previous errors
4430

45-
Some errors have detailed explanations: E0046, E0080, E0412.
31+
Some errors have detailed explanations: E0046, E0412.
4632
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)