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