about summary refs log tree commit diff
path: root/tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs')
-rw-r--r--tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs b/tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs
new file mode 100644
index 00000000000..dfc094abeb9
--- /dev/null
+++ b/tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs
@@ -0,0 +1,25 @@
+// This would previously leak the Box<Trait> because we wouldn't
+// schedule cleanups when auto borrowing trait objects.
+// This program should be valgrind clean.
+
+static mut DROP_RAN: bool = false;
+
+struct Foo;
+impl Drop for Foo {
+    fn drop(&mut self) {
+        unsafe { DROP_RAN = true; }
+    }
+}
+
+
+trait Trait { fn dummy(&self) { } }
+impl Trait for Foo {}
+
+pub fn main() {
+    {
+        let _x: &Trait = &*(Box::new(Foo) as Box<Trait>);
+    }
+    unsafe {
+        assert!(DROP_RAN);
+    }
+}