]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/unwind-resource.rs
Rollup merge of #98640 - cuviper:stable-rust-analyzer, r=Mark-Simulacrum
[rust.git] / src / test / ui / threads-sendsync / unwind-resource.rs
1 // run-pass
2 // needs-unwind
3
4 #![allow(non_camel_case_types)]
5 // ignore-emscripten no threads support
6
7 use std::sync::mpsc::{channel, Sender};
8 use std::thread;
9
10 struct complainer {
11     tx: Sender<bool>,
12 }
13
14 impl Drop for complainer {
15     fn drop(&mut self) {
16         println!("About to send!");
17         self.tx.send(true).unwrap();
18         println!("Sent!");
19     }
20 }
21
22 fn complainer(tx: Sender<bool>) -> complainer {
23     println!("Hello!");
24     complainer {
25         tx: tx
26     }
27 }
28
29 fn f(tx: Sender<bool>) {
30     let _tx = complainer(tx);
31     panic!();
32 }
33
34 pub fn main() {
35     let (tx, rx) = channel();
36     let t = thread::spawn(move|| f(tx.clone()));
37     println!("hiiiiiiiii");
38     assert!(rx.recv().unwrap());
39     drop(t.join());
40 }