]> git.proxmox.com Git - rustc.git/blobdiff - src/test/run-pass/resource-in-struct.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / resource-in-struct.rs
index d74ec61d3c0740930d198113b62fe53fc09c283b..c1e1ff0658b6e718621f208bb775bb0198c318c6 100644 (file)
@@ -8,22 +8,25 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+
+#![feature(unsafe_destructor)]
+
 // Ensures that class dtors run if the object is inside an enum
 // variant
 
-type closable = @mut bool;
+use std::cell::Cell;
+
+type closable<'a> = &'a Cell<bool>;
 
-struct close_res {
-  i: closable,
+struct close_res<'a> {
+  i: closable<'a>,
 
 }
 
 #[unsafe_destructor]
-impl Drop for close_res {
-    fn finalize(&self) {
-        unsafe {
-            *(self.i) = false;
-        }
+impl<'a> Drop for close_res<'a> {
+    fn drop(&mut self) {
+        self.i.set(false);
     }
 }
 
@@ -35,11 +38,11 @@ fn close_res(i: closable) -> close_res {
 
 enum option<T> { none, some(T), }
 
-fn sink(res: option<close_res>) { }
+fn sink(_res: option<close_res>) { }
 
 pub fn main() {
-    let c = @mut true;
-    sink(none);
-    sink(some(close_res(c)));
-    assert!((!*c));
+    let c = &Cell::new(true);
+    sink(option::none);
+    sink(option::some(close_res(c)));
+    assert!(!c.get());
 }