Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a regression test for mutating a non-mut #[thread_local] #57107

Merged
merged 1 commit into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/test/ui/thread-local-mutation.nll.stderr
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`.
18 changes: 18 additions & 0 deletions src/test/ui/thread-local-mutation.rs
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);
}
9 changes: 9 additions & 0 deletions src/test/ui/thread-local-mutation.stderr
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`.