From db20f248ebcd2a6cb5230b3bde7f400a380b0b87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 24 Dec 2019 12:20:36 +0100 Subject: [PATCH] add test for dropping in const --- src/test/ui/consts/miri_unleashed/drop.rs | 19 +++++++++++++++ src/test/ui/consts/miri_unleashed/drop.stderr | 24 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/ui/consts/miri_unleashed/drop.rs create mode 100644 src/test/ui/consts/miri_unleashed/drop.stderr diff --git a/src/test/ui/consts/miri_unleashed/drop.rs b/src/test/ui/consts/miri_unleashed/drop.rs new file mode 100644 index 00000000000..ab9d874d579 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/drop.rs @@ -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 = 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 = 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 index 00000000000..b8fc6a0271d --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/drop.stderr @@ -0,0 +1,24 @@ +warning: skipping const checks + --> $DIR/drop.rs:17:9 + | +LL | let _v: Vec = Vec::new(); + | ^^ + +error[E0080]: could not evaluate static initializer + --> $SRC_DIR/libcore/ptr/mod.rs:LL:COL + | +LL | / unsafe fn real_drop_in_place(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 ` as std::ops::Drop>::drop` + | + ::: $DIR/drop.rs:19:1 + | +LL | }; + | - inside call to `std::ptr::real_drop_in_place::> - shim(Some(std::vec::Vec))` at $DIR/drop.rs:19:1 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. -- 2.44.0