1
Fork 0

Update miri unleashed tests

This commit is contained in:
Christian Poveda 2019-11-28 11:38:07 -05:00
parent 5e61e4cadc
commit 19ddfb545b
5 changed files with 37 additions and 9 deletions

View file

@ -1,6 +1,7 @@
// compile-flags: -Zunleash-the-miri-inside-of-you // compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(const_raw_ptr_deref)] #![feature(const_raw_ptr_deref)]
#![feature(const_mut_refs)]
#![deny(const_err)] #![deny(const_err)]
use std::cell::UnsafeCell; 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: () = { const MUTATING_BEHIND_RAW: () = {
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time. // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
unsafe { 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
} }
}; };

View file

@ -1,15 +1,26 @@
warning: skipping const checks 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 _; LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error[E0019]: constant contains unimplemented expression type error: any use of this value will cause an error
--> $DIR/mutable_const.rs:15:9 --> $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 error: aborting due to previous error
For more information about this error, try `rustc --explain E0019`.

View file

@ -6,12 +6,16 @@ use std::cell::UnsafeCell;
// a test demonstrating what things we could allow with a smarter const qualification // 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; 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 (); static BAR: &mut () = &mut ();
struct Foo<T>(T); struct Foo<T>(T);
// this is fine for the same reason as `BAR`.
static BOO: &mut Foo<()> = &mut Foo(()); static BOO: &mut Foo<()> = &mut Foo(());
struct Meh { struct Meh {
@ -25,6 +29,7 @@ static MEH: Meh = Meh {
//~^ WARN: skipping const checks //~^ WARN: skipping const checks
}; };
// this is fine for the same reason as `BAR`.
static OH_YES: &mut i32 = &mut 42; static OH_YES: &mut i32 = &mut 42;
fn main() { fn main() {

View file

@ -1,11 +1,11 @@
warning: skipping const checks warning: skipping const checks
--> $DIR/mutable_references.rs:24:8 --> $DIR/mutable_references.rs:28:8
| |
LL | x: &UnsafeCell::new(42), LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item 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; LL | *OH_YES = 99;
| ^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^ cannot assign

View 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);
}