bless; add test for mutating a static
This commit is contained in:
parent
9d9649adea
commit
f70af91e51
6 changed files with 48 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
|
|||
--> $DIR/assign-to-static-within-other-static.rs:10:5
|
||||
|
|
||||
LL | FOO = 5;
|
||||
| ^^^^^^^ tried to modify a static's initial value from another static's initializer
|
||||
| ^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ 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
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc1 which is read-only
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
LL | | }
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
|
|||
15
src/test/ui/consts/miri_unleashed/mutating_global.rs
Normal file
15
src/test/ui/consts/miri_unleashed/mutating_global.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
|
||||
// Make sure we cannot mutate globals.
|
||||
|
||||
static mut GLOBAL: i32 = 0;
|
||||
|
||||
const MUTATING_GLOBAL: () = {
|
||||
unsafe {
|
||||
GLOBAL = 99 //~ ERROR any use of this value will cause an error
|
||||
//~^ WARN skipping const checks
|
||||
//~| WARN skipping const checks
|
||||
}
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
29
src/test/ui/consts/miri_unleashed/mutating_global.stderr
Normal file
29
src/test/ui/consts/miri_unleashed/mutating_global.stderr
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
warning: skipping const checks
|
||||
--> $DIR/mutating_global.rs:9:9
|
||||
|
|
||||
LL | GLOBAL = 99
|
||||
| ^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/mutating_global.rs:9:9
|
||||
|
|
||||
LL | GLOBAL = 99
|
||||
| ^^^^^^
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/mutating_global.rs:9:9
|
||||
|
|
||||
LL | / const MUTATING_GLOBAL: () = {
|
||||
LL | | unsafe {
|
||||
LL | | GLOBAL = 99
|
||||
| | ^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | }
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
|
|||
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
|
|||
--> $DIR/static_mut_containing_mut_ref3.rs:3:31
|
||||
|
|
||||
LL | static mut BAR: () = unsafe { FOO.0 = 99; };
|
||||
| ^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
|
||||
| ^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue