check mir exists before validation; fix tests

This commit is contained in:
Vishnunarayan K I 2020-11-09 23:15:11 +05:30
parent 6781907444
commit 5029a19313
15 changed files with 25 additions and 90 deletions

View file

@ -275,6 +275,13 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
return Err(ErrorHandled::Reported(error_reported)); return Err(ErrorHandled::Reported(error_reported));
} }
} }
if !tcx.is_mir_available(def.did) {
tcx.sess.delay_span_bug(
tcx.def_span(def.did),
&format!("no MIR body is available for {:?}", def.did),
);
return Err(ErrorHandled::Reported(ErrorReported {}));
}
let qualif = tcx.mir_const_qualif_opt_const_arg(def); let qualif = tcx.mir_const_qualif_opt_const_arg(def);
if qualif.error_occured { if qualif.error_occured {
return Err(ErrorHandled::Reported(ErrorReported {})); return Err(ErrorHandled::Reported(ErrorReported {}));

View file

@ -11,5 +11,4 @@ fn main() {
//~| ERROR calls in constants are limited to constant functions //~| ERROR calls in constants are limited to constant functions
//~| ERROR mutable references are not allowed in constants //~| ERROR mutable references are not allowed in constants
//~| ERROR calls in constants are limited to constant functions //~| ERROR calls in constants are limited to constant functions
//~| ERROR evaluation of constant value failed
} }

View file

@ -4,13 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
LL | Foo::<17>::value() LL | Foo::<17>::value()
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of constant value failed error: aborting due to previous error
--> $DIR/nested-type.rs:16:5
|
LL | Foo::<17>::value()
| ^^^^^^^^^^^^^^^^^^ calling non-const function `Foo::{constant#0}::Foo::<17_usize>::value`
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0015`.
Some errors have detailed explanations: E0015, E0080.
For more information about an error, try `rustc --explain E0015`.

View file

@ -20,13 +20,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
LL | Foo::<17>::value() LL | Foo::<17>::value()
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of constant value failed error: aborting due to 2 previous errors
--> $DIR/nested-type.rs:16:5
|
LL | Foo::<17>::value()
| ^^^^^^^^^^^^^^^^^^ calling non-const function `Foo::{constant#0}::Foo::<17_usize>::value`
error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0015`.
Some errors have detailed explanations: E0015, E0080.
For more information about an error, try `rustc --explain E0015`.

View file

@ -15,7 +15,6 @@ struct Foo<const N: [u8; { //[min]~ ERROR `[u8; _]` is forbidden
Foo::<17>::value() Foo::<17>::value()
//~^ ERROR calls in constants are limited to constant functions //~^ ERROR calls in constants are limited to constant functions
//~| ERROR evaluation of constant value failed
}]>; }]>;
fn main() {} fn main() {}

View file

@ -13,8 +13,6 @@ impl Dim for Dim3 {
fn main() { fn main() {
let array: [usize; Dim3::dim()] let array: [usize; Dim3::dim()]
//~^ ERROR E0015 //~^ ERROR E0015
//~| ERROR E0080
= [0; Dim3::dim()]; = [0; Dim3::dim()];
//~^ ERROR E0015 //~^ ERROR E0015
//~| ERROR E0080
} }

View file

@ -4,25 +4,12 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
LL | let array: [usize; Dim3::dim()] LL | let array: [usize; Dim3::dim()]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error[E0080]: evaluation of constant value failed
--> $DIR/issue-39559-2.rs:14:24
|
LL | let array: [usize; Dim3::dim()]
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-39559-2.rs:17:15 --> $DIR/issue-39559-2.rs:16:15
| |
LL | = [0; Dim3::dim()]; LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error[E0080]: evaluation of constant value failed error: aborting due to 2 previous errors
--> $DIR/issue-39559-2.rs:17:15
|
LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0015`.
Some errors have detailed explanations: E0015, E0080.
For more information about an error, try `rustc --explain E0015`.

View file

@ -2,7 +2,6 @@ fn xyz() -> u8 { 42 }
const NUM: u8 = xyz(); const NUM: u8 = xyz();
//~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants //~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants
//~| ERROR any use of this value will cause an error [const_err]
fn main() { fn main() {
match 1 { match 1 {

View file

@ -4,28 +4,18 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
LL | const NUM: u8 = xyz(); LL | const NUM: u8 = xyz();
| ^^^^^ | ^^^^^
error: any use of this value will cause an error
--> $DIR/issue-43105.rs:3:17
|
LL | const NUM: u8 = xyz();
| ----------------^^^^^-
| |
| calling non-const function `xyz`
|
= note: `#[deny(const_err)]` on by default
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/issue-43105.rs:9:9 --> $DIR/issue-43105.rs:8:9
| |
LL | NUM => unimplemented!(), LL | NUM => unimplemented!(),
| ^^^ | ^^^
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/issue-43105.rs:9:9 --> $DIR/issue-43105.rs:8:9
| |
LL | NUM => unimplemented!(), LL | NUM => unimplemented!(),
| ^^^ | ^^^
error: aborting due to 4 previous errors error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0015`. For more information about this error, try `rustc --explain E0015`.

View file

@ -1,4 +1,3 @@
fn main() { fn main() {
let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants
//~^ ERROR evaluation of constant value failed
} }

View file

@ -7,13 +7,6 @@ LL | let _ = [0; (&0 as *const i32) as usize];
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information = 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 = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
error[E0080]: evaluation of constant value failed error: aborting due to previous error
--> $DIR/issue-52023-array-size-pointer-cast.rs:2:17
|
LL | let _ = [0; (&0 as *const i32) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`.
Some errors have detailed explanations: E0080, E0658.
For more information about an error, try `rustc --explain E0080`.

View file

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

View file

@ -6,13 +6,6 @@ LL | static B: [u32; 1] = [0; A.len()];
| |
= help: consider extracting the value of the `static` to a `const`, and referring to that = help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0080]: evaluation of constant value failed error: aborting due to previous error
--> $DIR/issue-52060.rs:4:26
|
LL | static B: [u32; 1] = [0; A.len()];
| ^ constant accesses static
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0013`.
Some errors have detailed explanations: E0013, E0080.
For more information about an error, try `rustc --explain E0013`.

View file

@ -1,8 +1,8 @@
fn main() { fn main() {
[1; <Multiply<Five, Five>>::VAL]; //~ ERROR evaluation of constant value failed [1; <Multiply<Five, Five>>::VAL];
} }
trait TypeVal<T> { trait TypeVal<T> {
const VAL: T; //~ ERROR any use of this value will cause an error const VAL: T;
} }
struct Five; struct Five;
struct Multiply<N, M> { struct Multiply<N, M> {

View file

@ -26,21 +26,7 @@ LL | const VAL: T;
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {} LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
error: any use of this value will cause an error error: aborting due to 3 previous errors
--> $DIR/issue-77919.rs:5:5
|
LL | const VAL: T;
| ^^^^^^^^^^^^^ no MIR body is available for DefId(0:7 ~ issue_77919[317d]::TypeVal::VAL)
|
= note: `#[deny(const_err)]` on by default
error[E0080]: evaluation of constant value failed Some errors have detailed explanations: E0046, E0412.
--> $DIR/issue-77919.rs:2:9
|
LL | [1; <Multiply<Five, Five>>::VAL];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0046, E0080, E0412.
For more information about an error, try `rustc --explain E0046`. For more information about an error, try `rustc --explain E0046`.