]> git.lizzy.rs Git - rust.git/blob - tests/ui/binding/order-drop-with-match.rs
Rollup merge of #106805 - madsravn:master, r=compiler-errors
[rust.git] / tests / ui / binding / order-drop-with-match.rs
1 // run-pass
2
3 // Test to make sure the destructors run in the right order.
4 // Each destructor sets it's tag in the corresponding entry
5 // in ORDER matching up to when it ran.
6 // Correct order is: matched, inner, outer
7
8
9 static mut ORDER: [usize; 3] = [0, 0, 0];
10 static mut INDEX: usize = 0;
11
12 struct A;
13 impl Drop for A {
14     fn drop(&mut self) {
15         unsafe {
16             ORDER[INDEX] = 1;
17             INDEX = INDEX + 1;
18         }
19     }
20 }
21
22 struct B;
23 impl Drop for B {
24     fn drop(&mut self) {
25         unsafe {
26             ORDER[INDEX] = 2;
27             INDEX = INDEX + 1;
28         }
29     }
30 }
31
32 struct C;
33 impl Drop for C {
34     fn drop(&mut self) {
35         unsafe {
36             ORDER[INDEX] = 3;
37             INDEX = INDEX + 1;
38         }
39     }
40 }
41
42 fn main() {
43     {
44         let matched = A;
45         let _outer = C;
46         {
47             match matched {
48                 _s => {}
49             }
50             let _inner = B;
51         }
52     }
53     unsafe {
54         let expected: &[_] = &[1, 2, 3];
55         assert_eq!(expected, ORDER);
56     }
57 }