Skip to content

Commit 6b76b0e

Browse files
committed
explain what we are testing in mutable_const
1 parent 6463ecf commit 6b76b0e

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

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)] // FIXME: ICEs with allow! See #71316.
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)] // FIXME: ICEs with allow! See #71316.
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
#![allow(const_err)]
99

0 commit comments

Comments
 (0)