Skip to content

Commit 19ddfb5

Browse files
committed
Update miri unleashed tests
1 parent 5e61e4c commit 19ddfb5

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
22

33
#![feature(const_raw_ptr_deref)]
4+
#![feature(const_mut_refs)]
45
#![deny(const_err)]
56

67
use std::cell::UnsafeCell;
@@ -12,7 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1213
const MUTATING_BEHIND_RAW: () = {
1314
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
1415
unsafe {
15-
*MUTABLE_BEHIND_RAW = 99 //~ ERROR constant contains unimplemented expression type
16+
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error
1617
}
1718
};
1819

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

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

7-
error[E0019]: constant contains unimplemented expression type
8-
--> $DIR/mutable_const.rs:15:9
7+
error: any use of this value will cause an error
8+
--> $DIR/mutable_const.rs:16:9
99
|
10-
LL | *MUTABLE_BEHIND_RAW = 99
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | / const MUTATING_BEHIND_RAW: () = {
11+
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
12+
LL | | unsafe {
13+
LL | | *MUTABLE_BEHIND_RAW = 99
14+
| | ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
15+
LL | | }
16+
LL | | };
17+
| |__-
18+
|
19+
note: lint level defined here
20+
--> $DIR/mutable_const.rs:5:9
21+
|
22+
LL | #![deny(const_err)]
23+
| ^^^^^^^^^
1224

1325
error: aborting due to previous error
1426

15-
For more information about this error, try `rustc --explain E0019`.

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

+5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ use std::cell::UnsafeCell;
66

77
// a test demonstrating what things we could allow with a smarter const qualification
88

9+
// this is fine because is not possible to mutate through an immutable reference.
910
static FOO: &&mut u32 = &&mut 42;
1011

12+
// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
13+
// which puts the mutable reference behind an immutable one.
1114
static BAR: &mut () = &mut ();
1215

1316
struct Foo<T>(T);
1417

18+
// this is fine for the same reason as `BAR`.
1519
static BOO: &mut Foo<()> = &mut Foo(());
1620

1721
struct Meh {
@@ -25,6 +29,7 @@ static MEH: Meh = Meh {
2529
//~^ WARN: skipping const checks
2630
};
2731

32+
// this is fine for the same reason as `BAR`.
2833
static OH_YES: &mut i32 = &mut 42;
2934

3035
fn main() {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: skipping const checks
2-
--> $DIR/mutable_references.rs:24:8
2+
--> $DIR/mutable_references.rs:28:8
33
|
44
LL | x: &UnsafeCell::new(42),
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
8-
--> $DIR/mutable_references.rs:34:5
8+
--> $DIR/mutable_references.rs:39:5
99
|
1010
LL | *OH_YES = 99;
1111
| ^^^^^^^^^^^^ cannot assign
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-pass
2+
// compile-flags: -Zunleash-the-miri-inside-of-you
3+
#![feature(const_mut_refs)]
4+
#![allow(const_err)]
5+
6+
static OH_YES: &mut i32 = &mut 42;
7+
8+
fn main() {
9+
// Make sure `OH_YES` can be read.
10+
assert_eq!(*OH_YES, 42);
11+
}

0 commit comments

Comments
 (0)