about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-05 11:11:47 +0000
committerbors <bors@rust-lang.org>2014-07-05 11:11:47 +0000
commit342321def69789fb45f73f61bf3ab646b01e4bca (patch)
tree2c6578aa3f16b9cef48f6076ccea6657f261d1fb /src/test
parente0d3cf6b2a1db489520712f7e0a47874176c35de (diff)
parent1af8663579c0e0eb08fda29df51d0eefb2e2b6de (diff)
downloadrust-342321def69789fb45f73f61bf3ab646b01e4bca.tar.gz
rust-342321def69789fb45f73f61bf3ab646b01e4bca.zip
auto merge of #15442 : luqmana/rust/odp, r=pnkfelix
Inadvertently changed the order in which destructors ran in certain cases with #15076.

Fixes #15438.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/order-drop-with-match.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/test/run-pass/order-drop-with-match.rs b/src/test/run-pass/order-drop-with-match.rs
new file mode 100644
index 00000000000..ed5cff36c8b
--- /dev/null
+++ b/src/test/run-pass/order-drop-with-match.rs
@@ -0,0 +1,64 @@
+// 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
+
+static mut ORDER: [uint, ..3] = [0, 0, 0];
+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 {
+        assert_eq!(&[1, 2, 3], ORDER.as_slice());
+    }
+}