Skip to content

Commit 2846aa2

Browse files
authored
Rollup merge of #71318 - RalfJung:miri-unleash-cleanup, r=oli-obk
miri-unleash tests: ensure they fire even with 'allow(const_err)' This is easier with `static` than `const` so I switched some of them over.
2 parents 7d8a3ad + 6b76b0e commit 2846aa2

16 files changed

+156
-181
lines changed

src/test/ui/consts/miri_unleashed/abi-mismatch.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
// compile-flags: -Z unleash-the-miri-inside-of-you
33

44
#![feature(const_extern_fn)]
5+
#![allow(const_err)]
56

67
const extern "C" fn c_fn() {}
78

89
const fn call_rust_fn(my_fn: extern "Rust" fn()) {
9-
my_fn(); //~ ERROR any use of this value will cause an error
10+
my_fn();
1011
//~^ WARN skipping const checks
12+
//~| ERROR could not evaluate static initializer
13+
//~| NOTE calling a function with ABI C using caller ABI Rust
14+
//~| NOTE inside `call_rust_fn`
1115
}
1216

13-
const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
17+
static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
1418
//~^ WARN skipping const checks
19+
//~| NOTE inside `VAL`
1520

1621
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
warning: skipping const checks
2-
--> $DIR/abi-mismatch.rs:9:5
2+
--> $DIR/abi-mismatch.rs:10:5
33
|
44
LL | my_fn();
55
| ^^^^^^^
66

77
warning: skipping const checks
8-
--> $DIR/abi-mismatch.rs:13:39
8+
--> $DIR/abi-mismatch.rs:17:40
99
|
10-
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: any use of this value will cause an error
14-
--> $DIR/abi-mismatch.rs:9:5
13+
error[E0080]: could not evaluate static initializer
14+
--> $DIR/abi-mismatch.rs:10:5
1515
|
1616
LL | my_fn();
1717
| ^^^^^^^
1818
| |
1919
| calling a function with ABI C using caller ABI Rust
20-
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:9:5
21-
| inside `VAL` at $DIR/abi-mismatch.rs:13:17
20+
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
2221
...
23-
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
24-
| --------------------------------------------------------------------------------------
25-
|
26-
= note: `#[deny(const_err)]` on by default
22+
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
23+
| --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:17:18
2724

2825
error: aborting due to previous error; 2 warnings emitted
2926

27+
For more information about this error, try `rustc --explain E0080`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
22
#![feature(const_mut_refs, box_syntax)]
3-
#![deny(const_err)]
3+
#![allow(const_err)]
44

55
use std::mem::ManuallyDrop;
66

Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1+
// build-fail
12
// compile-flags: -Zunleash-the-miri-inside-of-you
2-
#![warn(const_err)]
3+
#![allow(const_err)]
34

45
#![feature(const_raw_ptr_deref)]
56

67
use std::sync::atomic::AtomicUsize;
78
use std::sync::atomic::Ordering;
89

9-
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
10-
static FOO: AtomicUsize = AtomicUsize::new(0);
11-
unsafe { &*(&FOO as *const _ as *const usize) }
12-
//~^ WARN skipping const checks
13-
};
10+
// These tests only cause an error when *using* the const.
1411

1512
const MUTATE_INTERIOR_MUT: usize = {
1613
static FOO: AtomicUsize = AtomicUsize::new(0);
17-
FOO.fetch_add(1, Ordering::Relaxed) //~ WARN any use of this value will cause an error
14+
FOO.fetch_add(1, Ordering::Relaxed)
1815
//~^ WARN skipping const checks
1916
//~| WARN skipping const checks
2017
};
2118

2219
const READ_INTERIOR_MUT: usize = {
2320
static FOO: AtomicUsize = AtomicUsize::new(0);
24-
unsafe { *(&FOO as *const _ as *const usize) } //~ WARN any use of this value will cause an err
21+
unsafe { *(&FOO as *const _ as *const usize) }
2522
//~^ WARN skipping const checks
2623
};
2724

2825
static mut MUTABLE: u32 = 0;
29-
const READ_MUT: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
26+
const READ_MUT: u32 = unsafe { MUTABLE };
3027
//~^ WARN skipping const checks
3128
//~| WARN skipping const checks
3229

33-
// ok some day perhaps
34-
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
35-
static FOO: usize = 0;
36-
&FOO
37-
//~^ WARN skipping const checks
38-
};
39-
fn main() {}
30+
fn main() {
31+
MUTATE_INTERIOR_MUT;
32+
//~^ ERROR: erroneous constant used
33+
READ_INTERIOR_MUT;
34+
//~^ ERROR: erroneous constant used
35+
READ_MUT;
36+
//~^ ERROR: erroneous constant used
37+
}
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,51 @@
11
warning: skipping const checks
2-
--> $DIR/const_refers_to_static.rs:11:18
3-
|
4-
LL | unsafe { &*(&FOO as *const _ as *const usize) }
5-
| ^^^
6-
7-
warning: skipping const checks
8-
--> $DIR/const_refers_to_static.rs:17:5
2+
--> $DIR/const_refers_to_static.rs:14:5
93
|
104
LL | FOO.fetch_add(1, Ordering::Relaxed)
115
| ^^^
126

137
warning: skipping const checks
14-
--> $DIR/const_refers_to_static.rs:17:5
8+
--> $DIR/const_refers_to_static.rs:14:5
159
|
1610
LL | FOO.fetch_add(1, Ordering::Relaxed)
1711
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1812

1913
warning: skipping const checks
20-
--> $DIR/const_refers_to_static.rs:24:17
14+
--> $DIR/const_refers_to_static.rs:21:17
2115
|
2216
LL | unsafe { *(&FOO as *const _ as *const usize) }
2317
| ^^^
2418

2519
warning: skipping const checks
26-
--> $DIR/const_refers_to_static.rs:29:32
20+
--> $DIR/const_refers_to_static.rs:26:32
2721
|
2822
LL | const READ_MUT: u32 = unsafe { MUTABLE };
2923
| ^^^^^^^
3024

3125
warning: skipping const checks
32-
--> $DIR/const_refers_to_static.rs:29:32
26+
--> $DIR/const_refers_to_static.rs:26:32
3327
|
3428
LL | const READ_MUT: u32 = unsafe { MUTABLE };
3529
| ^^^^^^^
3630

37-
warning: skipping const checks
38-
--> $DIR/const_refers_to_static.rs:36:6
31+
error[E0080]: erroneous constant used
32+
--> $DIR/const_refers_to_static.rs:31:5
3933
|
40-
LL | &FOO
41-
| ^^^
34+
LL | MUTATE_INTERIOR_MUT;
35+
| ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
4236

43-
error[E0080]: it is undefined behavior to use this value
44-
--> $DIR/const_refers_to_static.rs:9:1
37+
error[E0080]: erroneous constant used
38+
--> $DIR/const_refers_to_static.rs:33:5
4539
|
46-
LL | / const REF_INTERIOR_MUT: &usize = {
47-
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
48-
LL | | unsafe { &*(&FOO as *const _ as *const usize) }
49-
LL | |
50-
LL | | };
51-
| |__^ type validation failed: encountered a reference pointing to a static variable
52-
|
53-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
40+
LL | READ_INTERIOR_MUT;
41+
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
5442

55-
warning: any use of this value will cause an error
56-
--> $DIR/const_refers_to_static.rs:17:5
57-
|
58-
LL | / const MUTATE_INTERIOR_MUT: usize = {
59-
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
60-
LL | | FOO.fetch_add(1, Ordering::Relaxed)
61-
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `std::sync::atomic::AtomicUsize::fetch_add`
62-
LL | |
63-
LL | |
64-
LL | | };
65-
| |__-
66-
|
67-
note: the lint level is defined here
68-
--> $DIR/const_refers_to_static.rs:2:9
69-
|
70-
LL | #![warn(const_err)]
71-
| ^^^^^^^^^
72-
73-
warning: any use of this value will cause an error
74-
--> $DIR/const_refers_to_static.rs:24:14
75-
|
76-
LL | / const READ_INTERIOR_MUT: usize = {
77-
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
78-
LL | | unsafe { *(&FOO as *const _ as *const usize) }
79-
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
80-
LL | |
81-
LL | | };
82-
| |__-
83-
84-
warning: any use of this value will cause an error
85-
--> $DIR/const_refers_to_static.rs:29:32
86-
|
87-
LL | const READ_MUT: u32 = unsafe { MUTABLE };
88-
| -------------------------------^^^^^^^---
89-
| |
90-
| constant accesses static
91-
92-
error[E0080]: it is undefined behavior to use this value
93-
--> $DIR/const_refers_to_static.rs:34:1
94-
|
95-
LL | / const READ_IMMUT: &usize = {
96-
LL | | static FOO: usize = 0;
97-
LL | | &FOO
98-
LL | |
99-
LL | | };
100-
| |__^ type validation failed: encountered a reference pointing to a static variable
43+
error[E0080]: erroneous constant used
44+
--> $DIR/const_refers_to_static.rs:35:5
10145
|
102-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
46+
LL | READ_MUT;
47+
| ^^^^^^^^ referenced constant has errors
10348

104-
error: aborting due to 2 previous errors; 10 warnings emitted
49+
error: aborting due to 3 previous errors; 5 warnings emitted
10550

10651
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![allow(const_err)]
3+
4+
#![feature(const_raw_ptr_deref)]
5+
6+
use std::sync::atomic::AtomicUsize;
7+
use std::sync::atomic::Ordering;
8+
9+
// These tests cause immediate error when *defining* the const.
10+
11+
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
12+
static FOO: AtomicUsize = AtomicUsize::new(0);
13+
unsafe { &*(&FOO as *const _ as *const usize) }
14+
//~^ WARN skipping const checks
15+
};
16+
17+
// ok some day perhaps
18+
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
19+
static FOO: usize = 0;
20+
&FOO
21+
//~^ WARN skipping const checks
22+
};
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
warning: skipping const checks
2+
--> $DIR/const_refers_to_static2.rs:13:18
3+
|
4+
LL | unsafe { &*(&FOO as *const _ as *const usize) }
5+
| ^^^
6+
7+
warning: skipping const checks
8+
--> $DIR/const_refers_to_static2.rs:20:6
9+
|
10+
LL | &FOO
11+
| ^^^
12+
13+
error[E0080]: it is undefined behavior to use this value
14+
--> $DIR/const_refers_to_static2.rs:11:1
15+
|
16+
LL | / const REF_INTERIOR_MUT: &usize = {
17+
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
18+
LL | | unsafe { &*(&FOO as *const _ as *const usize) }
19+
LL | |
20+
LL | | };
21+
| |__^ type validation failed: encountered a reference pointing to a static variable
22+
|
23+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
24+
25+
error[E0080]: it is undefined behavior to use this value
26+
--> $DIR/const_refers_to_static2.rs:18:1
27+
|
28+
LL | / const READ_IMMUT: &usize = {
29+
LL | | static FOO: usize = 0;
30+
LL | | &FOO
31+
LL | |
32+
LL | | };
33+
| |__^ type validation failed: encountered a reference pointing to a static variable
34+
|
35+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
36+
37+
error: aborting due to 2 previous errors; 2 warnings emitted
38+
39+
For more information about this error, try `rustc --explain E0080`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
22
// error-pattern: calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
3-
#![deny(const_err)]
3+
#![allow(const_err)]
44

55
use std::mem::ManuallyDrop;
66

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
// normalize-stderr-test "alloc[0-9]+" -> "allocN"
23

34
#![feature(const_raw_ptr_deref)]
45
#![feature(const_mut_refs)]
5-
#![deny(const_err)]
6+
#![deny(const_err)] // The `allow` variant is tested by `mutable_const2`.
7+
//~^ NOTE lint level
8+
// Here we check that even though `MUTABLE_BEHIND_RAW` is created from a mutable
9+
// allocation, we intern that allocation as *immutable* and reject writes to it.
10+
// We avoid the `delay_span_bug` ICE by having compilation fail via the `deny` above.
611

712
use std::cell::UnsafeCell;
813

914
// make sure we do not just intern this as mutable
1015
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1116
//~^ WARN: skipping const checks
1217

13-
const MUTATING_BEHIND_RAW: () = {
18+
const MUTATING_BEHIND_RAW: () = { //~ NOTE
1419
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
1520
unsafe {
1621
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error
22+
//~^ NOTE: which is read-only
23+
// FIXME would be good to match more of the error message here, but looks like we
24+
// normalize *after* checking the annoations here.
1725
}
1826
};
1927

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
warning: skipping const checks
2-
--> $DIR/mutable_const.rs:10:38
2+
--> $DIR/mutable_const.rs:15:38
33
|
44
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: any use of this value will cause an error
8-
--> $DIR/mutable_const.rs:16:9
8+
--> $DIR/mutable_const.rs:21:9
99
|
1010
LL | / const MUTATING_BEHIND_RAW: () = {
1111
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
1212
LL | | unsafe {
1313
LL | | *MUTABLE_BEHIND_RAW = 99
14-
| | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc2 which is read-only
14+
| | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to allocN which is read-only
15+
... |
1516
LL | | }
1617
LL | | };
1718
| |__-
1819
|
1920
note: the lint level is defined here
20-
--> $DIR/mutable_const.rs:5:9
21+
--> $DIR/mutable_const.rs:6:9
2122
|
22-
LL | #![deny(const_err)]
23+
LL | #![deny(const_err)] // The `allow` variant is tested by `mutable_const2`.
2324
| ^^^^^^^^^
2425

2526
error: aborting due to previous error; 1 warning emitted

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// rustc-env:RUST_BACKTRACE=0
44
// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
55
// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
6-
// normalize-stderr-test "interpret/intern.rs:[0-9]*:[0-9]*" -> "interpret/intern.rs:LL:CC"
6+
// normalize-stderr-test "interpret/intern.rs:[0-9]+:[0-9]+" -> "interpret/intern.rs:LL:CC"
77

88
#![feature(const_raw_ptr_deref)]
99
#![feature(const_mut_refs)]
10-
#![deny(const_err)]
10+
#![allow(const_err)]
1111

1212
use std::cell::UnsafeCell;
1313

0 commit comments

Comments
 (0)