]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/eprint-on-tls-drop.rs
Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup
[rust.git] / src / test / ui / threads-sendsync / eprint-on-tls-drop.rs
1 // run-pass
2 // ignore-emscripten no processes
3 // ignore-sgx no processes
4
5 use std::cell::RefCell;
6 use std::env;
7 use std::process::Command;
8
9 fn main() {
10     let name = "YOU_ARE_THE_TEST";
11     if env::var(name).is_ok() {
12         std::thread::spawn(|| {
13             TLS.with(|f| f.borrow().ensure());
14         })
15         .join()
16         .unwrap();
17     } else {
18         let me = env::current_exe().unwrap();
19         let output = Command::new(&me).env(name, "1").output().unwrap();
20         println!("{:?}", output);
21         assert!(output.status.success());
22         let stderr = String::from_utf8(output.stderr).unwrap();
23         assert!(stderr.contains("hello new\n"));
24         assert!(stderr.contains("hello drop\n"));
25     }
26 }
27
28 struct Stuff {
29     _x: usize,
30 }
31
32 impl Stuff {
33     fn new() -> Self {
34         eprintln!("hello new");
35         Self { _x: 0 }
36     }
37
38     fn ensure(&self) {}
39 }
40
41 impl Drop for Stuff {
42     fn drop(&mut self) {
43         eprintln!("hello drop");
44     }
45 }
46
47 thread_local! {
48     static TLS: RefCell<Stuff> = RefCell::new(Stuff::new());
49 }