]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
e74abb32 | 2 | // ignore-wasm32-bare compiled with panic=abort by default |
abe05a73 | 3 | |
9e0c209e SL |
4 | // Check that values are not leaked when a dtor panics (#14875) |
5 | ||
6 | use std::panic::{self, UnwindSafe}; | |
7 | ||
8 | struct SetInnerOnDrop<'a>(&'a mut bool); | |
9 | ||
10 | impl<'a> UnwindSafe for SetInnerOnDrop<'a> {} | |
11 | ||
12 | impl<'a> Drop for SetInnerOnDrop<'a> { | |
13 | fn drop(&mut self) { | |
14 | *self.0 = true; | |
15 | } | |
16 | } | |
17 | ||
18 | struct PanicOnDrop; | |
19 | impl Drop for PanicOnDrop { | |
20 | fn drop(&mut self) { | |
21 | panic!("test panic"); | |
22 | } | |
23 | } | |
24 | ||
9e0c209e SL |
25 | fn main() { |
26 | let mut set_on_drop = false; | |
27 | { | |
28 | let set_inner_on_drop = SetInnerOnDrop(&mut set_on_drop); | |
29 | let _ = panic::catch_unwind(|| { | |
30 | let _set_inner_on_drop = set_inner_on_drop; | |
31 | let _panic_on_drop = PanicOnDrop; | |
32 | }); | |
33 | } | |
34 | assert!(set_on_drop); | |
35 | } |