]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-14875.rs
New upstream version 1.40.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-14875.rs
CommitLineData
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
6use std::panic::{self, UnwindSafe};
7
8struct SetInnerOnDrop<'a>(&'a mut bool);
9
10impl<'a> UnwindSafe for SetInnerOnDrop<'a> {}
11
12impl<'a> Drop for SetInnerOnDrop<'a> {
13 fn drop(&mut self) {
14 *self.0 = true;
15 }
16}
17
18struct PanicOnDrop;
19impl Drop for PanicOnDrop {
20 fn drop(&mut self) {
21 panic!("test panic");
22 }
23}
24
9e0c209e
SL
25fn 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}