2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2014-07-05 00:55:51 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
static mut ORDER: [usize; 3] = [0, 0, 0];
|
|
|
|
static mut INDEX: usize = 0;
|
2014-07-05 00:55:51 +00:00
|
|
|
|
|
|
|
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 09:59:40 +00:00
|
|
|
let expected: &[_] = &[1, 2, 3];
|
2015-02-02 02:53:25 +00:00
|
|
|
assert_eq!(expected, ORDER);
|
2014-07-05 00:55:51 +00:00
|
|
|
}
|
|
|
|
}
|