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