forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#57107 - mjbshaw:thread_local_test, r=nikoma…
…tsakis Add a regression test for mutating a non-mut #[thread_local] This should close rust-lang#54901 since the regression has since been fixed.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0594]: cannot assign to immutable static item `S` | ||
--> $DIR/thread-local-mutation.rs:11:5 | ||
| | ||
LL | S = "after"; //~ ERROR cannot assign to immutable | ||
| ^^^^^^^^^^^ cannot assign | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0594`. |
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,18 @@ | ||
// Regression test for #54901: immutable thread locals could be mutated. See: | ||
// https://github.com/rust-lang/rust/issues/29594#issuecomment-328177697 | ||
// https://github.com/rust-lang/rust/issues/54901 | ||
|
||
#![feature(thread_local)] | ||
|
||
#[thread_local] | ||
static S: &str = "before"; | ||
|
||
fn set_s() { | ||
S = "after"; //~ ERROR cannot assign to immutable | ||
} | ||
|
||
fn main() { | ||
println!("{}", S); | ||
set_s(); | ||
println!("{}", S); | ||
} |
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[E0594]: cannot assign to immutable thread-local static item | ||
--> $DIR/thread-local-mutation.rs:11:5 | ||
| | ||
LL | S = "after"; //~ ERROR cannot assign to immutable | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0594`. |