]> git.lizzy.rs Git - rust.git/blob - tests/run-pass-valgrind/down-with-thread-dtors.rs
Rollup merge of #107777 - compiler-errors:derive_const-actually-derive-const, r=fee1...
[rust.git] / tests / run-pass-valgrind / down-with-thread-dtors.rs
1 // ignore-emscripten
2
3 thread_local!(static FOO: Foo = Foo);
4 thread_local!(static BAR: Bar = Bar(1));
5 thread_local!(static BAZ: Baz = Baz);
6
7 static mut HIT: bool = false;
8
9 struct Foo;
10 struct Bar(i32);
11 struct Baz;
12
13 impl Drop for Foo {
14     fn drop(&mut self) {
15         BAR.with(|_| {});
16     }
17 }
18
19 impl Drop for Bar {
20     fn drop(&mut self) {
21         assert_eq!(self.0, 1);
22         self.0 = 2;
23         BAZ.with(|_| {});
24         assert_eq!(self.0, 2);
25     }
26 }
27
28 impl Drop for Baz {
29     fn drop(&mut self) {
30         unsafe { HIT = true; }
31     }
32 }
33
34 fn main() {
35     std::thread::spawn(|| {
36         FOO.with(|_| {});
37     }).join().unwrap();
38     assert!(unsafe { HIT });
39 }