diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-20 12:40:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-20 12:40:18 +0200 |
| commit | 663125cac2a84944a47a55e6c2c438bf67a55090 (patch) | |
| tree | 612b10c42cc171e5655f58f8559aceb6ea45c3e2 | |
| parent | 766073aeb4735bda885026731b56919c5cf932ad (diff) | |
| parent | 38fd74f22af7eec30d11d421bcbeaa891c7f7436 (diff) | |
| download | rust-663125cac2a84944a47a55e6c2c438bf67a55090.tar.gz rust-663125cac2a84944a47a55e6c2c438bf67a55090.zip | |
Rollup merge of #65593 - RalfJung:non-const-fn, r=oli-obk
add test for calling non-const fn The good news is that there is an error. But I expected to see [this error](https://github.com/rust-lang/rust/blob/9578272d681c8691ca2ff3f5c4230b491bc1c694/src/librustc_mir/const_eval.rs#L346) surface. @oli-obk any idea why that message is not shown anywhere? r? @oli-obk
| -rw-r--r-- | src/test/ui/consts/miri_unleashed/non_const_fn.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/consts/miri_unleashed/non_const_fn.stderr | 29 |
2 files changed, 42 insertions, 0 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 new file mode 100644 index 00000000000..e1ac4306575 --- /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 00000000000..7a574b34304 --- /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`. |
