]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/order-drop-with-match.rs
auto merge of #15421 : catharsis/rust/doc-ffi-minor-fixes, r=alexcrichton
[rust.git] / src / test / run-pass / order-drop-with-match.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // Test to make sure the destructors run in the right order.
13 // Each destructor sets it's tag in the corresponding entry
14 // in ORDER matching up to when it ran.
15 // Correct order is: matched, inner, outer
16
17 static mut ORDER: [uint, ..3] = [0, 0, 0];
18 static mut INDEX: uint = 0;
19
20 struct A;
21 impl Drop for A {
22     fn drop(&mut self) {
23         unsafe {
24             ORDER[INDEX] = 1;
25             INDEX = INDEX + 1;
26         }
27     }
28 }
29
30 struct B;
31 impl Drop for B {
32     fn drop(&mut self) {
33         unsafe {
34             ORDER[INDEX] = 2;
35             INDEX = INDEX + 1;
36         }
37     }
38 }
39
40 struct C;
41 impl Drop for C {
42     fn drop(&mut self) {
43         unsafe {
44             ORDER[INDEX] = 3;
45             INDEX = INDEX + 1;
46         }
47     }
48 }
49
50 fn main() {
51     {
52         let matched = A;
53         let _outer = C;
54         {
55             match matched {
56                 _s => {}
57             }
58             let _inner = B;
59         }
60     }
61     unsafe {
62         assert_eq!(&[1, 2, 3], ORDER.as_slice());
63     }
64 }