diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.rs b/src/test/ui/consts/miri_unleashed/non_const_fn.rs new file mode 100644 index 0000000000000..e1ac4306575da --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.rs @@ -0,0 +1,13 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you +#![warn(const_err)] + +// A test demonstrating that we prevent calling non-const fn during CTFE. + +fn foo() {} + +const C: () = foo(); //~ WARN: skipping const checks +//~^ WARN any use of this value will cause an error + +fn main() { + println!("{:?}", C); //~ ERROR: evaluation of constant expression failed +} diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.stderr b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr new file mode 100644 index 0000000000000..7a574b34304cb --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr @@ -0,0 +1,29 @@ +warning: skipping const checks + --> $DIR/non_const_fn.rs:8:15 + | +LL | const C: () = foo(); + | ^^^^^ + +warning: any use of this value will cause an error + --> $DIR/non_const_fn.rs:8:15 + | +LL | const C: () = foo(); + | --------------^^^^^- + | | + | calling non-const function `foo` + | +note: lint level defined here + --> $DIR/non_const_fn.rs:2:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + +error[E0080]: evaluation of constant expression failed + --> $DIR/non_const_fn.rs:12:22 + | +LL | println!("{:?}", C); + | ^ referenced constant has errors + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`.