about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-02 12:06:52 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-02 12:06:52 +0000
commit6c5c48e880ca0668c5c8a8029769636831985137 (patch)
tree89563cb0553ee23aafa573d2ebde5f7092d4d6e9
parente2cf2cb30388385f0fe6b406a31a3f9841a72a62 (diff)
downloadrust-6c5c48e880ca0668c5c8a8029769636831985137.tar.gz
rust-6c5c48e880ca0668c5c8a8029769636831985137.zip
Check that nested statics in thread locals are duplicated per thread.
-rw-r--r--tests/ui/statics/nested_thread_local.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/statics/nested_thread_local.rs b/tests/ui/statics/nested_thread_local.rs
new file mode 100644
index 00000000000..10e0a3420d9
--- /dev/null
+++ b/tests/ui/statics/nested_thread_local.rs
@@ -0,0 +1,24 @@
+// Check that nested statics in thread locals are
+// duplicated per thread.
+
+#![feature(const_refs_to_cell)]
+#![feature(thread_local)]
+
+//@run-pass
+
+#[thread_local]
+static mut FOO: &mut u32 = &mut 42;
+
+fn main() {
+    unsafe {
+        *FOO = 1;
+
+        let _ = std::thread::spawn(|| {
+            assert_eq!(*FOO, 42);
+            *FOO = 99;
+        })
+        .join();
+
+        assert_eq!(*FOO, 1);
+    }
+}