Update miri unleashed tests
This commit is contained in:
parent
5e61e4cadc
commit
19ddfb545b
5 changed files with 37 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![deny(const_err)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
@ -12,7 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
|||
const MUTATING_BEHIND_RAW: () = {
|
||||
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
||||
unsafe {
|
||||
*MUTABLE_BEHIND_RAW = 99 //~ ERROR constant contains unimplemented expression type
|
||||
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,15 +1,26 @@
|
|||
warning: skipping const checks
|
||||
--> $DIR/mutable_const.rs:9:38
|
||||
--> $DIR/mutable_const.rs:10:38
|
||||
|
|
||||
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0019]: constant contains unimplemented expression type
|
||||
--> $DIR/mutable_const.rs:15:9
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/mutable_const.rs:16:9
|
||||
|
|
||||
LL | *MUTABLE_BEHIND_RAW = 99
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / const MUTATING_BEHIND_RAW: () = {
|
||||
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
||||
LL | | unsafe {
|
||||
LL | | *MUTABLE_BEHIND_RAW = 99
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
|
||||
LL | | }
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/mutable_const.rs:5:9
|
||||
|
|
||||
LL | #![deny(const_err)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -6,12 +6,16 @@ use std::cell::UnsafeCell;
|
|||
|
||||
// a test demonstrating what things we could allow with a smarter const qualification
|
||||
|
||||
// this is fine because is not possible to mutate through an immutable reference.
|
||||
static FOO: &&mut u32 = &&mut 42;
|
||||
|
||||
// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
|
||||
// which puts the mutable reference behind an immutable one.
|
||||
static BAR: &mut () = &mut ();
|
||||
|
||||
struct Foo<T>(T);
|
||||
|
||||
// this is fine for the same reason as `BAR`.
|
||||
static BOO: &mut Foo<()> = &mut Foo(());
|
||||
|
||||
struct Meh {
|
||||
|
@ -25,6 +29,7 @@ static MEH: Meh = Meh {
|
|||
//~^ WARN: skipping const checks
|
||||
};
|
||||
|
||||
// this is fine for the same reason as `BAR`.
|
||||
static OH_YES: &mut i32 = &mut 42;
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
warning: skipping const checks
|
||||
--> $DIR/mutable_references.rs:24:8
|
||||
--> $DIR/mutable_references.rs:28:8
|
||||
|
|
||||
LL | x: &UnsafeCell::new(42),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
|
||||
--> $DIR/mutable_references.rs:34:5
|
||||
--> $DIR/mutable_references.rs:39:5
|
||||
|
|
||||
LL | *OH_YES = 99;
|
||||
| ^^^^^^^^^^^^ cannot assign
|
||||
|
|
11
src/test/ui/consts/miri_unleashed/read_from_static.rs
Normal file
11
src/test/ui/consts/miri_unleashed/read_from_static.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
// run-pass
|
||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
#![feature(const_mut_refs)]
|
||||
#![allow(const_err)]
|
||||
|
||||
static OH_YES: &mut i32 = &mut 42;
|
||||
|
||||
fn main() {
|
||||
// Make sure `OH_YES` can be read.
|
||||
assert_eq!(*OH_YES, 42);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue