diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-01-18 22:56:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-18 22:56:34 +0100 |
| commit | b9cb5db5e89a511e1a0488d1a9101fb32d3ad6ad (patch) | |
| tree | d35817b2b92ec8b8890197e554a4f556af641312 | |
| parent | c76f3c374f80e20b612601a3c375666a58ac3971 (diff) | |
| parent | f4ded5b5591b3ec1446422dd9d62d404d4335753 (diff) | |
| download | rust-b9cb5db5e89a511e1a0488d1a9101fb32d3ad6ad.tar.gz rust-b9cb5db5e89a511e1a0488d1a9101fb32d3ad6ad.zip | |
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
Add a regression test for mutating a non-mut #[thread_local] This should close #54901 since the regression has since been fixed.
| -rw-r--r-- | src/test/ui/thread-local-mutation.nll.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/thread-local-mutation.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/thread-local-mutation.stderr | 9 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/thread-local-mutation.nll.stderr b/src/test/ui/thread-local-mutation.nll.stderr new file mode 100644 index 00000000000..0a3664b0d9d --- /dev/null +++ b/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`. diff --git a/src/test/ui/thread-local-mutation.rs b/src/test/ui/thread-local-mutation.rs new file mode 100644 index 00000000000..e738225ce2a --- /dev/null +++ b/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); +} diff --git a/src/test/ui/thread-local-mutation.stderr b/src/test/ui/thread-local-mutation.stderr new file mode 100644 index 00000000000..bf298523e1b --- /dev/null +++ b/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`. |
