File tree 5 files changed +37
-9
lines changed
src/test/ui/consts/miri_unleashed
5 files changed +37
-9
lines changed Original file line number Diff line number Diff line change 1
1
// compile-flags: -Zunleash-the-miri-inside-of-you
2
2
3
3
#![ feature( const_raw_ptr_deref) ]
4
+ #![ feature( const_mut_refs) ]
4
5
#![ deny( const_err) ]
5
6
6
7
use std:: cell:: UnsafeCell ;
@@ -12,7 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
12
13
const MUTATING_BEHIND_RAW : ( ) = {
13
14
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
14
15
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
16
17
}
17
18
} ;
18
19
Original file line number Diff line number Diff line change 1
1
warning: skipping const checks
2
- --> $DIR/mutable_const.rs:9 :38
2
+ --> $DIR/mutable_const.rs:10 :38
3
3
|
4
4
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
5
5
| ^^^^^^^^^^^^^^^^^^^^
6
6
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
9
9
|
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
+ | ^^^^^^^^^
12
24
13
25
error: aborting due to previous error
14
26
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;
6
6
7
7
// a test demonstrating what things we could allow with a smarter const qualification
8
8
9
+ // this is fine because is not possible to mutate through an immutable reference.
9
10
static FOO : & & mut u32 = & & mut 42 ;
10
11
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.
11
14
static BAR : & mut ( ) = & mut ( ) ;
12
15
13
16
struct Foo < T > ( T ) ;
14
17
18
+ // this is fine for the same reason as `BAR`.
15
19
static BOO : & mut Foo < ( ) > = & mut Foo ( ( ) ) ;
16
20
17
21
struct Meh {
@@ -25,6 +29,7 @@ static MEH: Meh = Meh {
25
29
//~^ WARN: skipping const checks
26
30
} ;
27
31
32
+ // this is fine for the same reason as `BAR`.
28
33
static OH_YES : & mut i32 = & mut 42 ;
29
34
30
35
fn main ( ) {
Original file line number Diff line number Diff line change 1
1
warning: skipping const checks
2
- --> $DIR/mutable_references.rs:24 :8
2
+ --> $DIR/mutable_references.rs:28 :8
3
3
|
4
4
LL | x: &UnsafeCell::new(42),
5
5
| ^^^^^^^^^^^^^^^^^^^^
6
6
7
7
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
9
9
|
10
10
LL | *OH_YES = 99;
11
11
| ^^^^^^^^^^^^ 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