Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test the unleashed Miri #67580

Merged
merged 4 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;

const BOO: &usize = { //~ ERROR undefined behavior to use this value
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't like my useless variable names? 🙃

If we'd had the _ name feature back when I wrote the test I'dve used that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue readable names are better even than _ ;)

static FOO: AtomicUsize = AtomicUsize::new(0);
unsafe { &*(&FOO as *const _ as *const usize) }
//~^ WARN skipping const checks
};

const FOO: usize = {
const MUTATE_INTERIOR_MUT: usize = {
static FOO: AtomicUsize = AtomicUsize::new(0);
FOO.fetch_add(1, Ordering::Relaxed) //~ WARN any use of this value will cause an error
//~^ WARN skipping const checks
//~| WARN skipping const checks
};

const BAR: usize = {
const READ_INTERIOR_MUT: usize = {
static FOO: AtomicUsize = AtomicUsize::new(0);
unsafe { *(&FOO as *const _ as *const usize) } //~ WARN any use of this value will cause an err
//~^ WARN skipping const checks
};

static mut MUTABLE: u32 = 0;
const BAD: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
const READ_MUT: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
//~^ WARN skipping const checks

// ok some day perhaps
const BOO_OK: &usize = { //~ ERROR it is undefined behavior to use this value
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
static FOO: usize = 0;
&FOO
//~^ WARN skipping const checks
Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ LL | unsafe { *(&FOO as *const _ as *const usize) }
| ^^^

warning: skipping const checks
--> $DIR/const_refers_to_static.rs:29:27
--> $DIR/const_refers_to_static.rs:29:32
|
LL | const BAD: u32 = unsafe { MUTABLE };
| ^^^^^^^
LL | const READ_MUT: u32 = unsafe { MUTABLE };
| ^^^^^^^

warning: skipping const checks
--> $DIR/const_refers_to_static.rs:35:6
Expand All @@ -37,7 +37,7 @@ LL | &FOO
error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static.rs:9:1
|
LL | / const BOO: &usize = {
LL | / const REF_INTERIOR_MUT: &usize = {
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | unsafe { &*(&FOO as *const _ as *const usize) }
LL | |
Expand All @@ -49,7 +49,7 @@ LL | | };
warning: any use of this value will cause an error
--> $DIR/const_refers_to_static.rs:17:5
|
LL | / const FOO: usize = {
LL | / const MUTATE_INTERIOR_MUT: usize = {
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | FOO.fetch_add(1, Ordering::Relaxed)
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `std::sync::atomic::AtomicUsize::fetch_add`
Expand All @@ -67,7 +67,7 @@ LL | #![warn(const_err)]
warning: any use of this value will cause an error
--> $DIR/const_refers_to_static.rs:24:14
|
LL | / const BAR: usize = {
LL | / const READ_INTERIOR_MUT: usize = {
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | unsafe { *(&FOO as *const _ as *const usize) }
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
Expand All @@ -76,17 +76,17 @@ LL | | };
| |__-

warning: any use of this value will cause an error
--> $DIR/const_refers_to_static.rs:29:27
--> $DIR/const_refers_to_static.rs:29:32
|
LL | const BAD: u32 = unsafe { MUTABLE };
| --------------------------^^^^^^^---
| |
| constant accesses static
LL | const READ_MUT: u32 = unsafe { MUTABLE };
| -------------------------------^^^^^^^---
| |
| constant accesses static

error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static.rs:33:1
|
LL | / const BOO_OK: &usize = {
LL | / const READ_IMMUT: &usize = {
LL | | static FOO: usize = 0;
LL | | &FOO
LL | |
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/consts/miri_unleashed/drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// ignore-x86 FIXME: missing sysroot spans (#53081)
// error-pattern: calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
#![deny(const_err)]

use std::mem::ManuallyDrop;

fn main() {}

static TEST_OK: () = {
let v: Vec<i32> = Vec::new();
let _v = ManuallyDrop::new(v);
};

// Make sure we catch executing bad drop functions.
// The actual error is tested by the error-pattern above.
static TEST_BAD: () = {
let _v: Vec<i32> = Vec::new();
//~^ WARN skipping const check
};
24 changes: 24 additions & 0 deletions src/test/ui/consts/miri_unleashed/drop.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
warning: skipping const checks
--> $DIR/drop.rs:18:9
|
LL | let _v: Vec<i32> = Vec::new();
| ^^

error[E0080]: could not evaluate static initializer
--> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
|
LL | / unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
LL | | // Code here does not matter - this is replaced by the
LL | | // real drop glue by the compiler.
LL | | real_drop_in_place(to_drop)
LL | | }
| |_^ calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
|
::: $DIR/drop.rs:20:1
|
LL | };
| - inside call to `std::ptr::real_drop_in_place::<std::vec::Vec<i32>> - shim(Some(std::vec::Vec<i32>))` at $DIR/drop.rs:20:1

error: aborting due to previous error

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