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#56916 - oli-obk:static_mut_beta_regression,…
… r=davidtwco Fix mutable references in `static mut` fixes rust-lang#56903
- Loading branch information
Showing
8 changed files
with
69 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// compile-pass | ||
|
||
static mut STDERR_BUFFER_SPACE: [u8; 42] = [0u8; 42]; | ||
|
||
pub static mut STDERR_BUFFER: *mut [u8] = unsafe { &mut STDERR_BUFFER_SPACE }; | ||
|
||
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,9 @@ | ||
#![feature(const_let)] | ||
|
||
static mut STDERR_BUFFER_SPACE: u8 = 0; | ||
|
||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ||
//~^ ERROR references in statics may only refer to immutable values | ||
//~| ERROR static contains unimplemented expression type | ||
|
||
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,16 @@ | ||
error[E0017]: references in statics may only refer to immutable values | ||
--> $DIR/static_mut_containing_mut_ref2.rs:5:46 | ||
| | ||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values | ||
|
||
error[E0019]: static contains unimplemented expression type | ||
--> $DIR/static_mut_containing_mut_ref2.rs:5:45 | ||
| | ||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors occurred: E0017, E0019. | ||
For more information about an error, try `rustc --explain E0017`. |
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,8 @@ | ||
#![feature(const_let)] | ||
|
||
static mut FOO: (u8, u8) = (42, 43); | ||
|
||
static mut BAR: () = unsafe { FOO.0 = 99; }; | ||
//~^ ERROR could not evaluate static initializer | ||
|
||
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,9 @@ | ||
error[E0080]: could not evaluate static initializer | ||
--> $DIR/static_mut_containing_mut_ref3.rs:5:31 | ||
| | ||
LL | static mut BAR: () = unsafe { FOO.0 = 99; }; | ||
| ^^^^^^^^^^ tried to modify a static's initial value from another static's initializer | ||
|
||
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,14 +1,28 @@ | ||
error: cannot mutate statics in the initializer of another static | ||
error[E0080]: could not evaluate static initializer | ||
--> $DIR/write-to-static-mut-in-static.rs:14:33 | ||
| | ||
LL | pub static mut B: () = unsafe { A = 1; }; | ||
| ^^^^^ | ||
| ^^^^^ tried to modify a static's initial value from another static's initializer | ||
|
||
error: cannot mutate statics in the initializer of another static | ||
error[E0391]: cycle detected when const-evaluating `C` | ||
--> $DIR/write-to-static-mut-in-static.rs:17:34 | ||
| | ||
LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ||
| ^^^^^ | ||
| | ||
note: ...which requires const-evaluating `C`... | ||
--> $DIR/write-to-static-mut-in-static.rs:17:1 | ||
| | ||
LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which again requires const-evaluating `C`, completing the cycle | ||
note: cycle used when const-evaluating + checking `C` | ||
--> $DIR/write-to-static-mut-in-static.rs:17:1 | ||
| | ||
LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors occurred: E0080, E0391. | ||
For more information about an error, try `rustc --explain E0080`. |