]> git.lizzy.rs Git - rust.git/blob - src/test/ui/mir/mir_dynamic_drops_3.rs
Auto merge of #99292 - Aaron1011:stability-use-tree, r=cjgillot
[rust.git] / src / test / ui / mir / mir_dynamic_drops_3.rs
1 // run-fail
2 // needs-unwind
3 // error-pattern:unwind happens
4 // error-pattern:drop 3
5 // error-pattern:drop 2
6 // error-pattern:drop 1
7 // ignore-emscripten no processes
8
9 /// Structure which will not allow to be dropped twice.
10 struct Droppable<'a>(&'a mut bool, u32);
11 impl<'a> Drop for Droppable<'a> {
12     fn drop(&mut self) {
13         if *self.0 {
14             eprintln!("{} dropped twice", self.1);
15             ::std::process::exit(1);
16         }
17         eprintln!("drop {}", self.1);
18         *self.0 = true;
19     }
20 }
21
22 fn may_panic<'a>() -> Droppable<'a> {
23     panic!("unwind happens");
24 }
25
26 fn mir<'a>(d: Droppable<'a>) {
27     let (mut a, mut b) = (false, false);
28     let y = Droppable(&mut a, 2);
29     let x = [Droppable(&mut b, 1), y, d, may_panic()];
30 }
31
32 fn main() {
33     let mut c = false;
34     mir(Droppable(&mut c, 3));
35 }