Skip to content

Commit f70af91

Browse files
committed
bless; add test for mutating a static
1 parent 9d9649a commit f70af91

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/assign-to-static-within-other-static.rs:10:5
33
|
44
LL | FOO = 5;
5-
| ^^^^^^^ tried to modify a static's initial value from another static's initializer
5+
| ^^^^^^^ modifying a static's initial value from another static's initializer
66

77
error: aborting due to previous error
88

src/test/ui/consts/miri_unleashed/mutable_const.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | / const MUTATING_BEHIND_RAW: () = {
1111
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
1212
LL | | unsafe {
1313
LL | | *MUTABLE_BEHIND_RAW = 99
14-
| | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc1 which is read-only
14+
| | ^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
1515
LL | | }
1616
LL | | };
1717
| |__-
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
3+
// Make sure we cannot mutate globals.
4+
5+
static mut GLOBAL: i32 = 0;
6+
7+
const MUTATING_GLOBAL: () = {
8+
unsafe {
9+
GLOBAL = 99 //~ ERROR any use of this value will cause an error
10+
//~^ WARN skipping const checks
11+
//~| WARN skipping const checks
12+
}
13+
};
14+
15+
fn main() {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: skipping const checks
2+
--> $DIR/mutating_global.rs:9:9
3+
|
4+
LL | GLOBAL = 99
5+
| ^^^^^^
6+
7+
warning: skipping const checks
8+
--> $DIR/mutating_global.rs:9:9
9+
|
10+
LL | GLOBAL = 99
11+
| ^^^^^^
12+
13+
error: any use of this value will cause an error
14+
--> $DIR/mutating_global.rs:9:9
15+
|
16+
LL | / const MUTATING_GLOBAL: () = {
17+
LL | | unsafe {
18+
LL | | GLOBAL = 99
19+
| | ^^^^^^^^^^^ modifying a static's initial value from another static's initializer
20+
LL | |
21+
LL | |
22+
LL | | }
23+
LL | | };
24+
| |__-
25+
|
26+
= note: `#[deny(const_err)]` on by default
27+
28+
error: aborting due to previous error
29+

src/test/ui/consts/static_mut_containing_mut_ref2.mut_refs.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
33
|
44
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
66

77
error: aborting due to previous error
88

src/test/ui/consts/static_mut_containing_mut_ref3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/static_mut_containing_mut_ref3.rs:3:31
33
|
44
LL | static mut BAR: () = unsafe { FOO.0 = 99; };
5-
| ^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
5+
| ^^^^^^^^^^ modifying a static's initial value from another static's initializer
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)