Skip to content

Commit db20f24

Browse files
committed
add test for dropping in const
1 parent 6253754 commit db20f24

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![deny(const_err)]
3+
4+
use std::mem::ManuallyDrop;
5+
6+
fn main() {}
7+
8+
static TEST_OK: () = {
9+
let v: Vec<i32> = Vec::new();
10+
let _v = ManuallyDrop::new(v);
11+
};
12+
13+
// Make sure we catch executing bad drop functions.
14+
// The actual error is located in `real_drop_in_place` so we can't capture it with the
15+
// error annotations here.
16+
static TEST_BAD: () = {
17+
let _v: Vec<i32> = Vec::new();
18+
//~^ WARN skipping const check
19+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
warning: skipping const checks
2+
--> $DIR/drop.rs:17:9
3+
|
4+
LL | let _v: Vec<i32> = Vec::new();
5+
| ^^
6+
7+
error[E0080]: could not evaluate static initializer
8+
--> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
9+
|
10+
LL | / unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
11+
LL | | // Code here does not matter - this is replaced by the
12+
LL | | // real drop glue by the compiler.
13+
LL | | real_drop_in_place(to_drop)
14+
LL | | }
15+
| |_^ calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
16+
|
17+
::: $DIR/drop.rs:19:1
18+
|
19+
LL | };
20+
| - 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
21+
22+
error: aborting due to previous error
23+
24+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)