forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67337 - oli-obk:no_mut_static_ref_from_cons…
…t, r=RalfJung Ensure that evaluating or validating a constant never reads from a static r? @RalfJung as per rust-lang#66302 (comment) This does not yet address the fact that evaluation of a constant can read from a static (under unleash-miri)
- Loading branch information
Showing
15 changed files
with
301 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
|
||
#![allow(dead_code)] | ||
|
||
const TEST: &u8 = &MY_STATIC; | ||
//~^ skipping const checks | ||
//~| it is undefined behavior to use this value | ||
|
||
static MY_STATIC: u8 = 4; | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: skipping const checks | ||
--> $DIR/const-points-to-static.rs:5:20 | ||
| | ||
LL | const TEST: &u8 = &MY_STATIC; | ||
| ^^^^^^^^^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/const-points-to-static.rs:5:1 | ||
| | ||
LL | const TEST: &u8 = &MY_STATIC; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static | ||
| | ||
= 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 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
warning: skipping const checks | ||
--> $DIR/const-prop-read-static-in-const.rs:6:18 | ||
--> $DIR/const-prop-read-static-in-const.rs:5:18 | ||
| | ||
LL | const TEST: u8 = MY_STATIC; | ||
| ^^^^^^^^^ | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/const-prop-read-static-in-const.rs:5:18 | ||
| | ||
LL | const TEST: u8 = MY_STATIC; | ||
| -----------------^^^^^^^^^- | ||
| | | ||
| constant accesses static | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
38 changes: 38 additions & 0 deletions
38
src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
#![warn(const_err)] | ||
|
||
#![feature(const_raw_ptr_deref)] | ||
|
||
use std::sync::atomic::AtomicUsize; | ||
use std::sync::atomic::Ordering; | ||
|
||
const BOO: &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 | ||
}; | ||
|
||
const FOO: 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 = { | ||
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 | ||
//~^ WARN skipping const checks | ||
|
||
// ok some day perhaps | ||
const BOO_OK: &usize = { //~ ERROR it is undefined behavior to use this value | ||
static FOO: usize = 0; | ||
&FOO | ||
//~^ WARN skipping const checks | ||
}; | ||
fn main() {} |
Oops, something went wrong.