about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/threads-sendsync/tls-dont-move-after-init.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/threads-sendsync/tls-dont-move-after-init.rs b/tests/ui/threads-sendsync/tls-dont-move-after-init.rs
new file mode 100644
index 00000000000..2cd2a88a2c7
--- /dev/null
+++ b/tests/ui/threads-sendsync/tls-dont-move-after-init.rs
@@ -0,0 +1,39 @@
+//@ run-pass
+#![allow(stable_features)]
+//@ needs-threads
+#![feature(thread_local_try_with)]
+
+use std::cell::Cell;
+use std::thread;
+
+#[derive(Default)]
+struct Foo {
+    ptr: Cell<*const Foo>,
+}
+
+impl Foo {
+    fn touch(&self) {
+        if self.ptr.get().is_null() {
+            self.ptr.set(self);
+        } else {
+            assert!(self.ptr.get() == self);
+        }
+    }
+}
+
+impl Drop for Foo {
+    fn drop(&mut self) {
+        self.touch();
+    }
+}
+
+thread_local!(static FOO: Foo = Foo::default());
+
+fn main() {
+    thread::spawn(|| {
+        FOO.with(|foo| foo.touch());
+        FOO.with(|foo| foo.touch());
+    })
+    .join()
+    .unwrap();
+}