From 7f1ce451401b21155923174480f8be9e0b8cf499 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Oct 2019 13:13:31 +0200 Subject: [PATCH 1/2] add test for calling non-const fn --- src/test/ui/consts/miri_unleashed/non_const_fn.rs | 12 ++++++++++++ .../ui/consts/miri_unleashed/non_const_fn.stderr | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/ui/consts/miri_unleashed/non_const_fn.rs create mode 100644 src/test/ui/consts/miri_unleashed/non_const_fn.stderr 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..01ce6b904e370 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.rs @@ -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 +} 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..ad8154bd2c686 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr @@ -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`. From 38fd74f22af7eec30d11d421bcbeaa891c7f7436 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Oct 2019 15:52:08 +0200 Subject: [PATCH 2/2] show the proper diagnostics --- .../ui/consts/miri_unleashed/non_const_fn.rs | 3 ++- .../ui/consts/miri_unleashed/non_const_fn.stderr | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.rs b/src/test/ui/consts/miri_unleashed/non_const_fn.rs index 01ce6b904e370..e1ac4306575da 100644 --- a/src/test/ui/consts/miri_unleashed/non_const_fn.rs +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.rs @@ -1,11 +1,12 @@ // compile-flags: -Zunleash-the-miri-inside-of-you -#![allow(const_err)] +#![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 index ad8154bd2c686..7a574b34304cb 100644 --- a/src/test/ui/consts/miri_unleashed/non_const_fn.stderr +++ b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr @@ -4,8 +4,22 @@ warning: skipping const checks 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:11:22 + --> $DIR/non_const_fn.rs:12:22 | LL | println!("{:?}", C); | ^ referenced constant has errors