add test for calling non-const fn

This commit is contained in:
Ralf Jung 2019-10-19 13:13:31 +02:00
parent e5b8c118a3
commit 7f1ce45140
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,12 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![allow(const_err)]
// A test demonstrating that we prevent calling non-const fn during CTFE.
fn foo() {}
const C: () = foo(); //~ WARN: skipping const checks
fn main() {
println!("{:?}", C); //~ ERROR: evaluation of constant expression failed
}

View file

@ -0,0 +1,15 @@
warning: skipping const checks
--> $DIR/non_const_fn.rs:8:15
|
LL | const C: () = foo();
| ^^^^^
error[E0080]: evaluation of constant expression failed
--> $DIR/non_const_fn.rs:11:22
|
LL | println!("{:?}", C);
| ^ referenced constant has errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.