-
Notifications
You must be signed in to change notification settings - Fork 13.4k
miri-unleash tests: ensure they fire even with 'allow(const_err)' #71318
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
warning: skipping const checks | ||
--> $DIR/abi-mismatch.rs:9:5 | ||
--> $DIR/abi-mismatch.rs:10:5 | ||
| | ||
LL | my_fn(); | ||
| ^^^^^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/abi-mismatch.rs:13:39 | ||
--> $DIR/abi-mismatch.rs:17:40 | ||
| | ||
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/abi-mismatch.rs:9:5 | ||
error[E0080]: could not evaluate static initializer | ||
--> $DIR/abi-mismatch.rs:10:5 | ||
| | ||
LL | my_fn(); | ||
| ^^^^^^^ | ||
| | | ||
| calling a function with ABI C using caller ABI Rust | ||
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:9:5 | ||
| inside `VAL` at $DIR/abi-mismatch.rs:13:17 | ||
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5 | ||
... | ||
LL | const VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); | ||
| -------------------------------------------------------------------------------------- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); | ||
| --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:17:18 | ||
|
||
error: aborting due to previous error; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
// build-fail | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
#![warn(const_err)] | ||
#![allow(const_err)] | ||
|
||
#![feature(const_raw_ptr_deref)] | ||
|
||
use std::sync::atomic::AtomicUsize; | ||
use std::sync::atomic::Ordering; | ||
|
||
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value | ||
static FOO: AtomicUsize = AtomicUsize::new(0); | ||
unsafe { &*(&FOO as *const _ as *const usize) } | ||
//~^ WARN skipping const checks | ||
}; | ||
// These tests only cause an error when *using* the const. | ||
|
||
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 | ||
FOO.fetch_add(1, Ordering::Relaxed) | ||
//~^ WARN skipping const checks | ||
//~| WARN skipping const checks | ||
}; | ||
|
||
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 | ||
unsafe { *(&FOO as *const _ as *const usize) } | ||
//~^ WARN skipping const checks | ||
}; | ||
|
||
static mut MUTABLE: u32 = 0; | ||
const READ_MUT: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error | ||
const READ_MUT: u32 = unsafe { MUTABLE }; | ||
//~^ WARN skipping const checks | ||
//~| WARN skipping const checks | ||
|
||
// ok some day perhaps | ||
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value | ||
static FOO: usize = 0; | ||
&FOO | ||
//~^ WARN skipping const checks | ||
}; | ||
fn main() {} | ||
fn main() { | ||
MUTATE_INTERIOR_MUT; | ||
//~^ ERROR: erroneous constant used | ||
READ_INTERIOR_MUT; | ||
//~^ ERROR: erroneous constant used | ||
READ_MUT; | ||
//~^ ERROR: erroneous constant used | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes the error is "erroneous constant used", other times it is "evaluation of constant expression failed". I am not sure where the inconsistency is coming from. Maybe it is because in the latter case, promotion was involved? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,51 @@ | ||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:11:18 | ||
| | ||
LL | unsafe { &*(&FOO as *const _ as *const usize) } | ||
| ^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:17:5 | ||
--> $DIR/const_refers_to_static.rs:14:5 | ||
| | ||
LL | FOO.fetch_add(1, Ordering::Relaxed) | ||
| ^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:17:5 | ||
--> $DIR/const_refers_to_static.rs:14:5 | ||
| | ||
LL | FOO.fetch_add(1, Ordering::Relaxed) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:24:17 | ||
--> $DIR/const_refers_to_static.rs:21:17 | ||
| | ||
LL | unsafe { *(&FOO as *const _ as *const usize) } | ||
| ^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:29:32 | ||
--> $DIR/const_refers_to_static.rs:26:32 | ||
| | ||
LL | const READ_MUT: u32 = unsafe { MUTABLE }; | ||
| ^^^^^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:29:32 | ||
--> $DIR/const_refers_to_static.rs:26:32 | ||
| | ||
LL | const READ_MUT: u32 = unsafe { MUTABLE }; | ||
| ^^^^^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static.rs:36:6 | ||
error[E0080]: erroneous constant used | ||
--> $DIR/const_refers_to_static.rs:31:5 | ||
| | ||
LL | &FOO | ||
| ^^^ | ||
LL | MUTATE_INTERIOR_MUT; | ||
| ^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/const_refers_to_static.rs:9:1 | ||
error[E0080]: erroneous constant used | ||
--> $DIR/const_refers_to_static.rs:33:5 | ||
| | ||
LL | / const REF_INTERIOR_MUT: &usize = { | ||
LL | | static FOO: AtomicUsize = AtomicUsize::new(0); | ||
LL | | unsafe { &*(&FOO as *const _ as *const usize) } | ||
LL | | | ||
LL | | }; | ||
| |__^ type validation failed: encountered a reference pointing to a static variable | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
LL | READ_INTERIOR_MUT; | ||
| ^^^^^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
warning: any use of this value will cause an error | ||
--> $DIR/const_refers_to_static.rs:17:5 | ||
| | ||
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` | ||
LL | | | ||
LL | | | ||
LL | | }; | ||
| |__- | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/const_refers_to_static.rs:2:9 | ||
| | ||
LL | #![warn(const_err)] | ||
| ^^^^^^^^^ | ||
|
||
warning: any use of this value will cause an error | ||
--> $DIR/const_refers_to_static.rs:24:14 | ||
| | ||
LL | / const READ_INTERIOR_MUT: usize = { | ||
LL | | static FOO: AtomicUsize = AtomicUsize::new(0); | ||
LL | | unsafe { *(&FOO as *const _ as *const usize) } | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static | ||
LL | | | ||
LL | | }; | ||
| |__- | ||
|
||
warning: any use of this value will cause an error | ||
--> $DIR/const_refers_to_static.rs:29:32 | ||
| | ||
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:34:1 | ||
| | ||
LL | / const READ_IMMUT: &usize = { | ||
LL | | static FOO: usize = 0; | ||
LL | | &FOO | ||
LL | | | ||
LL | | }; | ||
| |__^ type validation failed: encountered a reference pointing to a static variable | ||
error[E0080]: erroneous constant used | ||
--> $DIR/const_refers_to_static.rs:35:5 | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
LL | READ_MUT; | ||
| ^^^^^^^^ referenced constant has errors | ||
|
||
error: aborting due to 2 previous errors; 10 warnings emitted | ||
error: aborting due to 3 previous errors; 5 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
#![allow(const_err)] | ||
|
||
#![feature(const_raw_ptr_deref)] | ||
|
||
use std::sync::atomic::AtomicUsize; | ||
use std::sync::atomic::Ordering; | ||
|
||
// These tests cause immediate error when *defining* the const. | ||
|
||
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value | ||
static FOO: AtomicUsize = AtomicUsize::new(0); | ||
unsafe { &*(&FOO as *const _ as *const usize) } | ||
//~^ WARN skipping const checks | ||
}; | ||
|
||
// ok some day perhaps | ||
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value | ||
static FOO: usize = 0; | ||
&FOO | ||
//~^ WARN skipping const checks | ||
}; | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static2.rs:13:18 | ||
| | ||
LL | unsafe { &*(&FOO as *const _ as *const usize) } | ||
| ^^^ | ||
|
||
warning: skipping const checks | ||
--> $DIR/const_refers_to_static2.rs:20:6 | ||
| | ||
LL | &FOO | ||
| ^^^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/const_refers_to_static2.rs:11:1 | ||
| | ||
LL | / const REF_INTERIOR_MUT: &usize = { | ||
LL | | static FOO: AtomicUsize = AtomicUsize::new(0); | ||
LL | | unsafe { &*(&FOO as *const _ as *const usize) } | ||
LL | | | ||
LL | | }; | ||
| |__^ type validation failed: encountered a reference pointing to a static variable | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/const_refers_to_static2.rs:18:1 | ||
| | ||
LL | / const READ_IMMUT: &usize = { | ||
LL | | static FOO: usize = 0; | ||
LL | | &FOO | ||
LL | | | ||
LL | | }; | ||
| |__^ type validation failed: encountered a reference pointing to a static variable | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error: aborting due to 2 previous errors; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
// normalize-stderr-test "alloc[0-9]+" -> "allocN" | ||
|
||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
#![deny(const_err)] | ||
#![deny(const_err)] // The `allow` variant is tested by `mutable_const2`. | ||
//~^ NOTE lint level | ||
// Here we check that even though `MUTABLE_BEHIND_RAW` is created from a mutable | ||
// allocation, we intern that allocation as *immutable* and reject writes to it. | ||
// We avoid the `delay_span_bug` ICE by having compilation fail via the `deny` above. | ||
|
||
use std::cell::UnsafeCell; | ||
|
||
// make sure we do not just intern this as mutable | ||
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; | ||
//~^ WARN: skipping const checks | ||
|
||
const MUTATING_BEHIND_RAW: () = { | ||
const MUTATING_BEHIND_RAW: () = { //~ NOTE | ||
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time. | ||
unsafe { | ||
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error | ||
//~^ NOTE: which is read-only | ||
// FIXME would be good to match more of the error message here, but looks like we | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no way to normalize the messages that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, these can't be normalized |
||
// normalize *after* checking the annoations here. | ||
} | ||
}; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.