We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9ffbc62 commit 22c5e1dCopy full SHA for 22c5e1d
tests/ui/threads-sendsync/tls-dont-move-after-init.rs
@@ -0,0 +1,39 @@
1
+//@ run-pass
2
+#![allow(stable_features)]
3
+//@ needs-threads
4
+#![feature(thread_local_try_with)]
5
+
6
+use std::cell::Cell;
7
+use std::thread;
8
9
+#[derive(Default)]
10
+struct Foo {
11
+ ptr: Cell<*const Foo>,
12
+}
13
14
+impl Foo {
15
+ fn touch(&self) {
16
+ if self.ptr.get().is_null() {
17
+ self.ptr.set(self);
18
+ } else {
19
+ assert!(self.ptr.get() == self);
20
+ }
21
22
23
24
+impl Drop for Foo {
25
+ fn drop(&mut self) {
26
+ self.touch();
27
28
29
30
+thread_local!(static FOO: Foo = Foo::default());
31
32
+fn main() {
33
+ thread::spawn(|| {
34
+ FOO.with(|foo| foo.touch());
35
36
+ })
37
+ .join()
38
+ .unwrap();
39
0 commit comments