From 76cb95ef4dba0e21c9befef1450a22c9c03e34bf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 18 Apr 2020 11:15:23 +0200 Subject: [PATCH 1/2] check_consts: make ops module private --- src/librustc_mir/transform/check_consts/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/check_consts/mod.rs b/src/librustc_mir/transform/check_consts/mod.rs index bce3a506b1dd9..1f916d5fc1d99 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -13,7 +13,7 @@ use std::fmt; pub use self::qualifs::Qualif; -pub mod ops; +mod ops; pub mod qualifs; mod resolver; pub mod validation; From cf3470a5fc8fc08018f4fe42b2c03a1b96a90029 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 18 Apr 2020 11:16:07 +0200 Subject: [PATCH 2/2] miri-unleashed: test that we detect heap allocations --- src/librustc_mir/transform/check_consts/ops.rs | 2 -- src/test/ui/consts/miri_unleashed/box.rs | 14 ++++++++++++++ src/test/ui/consts/miri_unleashed/box.stderr | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/miri_unleashed/box.rs create mode 100644 src/test/ui/consts/miri_unleashed/box.stderr diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index b3264a7a0321a..b5e62aa20130b 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -113,8 +113,6 @@ impl NonConstOp for FnCallUnstable { #[derive(Debug)] pub struct HeapAllocation; impl NonConstOp for HeapAllocation { - const IS_SUPPORTED_IN_MIRI: bool = false; - fn emit_error(&self, item: &Item<'_, '_>, span: Span) { let mut err = struct_span_err!( item.tcx.sess, diff --git a/src/test/ui/consts/miri_unleashed/box.rs b/src/test/ui/consts/miri_unleashed/box.rs new file mode 100644 index 0000000000000..049727684d0eb --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/box.rs @@ -0,0 +1,14 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you +#![feature(const_mut_refs, box_syntax)] +#![deny(const_err)] + +use std::mem::ManuallyDrop; + +fn main() {} + +static TEST_BAD: &mut i32 = { + &mut *(box 0) + //~^ WARN skipping const check + //~| ERROR could not evaluate static initializer + //~| NOTE heap allocations +}; diff --git a/src/test/ui/consts/miri_unleashed/box.stderr b/src/test/ui/consts/miri_unleashed/box.stderr new file mode 100644 index 0000000000000..d1b404ea737ca --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/box.stderr @@ -0,0 +1,15 @@ +warning: skipping const checks + --> $DIR/box.rs:10:11 + | +LL | &mut *(box 0) + | ^^^^^^^ + +error[E0080]: could not evaluate static initializer + --> $DIR/box.rs:10:11 + | +LL | &mut *(box 0) + | ^^^^^^^ "heap allocations via `box` keyword" needs an rfc before being allowed inside constants + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`.