Skip to content

Commit a1ef22a

Browse files
authored
Rollup merge of rust-lang#57107 - mjbshaw:thread_local_test, r=nikomatsakis
Add a regression test for mutating a non-mut #[thread_local] This should close rust-lang#54901 since the regression has since been fixed.
2 parents 8b8c576 + f4ded5b commit a1ef22a

3 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0594]: cannot assign to immutable static item `S`
2+
--> $DIR/thread-local-mutation.rs:11:5
3+
|
4+
LL | S = "after"; //~ ERROR cannot assign to immutable
5+
| ^^^^^^^^^^^ cannot assign
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0594`.

src/test/ui/thread-local-mutation.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for #54901: immutable thread locals could be mutated. See:
2+
// https://github.com/rust-lang/rust/issues/29594#issuecomment-328177697
3+
// https://github.com/rust-lang/rust/issues/54901
4+
5+
#![feature(thread_local)]
6+
7+
#[thread_local]
8+
static S: &str = "before";
9+
10+
fn set_s() {
11+
S = "after"; //~ ERROR cannot assign to immutable
12+
}
13+
14+
fn main() {
15+
println!("{}", S);
16+
set_s();
17+
println!("{}", S);
18+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0594]: cannot assign to immutable thread-local static item
2+
--> $DIR/thread-local-mutation.rs:11:5
3+
|
4+
LL | S = "after"; //~ ERROR cannot assign to immutable
5+
| ^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0594`.

0 commit comments

Comments
 (0)