Skip to content

Commit b13d65a

Browse files
committed
Auto merge of #67580 - RalfJung:miri-unleash-tests, r=oli-obk
test the unleashed Miri In particular, test what happens when we try to drop something. Cc rust-lang/const-eval#17 r? @oli-obk
2 parents bbf1372 + 40b8b7c commit b13d65a

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

src/test/ui/consts/miri_unleashed/const_refers_to_static.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@
66
use std::sync::atomic::AtomicUsize;
77
use std::sync::atomic::Ordering;
88

9-
const BOO: &usize = { //~ ERROR undefined behavior to use this value
9+
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
1010
static FOO: AtomicUsize = AtomicUsize::new(0);
1111
unsafe { &*(&FOO as *const _ as *const usize) }
1212
//~^ WARN skipping const checks
1313
};
1414

15-
const FOO: usize = {
15+
const MUTATE_INTERIOR_MUT: usize = {
1616
static FOO: AtomicUsize = AtomicUsize::new(0);
1717
FOO.fetch_add(1, Ordering::Relaxed) //~ WARN any use of this value will cause an error
1818
//~^ WARN skipping const checks
1919
//~| WARN skipping const checks
2020
};
2121

22-
const BAR: usize = {
22+
const READ_INTERIOR_MUT: usize = {
2323
static FOO: AtomicUsize = AtomicUsize::new(0);
2424
unsafe { *(&FOO as *const _ as *const usize) } //~ WARN any use of this value will cause an err
2525
//~^ WARN skipping const checks
2626
};
2727

2828
static mut MUTABLE: u32 = 0;
29-
const BAD: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
29+
const READ_MUT: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
3030
//~^ WARN skipping const checks
3131

3232
// ok some day perhaps
33-
const BOO_OK: &usize = { //~ ERROR it is undefined behavior to use this value
33+
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
3434
static FOO: usize = 0;
3535
&FOO
3636
//~^ WARN skipping const checks

src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ LL | unsafe { *(&FOO as *const _ as *const usize) }
2323
| ^^^
2424

2525
warning: skipping const checks
26-
--> $DIR/const_refers_to_static.rs:29:27
26+
--> $DIR/const_refers_to_static.rs:29:32
2727
|
28-
LL | const BAD: u32 = unsafe { MUTABLE };
29-
| ^^^^^^^
28+
LL | const READ_MUT: u32 = unsafe { MUTABLE };
29+
| ^^^^^^^
3030

3131
warning: skipping const checks
3232
--> $DIR/const_refers_to_static.rs:35:6
@@ -37,7 +37,7 @@ LL | &FOO
3737
error[E0080]: it is undefined behavior to use this value
3838
--> $DIR/const_refers_to_static.rs:9:1
3939
|
40-
LL | / const BOO: &usize = {
40+
LL | / const REF_INTERIOR_MUT: &usize = {
4141
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
4242
LL | | unsafe { &*(&FOO as *const _ as *const usize) }
4343
LL | |
@@ -49,7 +49,7 @@ LL | | };
4949
warning: any use of this value will cause an error
5050
--> $DIR/const_refers_to_static.rs:17:5
5151
|
52-
LL | / const FOO: usize = {
52+
LL | / const MUTATE_INTERIOR_MUT: usize = {
5353
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
5454
LL | | FOO.fetch_add(1, Ordering::Relaxed)
5555
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `std::sync::atomic::AtomicUsize::fetch_add`
@@ -67,7 +67,7 @@ LL | #![warn(const_err)]
6767
warning: any use of this value will cause an error
6868
--> $DIR/const_refers_to_static.rs:24:14
6969
|
70-
LL | / const BAR: usize = {
70+
LL | / const READ_INTERIOR_MUT: usize = {
7171
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
7272
LL | | unsafe { *(&FOO as *const _ as *const usize) }
7373
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
@@ -76,17 +76,17 @@ LL | | };
7676
| |__-
7777

7878
warning: any use of this value will cause an error
79-
--> $DIR/const_refers_to_static.rs:29:27
79+
--> $DIR/const_refers_to_static.rs:29:32
8080
|
81-
LL | const BAD: u32 = unsafe { MUTABLE };
82-
| --------------------------^^^^^^^---
83-
| |
84-
| constant accesses static
81+
LL | const READ_MUT: u32 = unsafe { MUTABLE };
82+
| -------------------------------^^^^^^^---
83+
| |
84+
| constant accesses static
8585

8686
error[E0080]: it is undefined behavior to use this value
8787
--> $DIR/const_refers_to_static.rs:33:1
8888
|
89-
LL | / const BOO_OK: &usize = {
89+
LL | / const READ_IMMUT: &usize = {
9090
LL | | static FOO: usize = 0;
9191
LL | | &FOO
9292
LL | |
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
// ignore-x86 FIXME: missing sysroot spans (#53081)
3+
// error-pattern: calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
4+
#![deny(const_err)]
5+
6+
use std::mem::ManuallyDrop;
7+
8+
fn main() {}
9+
10+
static TEST_OK: () = {
11+
let v: Vec<i32> = Vec::new();
12+
let _v = ManuallyDrop::new(v);
13+
};
14+
15+
// Make sure we catch executing bad drop functions.
16+
// The actual error is tested by the error-pattern above.
17+
static TEST_BAD: () = {
18+
let _v: Vec<i32> = Vec::new();
19+
//~^ WARN skipping const check
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
warning: skipping const checks
2+
--> $DIR/drop.rs:18: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:20: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:20: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)