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