about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-23 19:20:58 -0700
committerbors <bors@rust-lang.org>2013-09-23 19:20:58 -0700
commitd062de8aa48083439237cb338b38c25306bf6c94 (patch)
tree1ced905a1f2255a3f5207ed6c70fbe5e80cf4b41 /src/libstd
parent348d8446739f9633897a3d728d265ee6ac59c8fb (diff)
parent3b1d3e5bf8e2f288147fd879b37bc5e6f8c5528f (diff)
downloadrust-d062de8aa48083439237cb338b38c25306bf6c94.tar.gz
rust-d062de8aa48083439237cb338b38c25306bf6c94.zip
auto merge of #9310 : pcwalton/rust/at-fn, r=pcwalton
r? @brson
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io.rs32
-rw-r--r--src/libstd/reflect.rs8
-rw-r--r--src/libstd/routine.rs28
-rw-r--r--src/libstd/std.rs2
-rw-r--r--src/libstd/unstable/extfmt.rs22
-rw-r--r--src/libstd/unstable/finally.rs12
6 files changed, 72 insertions, 32 deletions
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 890a53690d9..ab8af22e116 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -1846,31 +1846,38 @@ pub mod fsync {
     pub struct Arg<t> {
         val: t,
         opt_level: Option<Level>,
-        fsync_fn: @fn(f: &t, Level) -> int,
+        fsync_fn: extern "Rust" fn(f: &t, Level) -> int,
     }
 
     // fsync file after executing blk
     // FIXME (#2004) find better way to create resources within lifetime of
     // outer res
-    pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
+    pub fn FILE_res_sync(file: &FILERes,
+                         opt_level: Option<Level>,
                          blk: &fn(v: Res<*libc::FILE>)) {
         blk(Res::new(Arg {
-            val: file.f, opt_level: opt_level,
-            fsync_fn: |file, l| fsync_fd(fileno(*file), l)
+            val: file.f,
+            opt_level: opt_level,
+            fsync_fn: fsync_FILE,
         }));
 
         fn fileno(stream: *libc::FILE) -> libc::c_int {
             #[fixed_stack_segment]; #[inline(never)];
             unsafe { libc::fileno(stream) }
         }
+
+        fn fsync_FILE(stream: &*libc::FILE, level: Level) -> int {
+            fsync_fd(fileno(*stream), level)
+        }
     }
 
     // fsync fd after executing blk
     pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
                        blk: &fn(v: Res<fd_t>)) {
         blk(Res::new(Arg {
-            val: fd.fd, opt_level: opt_level,
-            fsync_fn: |fd, l| fsync_fd(*fd, l)
+            val: fd.fd,
+            opt_level: opt_level,
+            fsync_fn: fsync_fd_helper,
         }));
     }
 
@@ -1880,6 +1887,10 @@ pub mod fsync {
         os::fsync_fd(fd, level) as int
     }
 
+    fn fsync_fd_helper(fd_ptr: &libc::c_int, level: Level) -> int {
+        fsync_fd(*fd_ptr, level)
+    }
+
     // Type of objects that may want to fsync
     pub trait FSyncable { fn fsync(&self, l: Level) -> int; }
 
@@ -1887,10 +1898,15 @@ pub mod fsync {
     pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>,
                     blk: &fn(v: Res<@FSyncable>)) {
         blk(Res::new(Arg {
-            val: o, opt_level: opt_level,
-            fsync_fn: |o, l| (*o).fsync(l)
+            val: o,
+            opt_level: opt_level,
+            fsync_fn: obj_fsync_fn,
         }));
     }
+
+    fn obj_fsync_fn(o: &@FSyncable, level: Level) -> int {
+        (*o).fsync(level)
+    }
 }
 
 #[cfg(test)]
diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs
index 91e3719e3d0..833a9f5ed82 100644
--- a/src/libstd/reflect.rs
+++ b/src/libstd/reflect.rs
@@ -485,9 +485,11 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
     }
 
     fn visit_closure_ptr(&mut self, ck: uint) -> bool {
-        self.align_to::<@fn()>();
-        if ! self.inner.visit_closure_ptr(ck) { return false; }
-        self.bump_past::<@fn()>();
+        self.align_to::<~fn()>();
+        if ! self.inner.visit_closure_ptr(ck) {
+            return false
+        }
+        self.bump_past::<~fn()>();
         true
     }
 }
diff --git a/src/libstd/routine.rs b/src/libstd/routine.rs
new file mode 100644
index 00000000000..e8a91b49c8e
--- /dev/null
+++ b/src/libstd/routine.rs
@@ -0,0 +1,28 @@
+// Copyright 2012 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.
+
+/*!
+ * Routines are like closures except that they own their arguments and can
+ * only run once.
+ */
+
+/// A routine that takes no arguments and returns nothing.
+pub trait Runnable {
+    /// The entry point for the routine.
+    fn run(~self);
+}
+
+/// A convenience routine that does nothing.
+pub struct NoOpRunnable;
+
+impl Runnable for NoOpRunnable {
+    fn run(~self) {}
+}
+
diff --git a/src/libstd/std.rs b/src/libstd/std.rs
index f7b55e977e0..5c1bac7418e 100644
--- a/src/libstd/std.rs
+++ b/src/libstd/std.rs
@@ -189,7 +189,7 @@ pub mod reflect;
 pub mod condition;
 pub mod logging;
 pub mod util;
-
+pub mod routine;
 
 /* Unsupported interfaces */
 
diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs
index f2cfd114349..4d53dd7d7bf 100644
--- a/src/libstd/unstable/extfmt.rs
+++ b/src/libstd/unstable/extfmt.rs
@@ -158,11 +158,14 @@ pub mod ct {
 
     // A fragment of the output sequence
     #[deriving(Eq)]
-    pub enum Piece { PieceString(~str), PieceConv(Conv), }
+    pub enum Piece {
+        PieceString(~str),
+        PieceConv(Conv),
+    }
 
-    pub type ErrorFn = @fn(&str) -> !;
+    pub type ErrorFn<'self> = &'self fn(&str) -> !;
 
-    pub fn parse_fmt_string(s: &str, err: ErrorFn) -> ~[Piece] {
+    pub fn parse_fmt_string<'a>(s: &str, err: ErrorFn<'a>) -> ~[Piece] {
         fn push_slice(ps: &mut ~[Piece], s: &str, from: uint, to: uint) {
             if to > from {
                 ps.push(PieceString(s.slice(from, to).to_owned()));
@@ -185,7 +188,10 @@ pub mod ct {
                     i += 1;
                 } else {
                     push_slice(&mut pieces, s, h, i - 1);
-                    let Parsed {val, next} = parse_conversion(s, i, lim, err);
+                    let Parsed {
+                        val,
+                        next
+                    } = parse_conversion(s, i, lim, |s| err(s));
                     pieces.push(val);
                     i = next;
                 }
@@ -224,8 +230,8 @@ pub mod ct {
         }
     }
 
-    pub fn parse_conversion(s: &str, i: uint, lim: uint, err: ErrorFn) ->
-        Parsed<Piece> {
+    pub fn parse_conversion<'a>(s: &str, i: uint, lim: uint, err: ErrorFn<'a>)
+                                -> Parsed<Piece> {
         let param = parse_parameter(s, i, lim);
         // avoid copying ~[Flag] by destructuring
         let Parsed {val: flags_val, next: flags_next} = parse_flags(s,
@@ -308,8 +314,8 @@ pub mod ct {
         }
     }
 
-    pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
-        Parsed<Ty> {
+    pub fn parse_type<'a>(s: &str, i: uint, lim: uint, err: ErrorFn<'a>)
+                          -> Parsed<Ty> {
         if i >= lim { err("missing type in conversion"); }
 
         // FIXME (#2249): Do we really want two signed types here?
diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs
index 6833ca6d7cf..ba5986aa4ab 100644
--- a/src/libstd/unstable/finally.rs
+++ b/src/libstd/unstable/finally.rs
@@ -55,7 +55,6 @@ impl<'self,T> Finally<T> for &'self fn() -> T {
 }
 
 finally_fn!(~fn() -> T)
-finally_fn!(@fn() -> T)
 finally_fn!(extern "Rust" fn() -> T)
 
 struct Finallyalizer<'self> {
@@ -119,14 +118,3 @@ fn test_owned() {
     spawn_with_finalizer(owned);
 }
 
-#[test]
-fn test_managed() {
-    let i = @mut 10;
-    let managed: @fn() -> int = || {
-        let r = *i;
-        *i += 10;
-        r
-    };
-    assert_eq!(do managed.finally {}, 10);
-    assert_eq!(*i, 20);
-}