]> git.lizzy.rs Git - rust.git/commitdiff
Add a regression test for mutating a non-mut #[thread_local]
authorMichael Bradshaw <mjbshaw@gmail.com>
Mon, 24 Dec 2018 23:07:10 +0000 (16:07 -0700)
committerMichael Bradshaw <mjbshaw@gmail.com>
Mon, 14 Jan 2019 16:02:33 +0000 (08:02 -0800)
src/test/ui/thread-local-mutation.nll.stderr [new file with mode: 0644]
src/test/ui/thread-local-mutation.rs [new file with mode: 0644]
src/test/ui/thread-local-mutation.stderr [new file with mode: 0644]

diff --git a/src/test/ui/thread-local-mutation.nll.stderr b/src/test/ui/thread-local-mutation.nll.stderr
new file mode 100644 (file)
index 0000000..0a3664b
--- /dev/null
@@ -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 (file)
index 0000000..e738225
--- /dev/null
@@ -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 (file)
index 0000000..bf29852
--- /dev/null
@@ -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`.