diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2025-05-29 02:47:23 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2025-05-29 02:47:23 +0200 |
| commit | 22c5e1d686967d8ef69fec69475f8bbe25b71b2f (patch) | |
| tree | e5798f7bdbfd5075485312a19028ebf10b86d475 | |
| parent | 9ffbc62cb60f2151a38b6c5e18c016e406d10a62 (diff) | |
| download | rust-22c5e1d686967d8ef69fec69475f8bbe25b71b2f.tar.gz rust-22c5e1d686967d8ef69fec69475f8bbe25b71b2f.zip | |
Add test
| -rw-r--r-- | tests/ui/threads-sendsync/tls-dont-move-after-init.rs | 39 |
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(); +} |
