2014-07-04 19:55:51 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
|
|
|
// Test to make sure the destructors run in the right order.
|
|
|
|
// Each destructor sets it's tag in the corresponding entry
|
|
|
|
// in ORDER matching up to when it ran.
|
|
|
|
// Correct order is: matched, inner, outer
|
|
|
|
|
2014-12-19 20:20:51 -06:00
|
|
|
static mut ORDER: [uint; 3] = [0, 0, 0];
|
2014-07-04 19:55:51 -05:00
|
|
|
static mut INDEX: uint = 0;
|
|
|
|
|
|
|
|
struct A;
|
|
|
|
impl Drop for A {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
ORDER[INDEX] = 1;
|
|
|
|
INDEX = INDEX + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B;
|
|
|
|
impl Drop for B {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
ORDER[INDEX] = 2;
|
|
|
|
INDEX = INDEX + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct C;
|
|
|
|
impl Drop for C {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
ORDER[INDEX] = 3;
|
|
|
|
INDEX = INDEX + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
{
|
|
|
|
let matched = A;
|
|
|
|
let _outer = C;
|
|
|
|
{
|
|
|
|
match matched {
|
|
|
|
_s => {}
|
|
|
|
}
|
|
|
|
let _inner = B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsafe {
|
2014-08-06 04:59:40 -05:00
|
|
|
let expected: &[_] = &[1, 2, 3];
|
2015-02-01 20:53:25 -06:00
|
|
|
assert_eq!(expected, ORDER);
|
2014-07-04 19:55:51 -05:00
|
|
|
}
|
|
|
|
}
|