about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-04-12 21:00:57 -0700
committerbors <bors@rust-lang.org>2013-04-12 21:00:57 -0700
commit65ff441b3d25d83335dc46ed4ef86421fca29c8d (patch)
treed42a4367153491e650c76e0efb37ad60af684296
parenta9247e07acc5829473239393b8a9cd367b710585 (diff)
parent5f59012cce2675d805e5a6a3af75b76ee015af24 (diff)
downloadrust-65ff441b3d25d83335dc46ed4ef86421fca29c8d.tar.gz
rust-65ff441b3d25d83335dc46ed4ef86421fca29c8d.zip
auto merge of #5839 : bjz/rust/master, r=brson
r? @brson 
-rw-r--r--src/libcore/unstable/finally.rs43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/libcore/unstable/finally.rs b/src/libcore/unstable/finally.rs
index 4d2daa6f150..559287b5297 100644
--- a/src/libcore/unstable/finally.rs
+++ b/src/libcore/unstable/finally.rs
@@ -25,7 +25,7 @@ do || {
 
 use ops::Drop;
 
-#[cfg(test)] use task::failing;
+#[cfg(test)] use task::{failing, spawn};
 
 pub trait Finally<T> {
     fn finally(&self, dtor: &fn()) -> T;
@@ -41,6 +41,26 @@ impl<'self,T> Finally<T> for &'self fn() -> T {
     }
 }
 
+impl<T> Finally<T> for ~fn() -> T {
+    fn finally(&self, dtor: &fn()) -> T {
+        let _d = Finallyalizer {
+            dtor: dtor
+        };
+
+        (*self)()
+    }
+}
+
+impl<T> Finally<T> for @fn() -> T {
+    fn finally(&self, dtor: &fn()) -> T {
+        let _d = Finallyalizer {
+            dtor: dtor
+        };
+
+        (*self)()
+    }
+}
+
 struct Finallyalizer<'self> {
     dtor: &'self fn()
 }
@@ -96,3 +116,24 @@ fn test_compact() {
     do_some_fallible_work.finally(
         but_always_run_this_function);
 }
+
+#[test]
+fn test_owned() {
+    fn spawn_with_finalizer(f: ~fn()) {
+        do spawn { do f.finally { } }
+    }
+    let owned: ~fn() = || { };
+    spawn_with_finalizer(owned);
+}
+
+#[test]
+fn test_managed() {
+    let i = @mut 10;
+    let managed: @fn() -> int = || {
+        let r = *i;
+        *i += 10;
+        r
+    };
+    assert!(do managed.finally {} == 10);
+    assert!(*i == 20);
+}
\ No newline at end of file