]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/tls-try-with.rs
Rollup merge of #62837 - Kinrany:patch-1, r=GuillaumeGomez
[rust.git] / src / test / ui / threads-sendsync / tls-try-with.rs
1 // run-pass
2 #![allow(stable_features)]
3
4 // ignore-emscripten no threads support
5
6 #![feature(thread_local_try_with)]
7
8 use std::thread;
9
10 static mut DROP_RUN: bool = false;
11
12 struct Foo;
13
14 thread_local!(static FOO: Foo = Foo {});
15
16 impl Drop for Foo {
17     fn drop(&mut self) {
18         assert!(FOO.try_with(|_| panic!("`try_with` closure run")).is_err());
19         unsafe { DROP_RUN = true; }
20     }
21 }
22
23 fn main() {
24     thread::spawn(|| {
25         assert_eq!(FOO.try_with(|_| {
26             132
27         }).expect("`try_with` failed"), 132);
28     }).join().unwrap();
29     assert!(unsafe { DROP_RUN });
30 }