]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-valgrind/down-with-thread-dtors.rs
Auto merge of #42896 - llogiq:clippy_compiletest, r=alexcrichton
[rust.git] / src / test / run-pass-valgrind / down-with-thread-dtors.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // no-prefer-dynamic
12 // ignore-emscripten
13
14 thread_local!(static FOO: Foo = Foo);
15 thread_local!(static BAR: Bar = Bar(1));
16 thread_local!(static BAZ: Baz = Baz);
17
18 static mut HIT: bool = false;
19
20 struct Foo;
21 struct Bar(i32);
22 struct Baz;
23
24 impl Drop for Foo {
25     fn drop(&mut self) {
26         BAR.with(|_| {});
27     }
28 }
29
30 impl Drop for Bar {
31     fn drop(&mut self) {
32         assert_eq!(self.0, 1);
33         self.0 = 2;
34         BAZ.with(|_| {});
35         assert_eq!(self.0, 2);
36     }
37 }
38
39 impl Drop for Baz {
40     fn drop(&mut self) {
41         unsafe { HIT = true; }
42     }
43 }
44
45 fn main() {
46     std::thread::spawn(|| {
47         FOO.with(|_| {});
48     }).join().unwrap();
49     assert!(unsafe { HIT });
50 }