File tree Expand file tree Collapse file tree 5 files changed +37
-9
lines changed
src/test/ui/consts/miri_unleashed Expand file tree Collapse file tree 5 files changed +37
-9
lines changed Original file line number Diff line number Diff line change 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
67use std:: cell:: UnsafeCell ;
@@ -12,7 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1213const 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
Original file line number Diff line number Diff line change 11warning: skipping const checks
2- --> $DIR/mutable_const.rs:9 :38
2+ --> $DIR/mutable_const.rs:10 :38
33 |
44LL | 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
1325error: aborting due to previous error
1426
15- For more information about this error, try `rustc --explain E0019`.
Original file line number Diff line number Diff 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.
910static 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.
1114static BAR : & mut ( ) = & mut ( ) ;
1215
1316struct Foo < T > ( T ) ;
1417
18+ // this is fine for the same reason as `BAR`.
1519static BOO : & mut Foo < ( ) > = & mut Foo ( ( ) ) ;
1620
1721struct 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`.
2833static OH_YES : & mut i32 = & mut 42 ;
2934
3035fn main ( ) {
Original file line number Diff line number Diff line change 11warning: skipping const checks
2- --> $DIR/mutable_references.rs:24 :8
2+ --> $DIR/mutable_references.rs:28 :8
33 |
44LL | x: &UnsafeCell::new(42),
55 | ^^^^^^^^^^^^^^^^^^^^
66
77error[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 |
1010LL | *OH_YES = 99;
1111 | ^^^^^^^^^^^^ cannot assign
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments