]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-14875.rs
Require Drop impls to have the same constness on its bounds as the bounds on the...
[rust.git] / src / test / ui / issues / issue-14875.rs
1 // run-pass
2 // needs-unwind
3
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
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 }