]> git.lizzy.rs Git - rust.git/commitdiff
miri-unleashed: test that we detect heap allocations
authorRalf Jung <post@ralfj.de>
Sat, 18 Apr 2020 09:16:07 +0000 (11:16 +0200)
committerRalf Jung <post@ralfj.de>
Sat, 18 Apr 2020 09:38:25 +0000 (11:38 +0200)
src/librustc_mir/transform/check_consts/ops.rs
src/test/ui/consts/miri_unleashed/box.rs [new file with mode: 0644]
src/test/ui/consts/miri_unleashed/box.stderr [new file with mode: 0644]

index b3264a7a0321ad4b955c7d4b5555c9c1831a74b5..b5e62aa20130b1eb0bdebfdaa3ad111cdcf5da70 100644 (file)
@@ -113,8 +113,6 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
 #[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 (file)
index 0000000..0497276
--- /dev/null
@@ -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 (file)
index 0000000..d1b404e
--- /dev/null
@@ -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`.