]> git.lizzy.rs Git - rust.git/commitdiff
add test for dropping in const
authorRalf Jung <post@ralfj.de>
Tue, 24 Dec 2019 11:20:36 +0000 (12:20 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 24 Dec 2019 11:21:05 +0000 (12:21 +0100)
src/test/ui/consts/miri_unleashed/drop.rs [new file with mode: 0644]
src/test/ui/consts/miri_unleashed/drop.stderr [new file with mode: 0644]

diff --git a/src/test/ui/consts/miri_unleashed/drop.rs b/src/test/ui/consts/miri_unleashed/drop.rs
new file mode 100644 (file)
index 0000000..ab9d874
--- /dev/null
@@ -0,0 +1,19 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![deny(const_err)]
+
+use std::mem::ManuallyDrop;
+
+fn main() {}
+
+static TEST_OK: () = {
+    let v: Vec<i32> = Vec::new();
+    let _v = ManuallyDrop::new(v);
+};
+
+// Make sure we catch executing bad drop functions.
+// The actual error is located in `real_drop_in_place` so we can't capture it with the
+// error annotations here.
+static TEST_BAD: () = {
+    let _v: Vec<i32> = Vec::new();
+    //~^ WARN skipping const check
+};
diff --git a/src/test/ui/consts/miri_unleashed/drop.stderr b/src/test/ui/consts/miri_unleashed/drop.stderr
new file mode 100644 (file)
index 0000000..b8fc6a0
--- /dev/null
@@ -0,0 +1,24 @@
+warning: skipping const checks
+  --> $DIR/drop.rs:17:9
+   |
+LL |     let _v: Vec<i32> = Vec::new();
+   |         ^^
+
+error[E0080]: could not evaluate static initializer
+  --> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
+   |
+LL | / unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
+LL | |     // Code here does not matter - this is replaced by the
+LL | |     // real drop glue by the compiler.
+LL | |     real_drop_in_place(to_drop)
+LL | | }
+   | |_^ calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
+   | 
+  ::: $DIR/drop.rs:19:1
+   |
+LL |   };
+   |   - inside call to `std::ptr::real_drop_in_place::<std::vec::Vec<i32>> - shim(Some(std::vec::Vec<i32>))` at $DIR/drop.rs:19:1
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.