about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-03-01 23:30:49 +0000
committerbors <bors@rust-lang.org>2016-03-01 23:30:49 +0000
commit339a409bfdb6c1e9b280388b5d8d9e898217840f (patch)
treea578361877af6042eb3e4e9f86ea290b97b349b1 /src/test
parent84d8fec9b014975145eb0d9d6ec29216593e10f6 (diff)
parentd1a12392b2bcbb58538cc99a995e962d2f0cdf45 (diff)
Auto merge of #31430 - nagisa:mir-dyndrop, r=nikomatsakis
Zeroing on-drop seems to work fine. Still thinking about the best way to approach zeroing on-move.

(based on top of the other drop PR; only the last 2 commits are relevant)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-fail/mir_dynamic_drops_1.rs42
-rw-r--r--src/test/run-fail/mir_dynamic_drops_2.rs40
-rw-r--r--src/test/run-fail/mir_dynamic_drops_3.rs45
-rw-r--r--src/test/run-pass/mir_fat_ptr_drop.rs39
4 files changed, 166 insertions, 0 deletions
diff --git a/src/test/run-fail/mir_dynamic_drops_1.rs b/src/test/run-fail/mir_dynamic_drops_1.rs
new file mode 100644
index 00000000000..590b9fbe43c
--- /dev/null
+++ b/src/test/run-fail/mir_dynamic_drops_1.rs
@@ -0,0 +1,42 @@
+// Copyright 2016 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.
+#![feature(rustc_attrs)]
+// error-pattern:drop 1
+// error-pattern:drop 2
+use std::io::{self, Write};
+
+
+/// Structure which will not allow to be dropped twice.
+struct Droppable<'a>(&'a mut bool, u32);
+impl<'a> Drop for Droppable<'a> {
+    fn drop(&mut self) {
+        if *self.0 {
+            writeln!(io::stderr(), "{} dropped twice", self.1);
+            ::std::process::exit(1);
+        }
+        writeln!(io::stderr(), "drop {}", self.1);
+        *self.0 = true;
+    }
+}
+
+#[rustc_mir]
+fn mir(){
+    let (mut xv, mut yv) = (false, false);
+    let x = Droppable(&mut xv, 1);
+    let y = Droppable(&mut yv, 2);
+    let mut z = x;
+    let k = y;
+    z = k;
+}
+
+fn main() {
+    mir();
+    panic!();
+}
diff --git a/src/test/run-fail/mir_dynamic_drops_2.rs b/src/test/run-fail/mir_dynamic_drops_2.rs
new file mode 100644
index 00000000000..eafd3d351fb
--- /dev/null
+++ b/src/test/run-fail/mir_dynamic_drops_2.rs
@@ -0,0 +1,40 @@
+// Copyright 2016 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.
+#![feature(rustc_attrs)]
+// error-pattern:drop 1
+use std::io::{self, Write};
+
+
+/// Structure which will not allow to be dropped twice.
+struct Droppable<'a>(&'a mut bool, u32);
+impl<'a> Drop for Droppable<'a> {
+    fn drop(&mut self) {
+        if *self.0 {
+            writeln!(io::stderr(), "{} dropped twice", self.1);
+            ::std::process::exit(1);
+        }
+        writeln!(io::stderr(), "drop {}", self.1);
+        *self.0 = true;
+    }
+}
+
+#[rustc_mir]
+fn mir<'a>(d: Droppable<'a>){
+    loop {
+        let x = d;
+        break;
+    }
+}
+
+fn main() {
+    let mut xv = false;
+    mir(Droppable(&mut xv, 1));
+    panic!();
+}
diff --git a/src/test/run-fail/mir_dynamic_drops_3.rs b/src/test/run-fail/mir_dynamic_drops_3.rs
new file mode 100644
index 00000000000..730d9c8f226
--- /dev/null
+++ b/src/test/run-fail/mir_dynamic_drops_3.rs
@@ -0,0 +1,45 @@
+// Copyright 2016 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.
+#![feature(rustc_attrs)]
+// error-pattern:unwind happens
+// error-pattern:drop 3
+// error-pattern:drop 2
+// error-pattern:drop 1
+use std::io::{self, Write};
+
+
+/// Structure which will not allow to be dropped twice.
+struct Droppable<'a>(&'a mut bool, u32);
+impl<'a> Drop for Droppable<'a> {
+    fn drop(&mut self) {
+        if *self.0 {
+            writeln!(io::stderr(), "{} dropped twice", self.1);
+            ::std::process::exit(1);
+        }
+        writeln!(io::stderr(), "drop {}", self.1);
+        *self.0 = true;
+    }
+}
+
+fn may_panic<'a>() -> Droppable<'a> {
+    panic!("unwind happens");
+}
+
+#[rustc_mir]
+fn mir<'a>(d: Droppable<'a>){
+    let (mut a, mut b) = (false, false);
+    let y = Droppable(&mut a, 2);
+    let x = [Droppable(&mut b, 1), y, d, may_panic()];
+}
+
+fn main() {
+    let mut c = false;
+    mir(Droppable(&mut c, 3));
+}
diff --git a/src/test/run-pass/mir_fat_ptr_drop.rs b/src/test/run-pass/mir_fat_ptr_drop.rs
new file mode 100644
index 00000000000..3f79be04793
--- /dev/null
+++ b/src/test/run-pass/mir_fat_ptr_drop.rs
@@ -0,0 +1,39 @@
+// Copyright 2015 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 that ordinary fat pointer operations work.
+
+#![feature(braced_empty_structs)]
+#![feature(rustc_attrs)]
+
+use std::sync::atomic;
+use std::sync::atomic::Ordering::SeqCst;
+
+static COUNTER: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
+
+struct DropMe {
+}
+
+impl Drop for DropMe {
+    fn drop(&mut self) {
+        COUNTER.fetch_add(1, SeqCst);
+    }
+}
+
+#[rustc_mir]
+fn fat_ptr_move_then_drop(a: Box<[DropMe]>) {
+    let b = a;
+}
+
+fn main() {
+    let a: Box<[DropMe]> = Box::new([DropMe { }]);
+    fat_ptr_move_then_drop(a);
+    assert_eq!(COUNTER.load(SeqCst), 1);
+}