Skip to content

Commit

Permalink
Add a regression test for mutating a non-mut #[thread_local]
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbshaw committed Jan 14, 2019
1 parent 4755e2f commit f4ded5b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/ui/thread-local-mutation.nll.stderr
@@ -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`.
18 changes: 18 additions & 0 deletions src/test/ui/thread-local-mutation.rs
@@ -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);
}
9 changes: 9 additions & 0 deletions src/test/ui/thread-local-mutation.stderr
@@ -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`.

0 comments on commit f4ded5b

Please sign in to comment.