]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-14875.rs
Rollup merge of #97149 - ChrisDenton:win_async_pipes, r=m-ou-se
[rust.git] / src / test / ui / issues / issue-14875.rs
1 // run-pass
2 // needs-unwind
3 // ignore-wasm32-bare compiled with panic=abort by default
4
5 // Check that values are not leaked when a dtor panics (#14875)
6
7 use std::panic::{self, UnwindSafe};
8
9 struct SetInnerOnDrop<'a>(&'a mut bool);
10
11 impl<'a> UnwindSafe for SetInnerOnDrop<'a> {}
12
13 impl<'a> Drop for SetInnerOnDrop<'a> {
14     fn drop(&mut self) {
15         *self.0 = true;
16     }
17 }
18
19 struct PanicOnDrop;
20 impl Drop for PanicOnDrop {
21     fn drop(&mut self) {
22         panic!("test panic");
23     }
24 }
25
26 fn main() {
27     let mut set_on_drop = false;
28     {
29         let set_inner_on_drop = SetInnerOnDrop(&mut set_on_drop);
30         let _ = panic::catch_unwind(|| {
31             let _set_inner_on_drop = set_inner_on_drop;
32             let _panic_on_drop = PanicOnDrop;
33         });
34     }
35     assert!(set_on_drop);
36 }