diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index ddf7c934a49..c4641eff572 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -235,7 +235,7 @@ impl ToStrConsume for ~[Ascii] { impl IterBytes for Ascii { #[inline] - fn iter_bytes(&self, _lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool { + fn iter_bytes(&self, _lsb0: bool, f: |buf: &[u8]| -> bool) -> bool { f([self.to_byte()]) } } diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 90729966c18..a052ae87a41 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -43,7 +43,7 @@ pub fn capacity(v: @[T]) -> uint { * onto the vector being constructed. */ #[inline] -pub fn build(size: Option, builder: &fn(push: &fn(v: A))) -> @[A] { +pub fn build(size: Option, builder: |push: |v: A||) -> @[A] { let mut vec = @[]; unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); } builder(|x| unsafe { raw::push(&mut vec, x) }); @@ -68,7 +68,7 @@ pub fn append(lhs: @[T], rhs: &[T]) -> @[T] { /// Apply a function to each element of a vector and return the results -pub fn map(v: &[T], f: &fn(x: &T) -> U) -> @[U] { +pub fn map(v: &[T], f: |x: &T| -> U) -> @[U] { do build(Some(v.len())) |push| { for elem in v.iter() { push(f(elem)); @@ -82,7 +82,7 @@ pub fn map(v: &[T], f: &fn(x: &T) -> U) -> @[U] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value returned by the function `op`. */ -pub fn from_fn(n_elts: uint, op: &fn(uint) -> T) -> @[T] { +pub fn from_fn(n_elts: uint, op: |uint| -> T) -> @[T] { do build(Some(n_elts)) |push| { let mut i: uint = 0u; while i < n_elts { push(op(i)); i += 1u; } diff --git a/src/libstd/bool.rs b/src/libstd/bool.rs index 7f91c5e4f90..ce0a6696596 100644 --- a/src/libstd/bool.rs +++ b/src/libstd/bool.rs @@ -58,7 +58,7 @@ use num::FromPrimitive; /// } /// ``` #[inline] -pub fn all_values(blk: &fn(v: bool)) { +pub fn all_values(blk: |v: bool|) { blk(true); blk(false); } diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 4d5c68ab717..a9c4d2cacde 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -117,7 +117,7 @@ impl CString { /// # Failure /// /// Fails if the CString is null. - pub fn with_ref(&self, f: &fn(*libc::c_char) -> T) -> T { + pub fn with_ref(&self, f: |*libc::c_char| -> T) -> T { if self.buf.is_null() { fail!("CString is null!"); } f(self.buf) } @@ -127,7 +127,7 @@ impl CString { /// # Failure /// /// Fails if the CString is null. - pub fn with_mut_ref(&mut self, f: &fn(*mut libc::c_char) -> T) -> T { + pub fn with_mut_ref(&mut self, f: |*mut libc::c_char| -> T) -> T { if self.buf.is_null() { fail!("CString is null!"); } f(unsafe { cast::transmute_mut_unsafe(self.buf) }) } @@ -223,13 +223,13 @@ pub trait ToCStr { /// /// Raises the `null_byte` condition if the receiver has an interior null. #[inline] - fn with_c_str(&self, f: &fn(*libc::c_char) -> T) -> T { + fn with_c_str(&self, f: |*libc::c_char| -> T) -> T { self.to_c_str().with_ref(f) } /// Unsafe variant of `with_c_str()` that doesn't check for nulls. #[inline] - unsafe fn with_c_str_unchecked(&self, f: &fn(*libc::c_char) -> T) -> T { + unsafe fn with_c_str_unchecked(&self, f: |*libc::c_char| -> T) -> T { self.to_c_str_unchecked().with_ref(f) } } @@ -246,12 +246,12 @@ impl<'self> ToCStr for &'self str { } #[inline] - fn with_c_str(&self, f: &fn(*libc::c_char) -> T) -> T { + fn with_c_str(&self, f: |*libc::c_char| -> T) -> T { self.as_bytes().with_c_str(f) } #[inline] - unsafe fn with_c_str_unchecked(&self, f: &fn(*libc::c_char) -> T) -> T { + unsafe fn with_c_str_unchecked(&self, f: |*libc::c_char| -> T) -> T { self.as_bytes().with_c_str_unchecked(f) } } @@ -282,17 +282,17 @@ impl<'self> ToCStr for &'self [u8] { } } - fn with_c_str(&self, f: &fn(*libc::c_char) -> T) -> T { + fn with_c_str(&self, f: |*libc::c_char| -> T) -> T { unsafe { with_c_str(*self, true, f) } } - unsafe fn with_c_str_unchecked(&self, f: &fn(*libc::c_char) -> T) -> T { + unsafe fn with_c_str_unchecked(&self, f: |*libc::c_char| -> T) -> T { with_c_str(*self, false, f) } } // Unsafe function that handles possibly copying the &[u8] into a stack array. -unsafe fn with_c_str(v: &[u8], checked: bool, f: &fn(*libc::c_char) -> T) -> T { +unsafe fn with_c_str(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T { if v.len() < BUF_LEN { let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit(); vec::bytes::copy_memory(buf, v, v.len()); @@ -357,7 +357,7 @@ impl<'self> Iterator for CStringIterator<'self> { /// is found, and the number of strings found is returned. pub unsafe fn from_c_multistring(buf: *libc::c_char, count: Option, - f: &fn(&CString)) -> uint { + f: |&CString|) -> uint { let mut curr_ptr: uint = buf as uint; let mut ctr = 0; diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index a1459b780df..54849a44f6d 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -71,12 +71,12 @@ impl Cell { } /// Calls a closure with a reference to the value. - pub fn with_ref(&self, op: &fn(v: &T) -> R) -> R { + pub fn with_ref(&self, op: |v: &T| -> R) -> R { do self.with_mut_ref |ptr| { op(ptr) } } /// Calls a closure with a mutable reference to the value. - pub fn with_mut_ref(&self, op: &fn(v: &mut T) -> R) -> R { + pub fn with_mut_ref(&self, op: |v: &mut T| -> R) -> R { let mut v = Some(self.take()); do (|| { op(v.get_mut_ref()) diff --git a/src/libstd/char.rs b/src/libstd/char.rs index 6530755cb1d..c5a4dd1631d 100644 --- a/src/libstd/char.rs +++ b/src/libstd/char.rs @@ -241,7 +241,7 @@ static N_COUNT: uint = (V_COUNT * T_COUNT); static S_COUNT: uint = (L_COUNT * N_COUNT); // Decompose a precomposed Hangul syllable -fn decompose_hangul(s: char, f: &fn(char)) { +fn decompose_hangul(s: char, f: |char|) { let si = s as uint - S_BASE; let li = si / N_COUNT; @@ -259,7 +259,7 @@ fn decompose_hangul(s: char, f: &fn(char)) { } /// Returns the canonical decompostion of a character -pub fn decompose_canonical(c: char, f: &fn(char)) { +pub fn decompose_canonical(c: char, f: |char|) { if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) { decompose::canonical(c, f); } else { @@ -268,7 +268,7 @@ pub fn decompose_canonical(c: char, f: &fn(char)) { } /// Returns the compatibility decompostion of a character -pub fn decompose_compatible(c: char, f: &fn(char)) { +pub fn decompose_compatible(c: char, f: |char|) { if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) { decompose::compatibility(c, f); } else { @@ -285,7 +285,7 @@ pub fn decompose_compatible(c: char, f: &fn(char)) { /// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN` /// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN` /// -pub fn escape_unicode(c: char, f: &fn(char)) { +pub fn escape_unicode(c: char, f: |char|) { // avoid calling str::to_str_radix because we don't really need to allocate // here. f('\\'); @@ -316,7 +316,7 @@ pub fn escape_unicode(c: char, f: &fn(char)) { /// - Any other chars in the range [0x20,0x7e] are not escaped. /// - Any other chars are given hex unicode escapes; see `escape_unicode`. /// -pub fn escape_default(c: char, f: &fn(char)) { +pub fn escape_default(c: char, f: |char|) { match c { '\t' => { f('\\'); f('t'); } '\r' => { f('\\'); f('r'); } @@ -367,8 +367,8 @@ pub trait Char { fn is_digit_radix(&self, radix: uint) -> bool; fn to_digit(&self, radix: uint) -> Option; fn from_digit(num: uint, radix: uint) -> Option; - fn escape_unicode(&self, f: &fn(char)); - fn escape_default(&self, f: &fn(char)); + fn escape_unicode(&self, f: |char|); + fn escape_default(&self, f: |char|); fn len_utf8_bytes(&self) -> uint; /// Encodes this character as utf-8 into the provided byte-buffer. The @@ -403,9 +403,9 @@ impl Char for char { fn from_digit(num: uint, radix: uint) -> Option { from_digit(num, radix) } - fn escape_unicode(&self, f: &fn(char)) { escape_unicode(*self, f) } + fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) } - fn escape_default(&self, f: &fn(char)) { escape_default(*self, f) } + fn escape_default(&self, f: |char|) { escape_default(*self, f) } fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) } diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index 7bbc8bc32fa..a1f85097865 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -30,7 +30,8 @@ struct AnnihilateStats { } unsafe fn each_live_alloc(read_next_before: bool, - f: &fn(box: *mut raw::Box<()>, uniq: bool) -> bool) -> bool { + f: |box: *mut raw::Box<()>, uniq: bool| -> bool) + -> bool { //! Walks the internal list of allocations use managed; diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index cb9552b189c..56d5a859401 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -133,7 +133,7 @@ impl Condition { /// Performs the same functionality as `raise`, except that when no handler /// is found the `default` argument is called instead of failing the task. - pub fn raise_default(&self, t: T, default: &fn() -> U) -> U { + pub fn raise_default(&self, t: T, default: || -> U) -> U { match local_data::pop(self.key) { None => { debug!("Condition.raise: found no handler"); @@ -145,7 +145,7 @@ impl Condition { None => {} Some(hp) => local_data::set(self.key, hp) } - let handle : &fn(T) -> U = unsafe { + let handle : |T| -> U = unsafe { ::cast::transmute(handler.handle) }; let u = handle(t); diff --git a/src/libstd/either.rs b/src/libstd/either.rs index 262cdaed492..d2874a6f7f5 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -38,7 +38,7 @@ impl Either { /// `value` is `Right(R)` then `f_right` is applied to its contents, and the /// result is returned. #[inline] - pub fn either(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T { + pub fn either(&self, f_left: |&L| -> T, f_right: |&R| -> T) -> T { match *self { Left(ref l) => f_left(l), Right(ref r) => f_right(r) diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index a48b8578116..427690a4aa5 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -931,8 +931,10 @@ impl<'self> Formatter<'self> { } } - fn with_padding(&mut self, padding: uint, - default: parse::Alignment, f: &fn(&mut Formatter)) { + fn with_padding(&mut self, + padding: uint, + default: parse::Alignment, + f: |&mut Formatter|) { let align = match self.align { parse::AlignUnknown => default, parse::AlignLeft | parse::AlignRight => self.align diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs index c9a85e6d25e..f15abff8316 100644 --- a/src/libstd/hash.rs +++ b/src/libstd/hash.rs @@ -408,7 +408,7 @@ mod tests { // Hash just the bytes of the slice, without length prefix struct Bytes<'self>(&'self [u8]); impl<'self> IterBytes for Bytes<'self> { - fn iter_bytes(&self, _lsb0: bool, f: &fn(&[u8]) -> bool) -> bool { + fn iter_bytes(&self, _lsb0: bool, f: |&[u8]| -> bool) -> bool { f(**self) } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index edefd39ebb4..2d3e6431b0c 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -80,8 +80,7 @@ impl HashMap { } #[inline] - fn bucket_sequence(&self, hash: uint, - op: &fn(uint) -> bool) -> bool { + fn bucket_sequence(&self, hash: uint, op: |uint| -> bool) -> bool { let start_idx = self.to_bucket(hash); let len_buckets = self.buckets.len(); let mut idx = start_idx; @@ -360,8 +359,14 @@ impl HashMap { /// Modify and return the value corresponding to the key in the map, or /// insert and return a new value if it doesn't exist. - pub fn mangle<'a,A>(&'a mut self, k: K, a: A, not_found: &fn(&K, A) -> V, - found: &fn(&K, &mut V, A)) -> &'a mut V { + pub fn mangle<'a, + A>( + &'a mut self, + k: K, + a: A, + not_found: |&K, A| -> V, + found: |&K, &mut V, A|) + -> &'a mut V { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is @@ -395,7 +400,7 @@ impl HashMap { /// Return the value corresponding to the key in the map, or create, /// insert, and return a new value if it doesn't exist. - pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) + pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V) -> &'a mut V { self.mangle(k, (), |k,_a| f(k), |_k,_v,_a| ()) } @@ -403,8 +408,12 @@ impl HashMap { /// Insert a key-value pair into the map if the key is not already present. /// Otherwise, modify the existing value for the key. /// Returns the new or modified value for the key. - pub fn insert_or_update_with<'a>(&'a mut self, k: K, v: V, - f: &fn(&K, &mut V)) -> &'a mut V { + pub fn insert_or_update_with<'a>( + &'a mut self, + k: K, + v: V, + f: |&K, &mut V|) + -> &'a mut V { self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v)) } @@ -446,12 +455,12 @@ impl HashMap { } /// Visit all keys - pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool { + pub fn each_key(&self, blk: |k: &K| -> bool) -> bool { self.iter().advance(|(k, _)| blk(k)) } /// Visit all values - pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool { + pub fn each_value<'a>(&'a self, blk: |v: &'a V| -> bool) -> bool { self.iter().advance(|(_, v)| blk(v)) } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index ebda2618dcf..5eb2e72e96b 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -54,8 +54,7 @@ impl<'self, R: Reader> Iterator for ByteIterator { } } -pub fn u64_to_le_bytes(n: u64, size: uint, - f: &fn(v: &[u8]) -> T) -> T { +pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), @@ -88,8 +87,7 @@ pub fn u64_to_le_bytes(n: u64, size: uint, } } -pub fn u64_to_be_bytes(n: u64, size: uint, - f: &fn(v: &[u8]) -> T) -> T { +pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index cc3f8bacb24..930f58ef33f 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -75,7 +75,7 @@ pub struct File { priv last_nread: int, } -fn io_raise(f: &fn(io: &mut IoFactory) -> Result) -> Option { +fn io_raise(f: |io: &mut IoFactory| -> Result) -> Option { do with_local_io |io| { match f(io) { Ok(t) => Some(t), @@ -499,7 +499,7 @@ pub fn rmdir(path: &Path) { /// use std::io::fs; /// /// // one possible implementation of fs::walk_dir only visiting files -/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) { +/// fn visit_dirs(dir: &Path, cb: |&Path|) { /// if dir.is_dir() { /// let contents = fs::readdir(dir).unwrap(); /// for entry in contents.iter() { diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 4b9c5ca5d4a..decdfb60bfb 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -240,7 +240,7 @@ impl<'self> Buffer for BufReader<'self> { ///Calls a function with a MemWriter and returns ///the writer's stored vector. -pub fn with_mem_writer(writeFn:&fn(&mut MemWriter)) -> ~[u8] { +pub fn with_mem_writer(writeFn: |&mut MemWriter|) -> ~[u8] { let mut writer = MemWriter::new(); writeFn(&mut writer); writer.inner() diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c56189dbb2b..1d0fef48890 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -394,7 +394,7 @@ condition! { /// Helper for wrapper calls where you want to /// ignore any io_errors that might be raised -pub fn ignore_io_error(cb: &fn() -> T) -> T { +pub fn ignore_io_error(cb: || -> T) -> T { do io_error::cond.trap(|_| { // just swallow the error.. downstream users // who can make a decision based on a None result @@ -407,7 +407,7 @@ pub fn ignore_io_error(cb: &fn() -> T) -> T { /// Helper for catching an I/O error and wrapping it in a Result object. The /// return result will be the last I/O error that happened or the result of the /// closure if no error occurred. -pub fn result(cb: &fn() -> T) -> Result { +pub fn result(cb: || -> T) -> Result { let mut err = None; let ret = io_error::cond.trap(|e| { if err.is_none() { diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index b2cb8f735cf..abaeab609aa 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -33,7 +33,7 @@ use vec; #[cfg(windows)] use ptr; #[cfg(windows)] use str; -fn keep_going(data: &[u8], f: &fn(*u8, uint) -> i64) -> i64 { +fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 { #[cfg(windows)] static eintr: int = 0; // doesn't matter #[cfg(not(windows))] static eintr: int = libc::EINTR as int; diff --git a/src/libstd/io/native/process.rs b/src/libstd/io/native/process.rs index 71c6ce78a1e..6aa3ae65fc9 100644 --- a/src/libstd/io/native/process.rs +++ b/src/libstd/io/native/process.rs @@ -432,7 +432,7 @@ fn spawn_process_os(prog: &str, args: &[~str], } #[cfg(unix)] -fn with_argv(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T { +fn with_argv(prog: &str, args: &[~str], cb: |**libc::c_char| -> T) -> T { use vec; // We can't directly convert `str`s into `*char`s, as someone needs to hold @@ -460,7 +460,7 @@ fn with_argv(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T { } #[cfg(unix)] -fn with_envp(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T { +fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T { use vec; // On posixy systems we can pass a char** for envp, which is a @@ -490,7 +490,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T { } #[cfg(windows)] -fn with_envp(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T { +fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T { // On win32 we pass an "environment block" which is not a char**, but // rather a concatenation of null-terminated k=v\0 sequences, with a final // \0 to terminate. @@ -514,7 +514,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T { } } -fn with_dirp(d: Option<&Path>, cb: &fn(*libc::c_char) -> T) -> T { +fn with_dirp(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T { match d { Some(dir) => dir.with_c_str(|buf| cb(buf)), None => cb(ptr::null()) diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 07240a4a509..9c63108beef 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -81,7 +81,8 @@ impl<'self> Parser<'self> { } // Commit only if parser returns Some - fn read_atomically(&mut self, cb: &fn(&mut Parser) -> Option) -> Option { + fn read_atomically(&mut self, cb: |&mut Parser| -> Option) + -> Option { let pos = self.pos; let r = cb(self); if r.is_none() { @@ -91,14 +92,16 @@ impl<'self> Parser<'self> { } // Commit only if parser read till EOF - fn read_till_eof(&mut self, cb: &fn(&mut Parser) -> Option) -> Option { + fn read_till_eof(&mut self, cb: |&mut Parser| -> Option) + -> Option { do self.read_atomically |p| { cb(p).filtered(|_| p.is_eof()) } } // Return result of first successful parser - fn read_or(&mut self, parsers: &[&fn(&mut Parser) -> Option]) -> Option { + fn read_or(&mut self, parsers: &[|&mut Parser| -> Option]) + -> Option { for pf in parsers.iter() { match self.read_atomically(|p: &mut Parser| (*pf)(p)) { Some(r) => return Some(r), @@ -109,12 +112,14 @@ impl<'self> Parser<'self> { } // Apply 3 parsers sequentially - fn read_seq_3(&mut self, - pa: &fn(&mut Parser) -> Option, - pb: &fn(&mut Parser) -> Option, - pc: &fn(&mut Parser) -> Option - ) -> Option<(A, B, C)> - { + fn read_seq_3( + &mut self, + pa: |&mut Parser| -> Option, + pb: |&mut Parser| -> Option, + pc: |&mut Parser| -> Option) + -> Option<(A, B, C)> { do self.read_atomically |p| { let a = pa(p); let b = if a.is_some() { pb(p) } else { None }; diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 1a2245ac442..b8cdbfc25cb 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -74,7 +74,9 @@ pub struct UdpStream { } impl UdpStream { - pub fn as_socket(&mut self, f: &fn(&mut UdpSocket) -> T) -> T { f(&mut self.socket) } + pub fn as_socket(&mut self, f: |&mut UdpSocket| -> T) -> T { + f(&mut self.socket) + } pub fn disconnect(self) -> UdpSocket { self.socket } } diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 49cac428cb2..1362d702f1c 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -69,7 +69,7 @@ enum StdSource { File(~RtioFileStream), } -fn src(fd: libc::c_int, readable: bool, f: &fn(StdSource) -> T) -> T { +fn src(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { do with_local_io |io| { let fd = unsafe { libc::dup(fd) }; match io.tty_open(fd, readable) { @@ -121,7 +121,7 @@ pub fn stderr() -> StdWriter { // // io1 aliases io2 // } // } -fn with_task_stdout(f: &fn(&mut Writer)) { +fn with_task_stdout(f: |&mut Writer|) { use rt::local::Local; use rt::task::Task; diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index 3897f519e90..f736b10cc4f 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -433,7 +433,7 @@ pub trait Iterator { /// range(0, 5).advance(|x| {print!("{} ", x); true}); /// ``` #[inline] - fn advance(&mut self, f: &fn(A) -> bool) -> bool { + fn advance(&mut self, f: |A| -> bool) -> bool { loop { match self.next() { Some(x) => { @@ -522,7 +522,7 @@ pub trait Iterator { /// assert!(a.iter().fold(0, |a, &b| a + b) == 15); /// ``` #[inline] - fn fold(&mut self, init: B, f: &fn(B, A) -> B) -> B { + fn fold(&mut self, init: B, f: |B, A| -> B) -> B { let mut accum = init; loop { match self.next() { @@ -558,7 +558,7 @@ pub trait Iterator { /// assert!(!a.iter().all(|&x| *x > 2)); /// ``` #[inline] - fn all(&mut self, f: &fn(A) -> bool) -> bool { + fn all(&mut self, f: |A| -> bool) -> bool { for x in *self { if !f(x) { return false; } } true } @@ -575,14 +575,14 @@ pub trait Iterator { /// assert!(!it.any(|&x| *x == 3)); /// ``` #[inline] - fn any(&mut self, f: &fn(A) -> bool) -> bool { + fn any(&mut self, f: |A| -> bool) -> bool { for x in *self { if f(x) { return true; } } false } /// Return the first element satisfying the specified predicate #[inline] - fn find(&mut self, predicate: &fn(&A) -> bool) -> Option { + fn find(&mut self, predicate: |&A| -> bool) -> Option { for x in *self { if predicate(&x) { return Some(x) } } @@ -591,7 +591,7 @@ pub trait Iterator { /// Return the index of the first element satisfying the specified predicate #[inline] - fn position(&mut self, predicate: &fn(A) -> bool) -> Option { + fn position(&mut self, predicate: |A| -> bool) -> Option { let mut i = 0; for x in *self { if predicate(x) { @@ -604,7 +604,7 @@ pub trait Iterator { /// Count the number of elements satisfying the specified predicate #[inline] - fn count(&mut self, predicate: &fn(A) -> bool) -> uint { + fn count(&mut self, predicate: |A| -> bool) -> uint { let mut i = 0; for x in *self { if predicate(x) { i += 1 } @@ -622,7 +622,7 @@ pub trait Iterator { /// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); /// ``` #[inline] - fn max_by(&mut self, f: &fn(&A) -> B) -> Option { + fn max_by(&mut self, f: |&A| -> B) -> Option { self.fold(None, |max: Option<(A, B)>, x| { let x_val = f(&x); match max { @@ -646,7 +646,7 @@ pub trait Iterator { /// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); /// ``` #[inline] - fn min_by(&mut self, f: &fn(&A) -> B) -> Option { + fn min_by(&mut self, f: |&A| -> B) -> Option { self.fold(None, |min: Option<(A, B)>, x| { let x_val = f(&x); match min { @@ -729,7 +729,7 @@ pub trait ExactSize : DoubleEndedIterator { /// /// If no element matches, None is returned. #[inline] - fn rposition(&mut self, predicate: &fn(A) -> bool) -> Option { + fn rposition(&mut self, predicate: |A| -> bool) -> Option { let (lower, upper) = self.size_hint(); assert!(upper == Some(lower)); let mut i = lower; diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 684fb9c76d9..083de15008a 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -177,7 +177,7 @@ pub fn pop(key: Key) -> Option { /// /// It is considered a runtime error to attempt to get a value which is already /// on loan via the `get_mut` method provided. -pub fn get(key: Key, f: &fn(Option<&T>) -> U) -> U { +pub fn get(key: Key, f: |Option<&T>| -> U) -> U { get_with(key, ImmLoan, f) } @@ -188,7 +188,7 @@ pub fn get(key: Key, f: &fn(Option<&T>) -> U) -> U { /// It is considered a runtime error to attempt to get a value which is already /// on loan via this or the `get` methods. This is similar to how it's a runtime /// error to take two mutable loans on an `@mut` box. -pub fn get_mut(key: Key, f: &fn(Option<&mut T>) -> U) -> U { +pub fn get_mut(key: Key, f: |Option<&mut T>| -> U) -> U { do get_with(key, MutLoan) |x| { match x { None => f(None), @@ -202,9 +202,12 @@ pub fn get_mut(key: Key, f: &fn(Option<&mut T>) -> U) -> U { } } -fn get_with(key: Key, - state: LoanState, - f: &fn(Option<&T>) -> U) -> U { +fn get_with( + key: Key, + state: LoanState, + f: |Option<&T>| -> U) + -> U { // This function must be extremely careful. Because TLS can store owned // values, and we must have some form of `get` function other than `pop`, // this function has to give a `&` reference back to the caller. @@ -335,7 +338,7 @@ pub fn set(key: Key, data: T) { /// /// This function will have the same runtime errors as generated from `pop` and /// `set` (the key must not currently be on loan -pub fn modify(key: Key, f: &fn(Option) -> Option) { +pub fn modify(key: Key, f: |Option| -> Option) { match f(pop(key)) { Some(next) => { set(key, next); } None => {} diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index ba1a7a4f912..9141e87bd72 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -415,7 +415,7 @@ impl FromStrRadix for $T { /// Convert to a string as a byte slice in a given base. #[inline] -pub fn to_str_bytes(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U { +pub fn to_str_bytes(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { // The radix can be as low as 2, so we need at least 64 characters for a // base 2 number, and then we need another for a possible '-' character. let mut buf = [0u8, ..65]; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 873d66d401e..aeda3fa1cd1 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -108,7 +108,7 @@ pub trait Unsigned: Num {} /// ``` /// pub trait Times { - fn times(&self, it: &fn()); + fn times(&self, it: ||); } pub trait Integer: Num diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index d17c947ab56..5d713f1a622 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -132,9 +132,19 @@ static NAN_BUF: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8]; * # Failure * - Fails if `radix` < 2 or `radix` > 36. */ -pub fn int_to_str_bytes_common+Neg+Rem+Mul>( - num: T, radix: uint, sign: SignFormat, f: &fn(u8)) { +pub fn int_to_str_bytes_common + +Neg + +Rem + +Mul>( + num: T, + radix: uint, + sign: SignFormat, + f: |u8|) { assert!(2 <= radix && radix <= 36); let _0: T = Zero::zero(); diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 2ecbb79407e..1cc0c191501 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -85,7 +85,7 @@ impl num::Times for uint { /// use with integer literals of inferred integer-type as /// the self-value (eg. `do 100.times { ... }`). /// - fn times(&self, it: &fn()) { + fn times(&self, it: ||) { let mut i = *self; while i > 0 { it(); diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 2974b402d4a..49f270369f7 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -266,7 +266,7 @@ impl FromStrRadix for $T { /// Convert to a string as a byte slice in a given base. #[inline] -pub fn to_str_bytes(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U { +pub fn to_str_bytes(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { // The radix can be as low as 2, so we need at least 64 characters for a // base 2 number. let mut buf = [0u8, ..64]; diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 0d9dc18726f..c5a10c75640 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -147,7 +147,7 @@ impl Option { /// Returns the contained value or computes it from a closure #[inline] - pub fn unwrap_or_else(self, f: &fn() -> T) -> T { + pub fn unwrap_or_else(self, f: || -> T) -> T { match self { Some(x) => x, None => f() @@ -160,19 +160,19 @@ impl Option { /// Maps an `Option` to `Option` by applying a function to a contained value. #[inline] - pub fn map(self, f: &fn(T) -> U) -> Option { + pub fn map(self, f: |T| -> U) -> Option { match self { Some(x) => Some(f(x)), None => None } } /// Applies a function to the contained value or returns a default. #[inline] - pub fn map_default(self, def: U, f: &fn(T) -> U) -> U { + pub fn map_default(self, def: U, f: |T| -> U) -> U { match self { None => def, Some(t) => f(t) } } /// Apply a function to the contained value or do nothing. /// Returns true if the contained value was mutated. - pub fn mutate(&mut self, f: &fn(T) -> T) -> bool { + pub fn mutate(&mut self, f: |T| -> T) -> bool { if self.is_some() { *self = Some(f(self.take_unwrap())); true @@ -181,7 +181,7 @@ impl Option { /// Apply a function to the contained value or set it to a default. /// Returns true if the contained value was mutated, or false if set to the default. - pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool { + pub fn mutate_default(&mut self, def: T, f: |T| -> T) -> bool { if self.is_some() { *self = Some(f(self.take_unwrap())); true @@ -235,7 +235,7 @@ impl Option { /// Returns `None` if the option is `None`, otherwise calls `f` with the /// wrapped value and returns the result. #[inline] - pub fn and_then(self, f: &fn(T) -> Option) -> Option { + pub fn and_then(self, f: |T| -> Option) -> Option { match self { Some(x) => f(x), None => None, @@ -254,7 +254,7 @@ impl Option { /// Returns the option if it contains a value, otherwise calls `f` and /// returns the result. #[inline] - pub fn or_else(self, f: &fn() -> Option) -> Option { + pub fn or_else(self, f: || -> Option) -> Option { match self { Some(_) => self, None => f(), @@ -273,7 +273,7 @@ impl Option { /// Filters an optional value using a given function. #[inline(always)] - pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option { + pub fn filtered(self, f: |t: &T| -> bool) -> Option { match self { Some(x) => if(f(&x)) {Some(x)} else {None}, None => None @@ -282,7 +282,7 @@ impl Option { /// Applies a function zero or more times until the result is `None`. #[inline] - pub fn while_some(self, blk: &fn(v: T) -> Option) { + pub fn while_some(self, blk: |v: T| -> Option) { let mut opt = self; while opt.is_some() { opt = blk(opt.unwrap()); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3ea6e18f942..3692bc303fb 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -94,7 +94,7 @@ pub mod win32 { use os::TMPBUF_SZ; use libc::types::os::arch::extra::DWORD; - pub fn fill_utf16_buf_and_decode(f: &fn(*mut u16, DWORD) -> DWORD) + pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option<~str> { unsafe { @@ -125,7 +125,7 @@ pub mod win32 { } } - pub fn as_utf16_p(s: &str, f: &fn(*u16) -> T) -> T { + pub fn as_utf16_p(s: &str, f: |*u16| -> T) -> T { let mut t = s.to_utf16(); // Null terminate before passing on. t.push(0u16); @@ -137,7 +137,7 @@ pub mod win32 { Accessing environment variables is not generally threadsafe. Serialize access through a global lock. */ -fn with_env_lock(f: &fn() -> T) -> T { +fn with_env_lock(f: || -> T) -> T { use unstable::mutex::{Mutex, MUTEX_INIT}; use unstable::finally::Finally; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 18f137e8b0e..6f152fa2a41 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -559,7 +559,7 @@ impl<'self, P: GenericPath> Display<'self, P> { /// If the path is not UTF-8, invalid sequences will be replaced with the /// unicode replacement char. This involves allocation. #[inline] - pub fn with_str(&self, f: &fn(&str) -> T) -> T { + pub fn with_str(&self, f: |&str| -> T) -> T { let opt = if self.filename { self.path.filename_str() } else { self.path.as_str() }; match opt { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f14f100de73..86f1e7f6e86 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -87,7 +87,7 @@ impl ToCStr for Path { impl IterBytes for Path { #[inline] - fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool { + fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool { self.repr.iter_bytes(lsb0, f) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 8483b504c01..d5bc6b85424 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -112,7 +112,7 @@ impl ToCStr for Path { impl IterBytes for Path { #[inline] - fn iter_bytes(&self, lsb0: bool, f: &fn(&[u8]) -> bool) -> bool { + fn iter_bytes(&self, lsb0: bool, f: |&[u8]| -> bool) -> bool { self.repr.iter_bytes(lsb0, f) } } @@ -970,7 +970,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { } return None; - fn parse_two_comps<'a>(mut path: &'a str, f: &fn(char)->bool) -> Option<(uint, uint)> { + fn parse_two_comps<'a>(mut path: &'a str, f: |char| -> bool) + -> Option<(uint, uint)> { let idx_a = match path.find(|x| f(x)) { None => return None, Some(x) => x diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 29ae88272a4..887f7f2e9a6 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -56,7 +56,7 @@ impl Clone for *mut T { /// Return the first offset `i` such that `f(buf[i]) == true`. #[inline] -pub unsafe fn position(buf: *T, f: &fn(&T) -> bool) -> uint { +pub unsafe fn position(buf: *T, f: |&T| -> bool) -> uint { let mut i = 0; loop { if f(&(*offset(buf, i as int))) { return i; } @@ -195,7 +195,7 @@ pub fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { SAFETY NOTE: Pointer-arithmetic. Dragons be here. */ -pub unsafe fn array_each_with_len(arr: **T, len: uint, cb: &fn(*T)) { +pub unsafe fn array_each_with_len(arr: **T, len: uint, cb: |*T|) { debug!("array_each_with_len: before iterate"); if (arr as uint == 0) { fail!("ptr::array_each_with_len failure: arr input is null pointer"); @@ -217,7 +217,7 @@ pub unsafe fn array_each_with_len(arr: **T, len: uint, cb: &fn(*T)) { pointer array. Barely less-dodgy Pointer Arithmetic. Dragons be here. */ -pub unsafe fn array_each(arr: **T, cb: &fn(*T)) { +pub unsafe fn array_each(arr: **T, cb: |*T|) { if (arr as uint == 0) { fail!("ptr::array_each_with_len failure: arr input is null pointer"); } diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index cc2f739ce98..9e83afa819c 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -203,7 +203,7 @@ impl RcMut { impl RcMut { /// Fails if there is already a mutable borrow of the box #[inline] - pub fn with_borrow(&self, f: &fn(&T) -> U) -> U { + pub fn with_borrow(&self, f: |&T| -> U) -> U { unsafe { assert!((*self.ptr).borrow != Mutable); let previous = (*self.ptr).borrow; @@ -216,7 +216,7 @@ impl RcMut { /// Fails if there is already a mutable or immutable borrow of the box #[inline] - pub fn with_mut_borrow(&self, f: &fn(&mut T) -> U) -> U { + pub fn with_mut_borrow(&self, f: |&mut T| -> U) -> U { unsafe { assert_eq!((*self.ptr).borrow, Nothing); (*self.ptr).borrow = Mutable; diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index 9769739b966..d0a69649176 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -28,7 +28,7 @@ use unstable::raw; * then build a MovePtrAdaptor wrapped around your struct. */ pub trait MovePtr { - fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void); + fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void); fn push_ptr(&mut self); fn pop_ptr(&mut self); } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 3f8da64b3d6..33e80d7fcae 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -116,7 +116,7 @@ pub fn ReprVisitor<'a>(ptr: *c_void, impl<'self> MovePtr for ReprVisitor<'self> { #[inline] - fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void) { + fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void) { self.ptr = adjustment(self.ptr); } fn push_ptr(&mut self) { @@ -131,7 +131,7 @@ impl<'self> ReprVisitor<'self> { // Various helpers for the TyVisitor impl #[inline] - pub fn get(&mut self, f: &fn(&mut ReprVisitor, &T)) -> bool { + pub fn get(&mut self, f: |&mut ReprVisitor, &T|) -> bool { unsafe { f(self, transmute::<*c_void,&T>(self.ptr)); } diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 03860c8ab22..97daf8d7e60 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -143,7 +143,7 @@ impl Result { /// parse_bytes(buf) /// } #[inline] - pub fn map(self, op: &fn(T) -> U) -> Result { + pub fn map(self, op: |T| -> U) -> Result { match self { Ok(t) => Ok(op(t)), Err(e) => Err(e) @@ -156,7 +156,7 @@ impl Result { /// This function can be used to pass through a successful result while handling /// an error. #[inline] - pub fn map_err(self, op: &fn(E) -> F) -> Result { + pub fn map_err(self, op: |E| -> F) -> Result { match self { Ok(t) => Ok(t), Err(e) => Err(op(e)) @@ -208,7 +208,7 @@ impl Result { /// /// This function can be used for control flow based on result values #[inline] - pub fn and_then(self, op: &fn(T) -> Result) -> Result { + pub fn and_then(self, op: |T| -> Result) -> Result { match self { Ok(t) => op(t), Err(e) => Err(e), @@ -228,7 +228,7 @@ impl Result { /// /// This function can be used for control flow based on result values #[inline] - pub fn or_else(self, op: &fn(E) -> Result) -> Result { + pub fn or_else(self, op: |E| -> Result) -> Result { match self { Ok(t) => Ok(t), Err(e) => op(e), @@ -378,12 +378,14 @@ pub fn collect>>(mut iterator: Iter) /// If an `Err` is encountered, it is immediately returned. /// Otherwise, the folded value is returned. #[inline] -pub fn fold>>( mut iterator: Iter, mut init: V, - f: &fn(V, T) -> V) - -> Result { + f: |V, T| -> V) + -> Result { for t in iterator { match t { Ok(v) => init = f(init, v), @@ -399,9 +401,7 @@ pub fn fold>>( - iterator: Iter) - -> Result<(), E> { +pub fn fold_>>(iterator: Iter) -> Result<(),E> { fold(iterator, (), |_, _| ()) } diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 0d32d2d7dba..a173be64356 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -107,9 +107,8 @@ mod imp { }) } - fn with_lock(f: &fn() -> T) -> T { + fn with_lock(f: || -> T) -> T { static mut lock: Mutex = MUTEX_INIT; - do (|| { unsafe { lock.lock(); diff --git a/src/libstd/rt/basic.rs b/src/libstd/rt/basic.rs index e8f6c4055a0..2c1c5d84be1 100644 --- a/src/libstd/rt/basic.rs +++ b/src/libstd/rt/basic.rs @@ -170,7 +170,7 @@ impl EventLoop for BasicLoop { ~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback } - fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) { + fn io<'a>(&'a mut self, f: |&'a mut IoFactory|) { f(self.io) } } diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index bd528cbe61f..d1f69ada301 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -40,7 +40,7 @@ fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> { } } -fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) { +fn swap_task_borrow_list(f: |~[BorrowRecord]| -> ~[BorrowRecord]) { let borrows = match try_take_task_borrow_list() { Some(l) => l, None => ~[] diff --git a/src/libstd/rt/crate_map.rs b/src/libstd/rt/crate_map.rs index 8decaea1f47..987b32c0846 100644 --- a/src/libstd/rt/crate_map.rs +++ b/src/libstd/rt/crate_map.rs @@ -79,8 +79,10 @@ fn version(crate_map: &CrateMap) -> i32 { } } -fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry), - visited: &mut HashSet<*CrateMap<'a>>) { +fn do_iter_crate_map<'a>( + crate_map: &'a CrateMap<'a>, + f: |&ModEntry|, + visited: &mut HashSet<*CrateMap<'a>>) { if visited.insert(crate_map as *CrateMap) { match version(crate_map) { 2 => { @@ -98,7 +100,7 @@ fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry), } /// Iterates recursively over `crate_map` and all child crate maps -pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry)) { +pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: |&ModEntry|) { // XXX: use random numbers as keys from the OS-level RNG when there is a nice // way to do this let mut v: HashSet<*CrateMap<'a>> = HashSet::with_capacity_and_keys(0, 0, 32); diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index f7abc33ce14..fa4746a6bb7 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -369,7 +369,7 @@ impl BlockedTask { // So that KillHandle can be hashed in the taskgroup bookkeeping code. impl IterBytes for KillHandle { - fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool { + fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool { self.data.iter_bytes(lsb0, f) } } @@ -525,9 +525,8 @@ impl KillHandle { // NB: Takes a pthread mutex -- 'blk' not allowed to reschedule. #[inline] fn add_lazy_tombstone(parent: &mut KillHandle, - blk: &fn(Option bool>) - -> proc() -> bool) { - + blk: |Option bool>| -> proc() -> bool) + { let inner: &mut KillHandleInner = unsafe { &mut *parent.get() }; unsafe { do inner.graveyard_lock.lock { diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 1ddc2f86f4b..d47dae96283 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -18,7 +18,7 @@ pub trait Local { fn put(value: ~Self); fn take() -> ~Self; fn exists(unused_value: Option) -> bool; - fn borrow(f: &fn(&mut Self) -> T) -> T; + fn borrow(f: |&mut Self| -> T) -> T; unsafe fn unsafe_take() -> ~Self; unsafe fn unsafe_borrow() -> *mut Self; unsafe fn try_unsafe_borrow() -> Option<*mut Self>; @@ -30,7 +30,7 @@ impl Local for Task { #[inline] fn take() -> ~Task { unsafe { local_ptr::take() } } fn exists(_: Option) -> bool { local_ptr::exists() } - fn borrow(f: &fn(&mut Task) -> T) -> T { + fn borrow(f: |&mut Task| -> T) -> T { let mut res: Option = None; let res_ptr: *mut Option = &mut res; unsafe { @@ -78,7 +78,7 @@ impl Local for Scheduler { } } } - fn borrow(f: &fn(&mut Scheduler) -> T) -> T { + fn borrow(f: |&mut Scheduler| -> T) -> T { do Local::borrow |task: &mut Task| { match task.sched { Some(~ref mut task) => { diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index d5d1931a217..862ecd6499a 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -103,7 +103,7 @@ pub fn exists() -> bool { /// # Safety note /// /// Does not validate the pointer type. -pub unsafe fn borrow(f: &fn(&mut T)) { +pub unsafe fn borrow(f: |&mut T|) { let mut value = take(); // XXX: Need a different abstraction from 'finally' here to avoid unsafety diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index 775f9d6c3be..f83932f9ffa 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -36,7 +36,7 @@ pub trait EventLoop { /// The asynchronous I/O services. Not all event loops may provide one // FIXME(#9382) this is an awful interface - fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)); + fn io<'a>(&'a mut self, f: |&'a mut IoFactory|); } pub trait RemoteCallback { @@ -75,7 +75,7 @@ pub enum CloseBehavior { CloseAsynchronously, } -pub fn with_local_io(f: &fn(&mut IoFactory) -> Option) -> Option { +pub fn with_local_io(f: |&mut IoFactory| -> Option) -> Option { use rt::sched::Scheduler; use rt::local::Local; use io::native; diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 00895289b6a..e317b76b24d 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -556,7 +556,7 @@ impl Scheduler { pub fn change_task_context(mut ~self, next_task: ~Task, - f: &fn(&mut Scheduler, ~Task)) { + f: |&mut Scheduler, ~Task|) { // The current task is grabbed from TLS, not taken as an input. // Doing an unsafe_take to avoid writing back a null pointer - // We're going to call `put` later to do that. @@ -568,8 +568,8 @@ impl Scheduler { // These transmutes do something fishy with a closure. let f_fake_region = unsafe { - transmute::<&fn(&mut Scheduler, ~Task), - &fn(&mut Scheduler, ~Task)>(f) + transmute::<|&mut Scheduler, ~Task|, + |&mut Scheduler, ~Task|>(f) }; let f_opaque = ClosureConverter::from_fn(f_fake_region); @@ -678,7 +678,7 @@ impl Scheduler { /// in order to prevent that fn from performing further scheduling operations. /// Doing further scheduling could easily result in infinite recursion. pub fn deschedule_running_task_and_then(mut ~self, - f: &fn(&mut Scheduler, BlockedTask)) { + f: |&mut Scheduler, BlockedTask|) { // Trickier - we need to get the scheduler task out of self // and use it as the destination. let stask = self.sched_task.take_unwrap(); @@ -687,7 +687,7 @@ impl Scheduler { } pub fn switch_running_tasks_and_then(~self, next_task: ~Task, - f: &fn(&mut Scheduler, BlockedTask)) { + f: |&mut Scheduler, BlockedTask|) { // This is where we convert the BlockedTask-taking closure into one // that takes just a Task, and is aware of the block-or-killed protocol. do self.change_task_context(next_task) |sched, task| { @@ -829,18 +829,18 @@ impl CleanupJob { } } -// XXX: Some hacks to put a &fn in Scheduler without borrowck +// XXX: Some hacks to put a || closure in Scheduler without borrowck // complaining type UnsafeTaskReceiver = raw::Closure; trait ClosureConverter { - fn from_fn(&fn(&mut Scheduler, ~Task)) -> Self; - fn to_fn(self) -> &fn(&mut Scheduler, ~Task); + fn from_fn(|&mut Scheduler, ~Task|) -> Self; + fn to_fn(self) -> |&mut Scheduler, ~Task|; } impl ClosureConverter for UnsafeTaskReceiver { - fn from_fn(f: &fn(&mut Scheduler, ~Task)) -> UnsafeTaskReceiver { + fn from_fn(f: |&mut Scheduler, ~Task|) -> UnsafeTaskReceiver { unsafe { transmute(f) } } - fn to_fn(self) -> &fn(&mut Scheduler, ~Task) { unsafe { transmute(self) } } + fn to_fn(self) -> |&mut Scheduler, ~Task| { unsafe { transmute(self) } } } // On unix, we read randomness straight from /dev/urandom, but the diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 6d3eec9a921..3fe555de56c 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -282,7 +282,7 @@ impl Task { } } - pub fn run(&mut self, f: &fn()) { + pub fn run(&mut self, f: ||) { rtdebug!("run called on task: {}", borrow::to_uint(self)); // The only try/catch block in the world. Attempt to run the task's @@ -494,7 +494,7 @@ impl Coroutine { static UNWIND_TOKEN: uintptr_t = 839147; impl Unwinder { - pub fn try(&mut self, f: &fn()) { + pub fn try(&mut self, f: ||) { use unstable::raw::Closure; unsafe { @@ -512,7 +512,7 @@ impl Unwinder { code: transmute(code), env: transmute(env), }; - let closure: &fn() = transmute(closure); + let closure: || = transmute(closure); closure(); } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f376a30efa7..c567fd0a8b3 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -925,7 +925,7 @@ pub fn is_utf16(v: &[u16]) -> bool { /// # Failures /// /// * Fails on invalid utf-16 data -pub fn utf16_chars(v: &[u16], f: &fn(char)) { +pub fn utf16_chars(v: &[u16], f: |char|) { let len = v.len(); let mut i = 0u; while (i < len && v[i] != 0u16) { @@ -1762,7 +1762,7 @@ pub trait StrSlice<'self> { /// Work with the byte buffer and length of a slice. /// /// The buffer does not have a null terminator. - fn as_imm_buf(&self, f: &fn(*u8, uint) -> T) -> T; + fn as_imm_buf(&self, f: |*u8, uint| -> T) -> T; } impl<'self> StrSlice<'self> for &'self str { @@ -2268,7 +2268,7 @@ impl<'self> StrSlice<'self> for &'self str { } #[inline] - fn as_imm_buf(&self, f: &fn(*u8, uint) -> T) -> T { + fn as_imm_buf(&self, f: |*u8, uint| -> T) -> T { let v: &[u8] = unsafe { cast::transmute(*self) }; v.as_imm_buf(f) } @@ -2355,7 +2355,7 @@ pub trait OwnedStr { /// /// The caller must make sure any mutations to this buffer keep the string /// valid UTF-8! - fn as_mut_buf(&mut self, f: &fn(*mut u8, uint) -> T) -> T; + fn as_mut_buf(&mut self, f: |*mut u8, uint| -> T) -> T; } impl OwnedStr for ~str { @@ -2456,7 +2456,7 @@ impl OwnedStr for ~str { } #[inline] - fn as_mut_buf(&mut self, f: &fn(*mut u8, uint) -> T) -> T { + fn as_mut_buf(&mut self, f: |*mut u8, uint| -> T) -> T { unsafe { raw::as_owned_vec(self).as_mut_buf(f) } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 5915dd45c08..f9b918d6d12 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -554,7 +554,7 @@ pub fn try(f: proc() -> T) -> Result { /* Lifecycle functions */ /// Read the name of the current task. -pub fn with_task_name(blk: &fn(Option<&str>) -> U) -> U { +pub fn with_task_name(blk: |Option<&str>| -> U) -> U { use rt::task::Task; if in_green_task_context() { @@ -605,7 +605,7 @@ pub fn failing() -> bool { * } * ``` */ -pub fn unkillable(f: &fn() -> U) -> U { +pub fn unkillable(f: || -> U) -> U { use rt::task::Task; unsafe { @@ -640,7 +640,7 @@ pub fn unkillable(f: &fn() -> U) -> U { * // Task is unkillable again * } */ -pub fn rekillable(f: &fn() -> U) -> U { +pub fn rekillable(f: || -> U) -> U { use rt::task::Task; unsafe { @@ -1201,7 +1201,7 @@ fn test_spawn_sched_blocking() { } #[cfg(test)] -fn avoid_copying_the_body(spawnfn: &fn(v: proc())) { +fn avoid_copying_the_body(spawnfn: |v: proc()|) { let (p, ch) = stream::(); let x = ~1; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index d7d3e715ef9..66a2e8cc5e0 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -164,15 +164,17 @@ struct AncestorList(Option>); // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline] -fn access_group(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U { +fn access_group(x: &TaskGroupArc, blk: |TaskGroupInner| -> U) -> U { unsafe { x.with(blk) } } #[inline] -fn access_ancestors(x: &Exclusive, - blk: &fn(x: &mut AncestorNode) -> U) -> U { +fn access_ancestors( + x: &Exclusive, + blk: |x: &mut AncestorNode| -> U) + -> U { unsafe { x.with(blk) } @@ -197,17 +199,17 @@ fn incr_generation(_ancestors: &AncestorList) -> uint { 0 } // is NOT called on the block that forward_blk broke on!). // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. fn each_ancestor(list: &mut AncestorList, - bail_blk: &fn(TaskGroupInner), - forward_blk: &fn(TaskGroupInner) -> bool) - -> bool { + bail_blk: |TaskGroupInner|, + forward_blk: |TaskGroupInner| -> bool) + -> bool { // "Kickoff" call - there was no last generation. return !coalesce(list, bail_blk, forward_blk, uint::max_value); // Recursively iterates, and coalesces afterwards if needed. Returns // whether or not unwinding is needed (i.e., !successful iteration). fn coalesce(list: &mut AncestorList, - bail_blk: &fn(TaskGroupInner), - forward_blk: &fn(TaskGroupInner) -> bool, + bail_blk: |TaskGroupInner|, + forward_blk: |TaskGroupInner| -> bool, last_generation: uint) -> bool { let (coalesce_this, early_break) = iterate(list, bail_blk, forward_blk, last_generation); @@ -229,8 +231,8 @@ fn each_ancestor(list: &mut AncestorList, // True if the supplied block did 'break', here or in any recursive // calls. If so, must call the unwinder on all previous nodes. fn iterate(ancestors: &mut AncestorList, - bail_blk: &fn(TaskGroupInner), - forward_blk: &fn(TaskGroupInner) -> bool, + bail_blk: |TaskGroupInner|, + forward_blk: |TaskGroupInner| -> bool, last_generation: uint) -> (Option, bool) { // At each step of iteration, three booleans are at play which govern @@ -457,7 +459,7 @@ impl RuntimeGlue { }; } - fn with_task_handle_and_failing(blk: &fn(&KillHandle, bool)) { + fn with_task_handle_and_failing(blk: |&KillHandle, bool|) { assert!(in_green_task_context()); unsafe { // Can't use safe borrow, because the taskgroup destructor needs to @@ -467,7 +469,7 @@ impl RuntimeGlue { } } - fn with_my_taskgroup(blk: &fn(&Taskgroup) -> U) -> U { + fn with_my_taskgroup(blk: |&Taskgroup| -> U) -> U { assert!(in_green_task_context()); unsafe { // Can't use safe borrow, because creating new hashmaps for the @@ -545,7 +547,7 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc, }; if result { // Unwinding function in case any ancestral enlisting fails - let bail: &fn(TaskGroupInner) = |tg| { leave_taskgroup(tg, child, false) }; + let bail: |TaskGroupInner| = |tg| { leave_taskgroup(tg, child, false) }; // Attempt to join every ancestor group. result = do each_ancestor(ancestors, bail) |ancestor_tg| { // Enlist as a descendant, not as an actual member. diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index c561fb6cc8a..f60d8641aca 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -107,43 +107,43 @@ impl TrieMap { /// Visit all key-value pairs in reverse order #[inline] - pub fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + pub fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool { self.root.each_reverse(f) } /// Visit all key-value pairs in order #[inline] - pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + pub fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool { self.root.each(f) } /// Visit all keys in order #[inline] - pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool { + pub fn each_key(&self, f: |&uint| -> bool) -> bool { self.each(|k, _| f(k)) } /// Visit all values in order #[inline] - pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool { + pub fn each_value<'a>(&'a self, f: |&'a T| -> bool) -> bool { self.each(|_, v| f(v)) } /// Iterate over the map and mutate the contained values #[inline] - pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool { + pub fn mutate_values(&mut self, f: |&uint, &mut T| -> bool) -> bool { self.root.mutate_values(f) } /// Visit all keys in reverse order #[inline] - pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool { + pub fn each_key_reverse(&self, f: |&uint| -> bool) -> bool { self.each_reverse(|k, _| f(k)) } /// Visit all values in reverse order #[inline] - pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool { + pub fn each_value_reverse(&self, f: |&T| -> bool) -> bool { self.each_reverse(|_, v| f(v)) } @@ -266,11 +266,11 @@ impl TrieSet { /// Visit all values in order #[inline] - pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) } + pub fn each(&self, f: |&uint| -> bool) -> bool { self.map.each_key(f) } /// Visit all values in reverse order #[inline] - pub fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool { + pub fn each_reverse(&self, f: |&uint| -> bool) -> bool { self.map.each_key_reverse(f) } @@ -328,7 +328,7 @@ impl TrieNode { } impl TrieNode { - fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool { for elt in self.children.iter() { match *elt { Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false }, @@ -339,7 +339,7 @@ impl TrieNode { true } - fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool { for elt in self.children.rev_iter() { match *elt { Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false }, @@ -350,7 +350,7 @@ impl TrieNode { true } - fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool { + fn mutate_values<'a>(&'a mut self, f: |&uint, &mut T| -> bool) -> bool { for child in self.children.mut_iter() { match *child { Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) { diff --git a/src/libstd/unicode.rs b/src/libstd/unicode.rs index d7f84a6abfb..a8f56228dcb 100644 --- a/src/libstd/unicode.rs +++ b/src/libstd/unicode.rs @@ -3619,15 +3619,15 @@ pub mod decompose { ('\U0001d185', '\U0001d189', 230), ('\U0001d18a', '\U0001d18b', 220), ('\U0001d1aa', '\U0001d1ad', 230), ('\U0001d242', '\U0001d244', 230) ]; - pub fn canonical(c: char, i: &fn(char)) { d(c, i, false); } + pub fn canonical(c: char, i: |char|) { d(c, i, false); } - pub fn compatibility(c: char, i: &fn(char)) { d(c, i, true); } + pub fn compatibility(c: char, i: |char|) { d(c, i, true); } pub fn canonical_combining_class(c: char) -> u8 { bsearch_range_value_table(c, combining_class_table) } - fn d(c: char, i: &fn(char), k: bool) { + fn d(c: char, i: |char|, k: bool) { use iter::Iterator; if c <= '\x7f' { i(c); return; } diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index e0d284a32df..cdfbf8c0049 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -153,10 +153,9 @@ pub mod dl { dlopen(ptr::null(), Lazy as libc::c_int) } - pub fn check_for_errors_in(f: &fn()->T) -> Result { + pub fn check_for_errors_in(f: || -> T) -> Result { use unstable::mutex::{Mutex, MUTEX_INIT}; static mut lock: Mutex = MUTEX_INIT; - unsafe { // dlerror isn't thread safe, so we need to lock around this entire // sequence. `atomically` asserts that we don't do anything that @@ -225,7 +224,7 @@ pub mod dl { handle } - pub fn check_for_errors_in(f: &fn()->T) -> Result { + pub fn check_for_errors_in(f: || -> T) -> Result { unsafe { do atomically { SetLastError(0); diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index 266a619c710..78f1c3655ad 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -28,13 +28,13 @@ use ops::Drop; #[cfg(test)] use task::{failing, spawn}; pub trait Finally { - fn finally(&self, dtor: &fn()) -> T; + fn finally(&self, dtor: ||) -> T; } macro_rules! finally_fn { ($fnty:ty) => { impl Finally for $fnty { - fn finally(&self, dtor: &fn()) -> T { + fn finally(&self, dtor: ||) -> T { let _d = Finallyalizer { dtor: dtor }; @@ -45,7 +45,7 @@ macro_rules! finally_fn { } impl<'self,T> Finally for &'self fn() -> T { - fn finally(&self, dtor: &fn()) -> T { + fn finally(&self, dtor: ||) -> T { let _d = Finallyalizer { dtor: dtor }; @@ -95,7 +95,7 @@ fn test_fail() { #[test] fn test_retval() { - let closure: &fn() -> int = || 10; + let closure: || -> int = || 10; let i = do closure.finally { }; assert_eq!(i, 10); } diff --git a/src/libstd/unstable/raw.rs b/src/libstd/unstable/raw.rs index d784c1d38c6..4ad4656af7b 100644 --- a/src/libstd/unstable/raw.rs +++ b/src/libstd/unstable/raw.rs @@ -73,7 +73,7 @@ mod tests { fn synthesize_closure() { unsafe { let x = 10; - let f: &fn(int) -> int = |y| x + y; + let f: |int| -> int = |y| x + y; assert_eq!(f(20), 30); @@ -87,7 +87,7 @@ mod tests { env: environment }; - let new_f: &fn(int) -> int = cast::transmute(new_closure); + let new_f: |int| -> int = cast::transmute(new_closure); assert_eq!(new_f(20), 30); } } diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index 3423b995fda..ae4b5d4c6aa 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -296,7 +296,7 @@ impl Drop for UnsafeArc{ * synchronization whatsoever. It only makes sense to use for CPU-local issues. */ // FIXME(#8140) should not be pub -pub unsafe fn atomically(f: &fn() -> U) -> U { +pub unsafe fn atomically(f: || -> U) -> U { use rt::task::{Task, GreenTask, SchedTask}; use rt::local::Local; @@ -340,7 +340,7 @@ impl LittleLock { } } - pub unsafe fn lock(&self, f: &fn() -> T) -> T { + pub unsafe fn lock(&self, f: || -> T) -> T { let this = cast::transmute_mut(self); do atomically { this.l.lock(); @@ -352,7 +352,7 @@ impl LittleLock { } } - pub unsafe fn try_lock(&self, f: &fn() -> T) -> Option { + pub unsafe fn try_lock(&self, f: || -> T) -> Option { let this = cast::transmute_mut(self); do atomically { if this.l.trylock() { @@ -372,7 +372,7 @@ impl LittleLock { this.l.signal(); } - pub unsafe fn lock_and_wait(&self, f: &fn() -> bool) { + pub unsafe fn lock_and_wait(&self, f: || -> bool) { let this = cast::transmute_mut(self); do atomically { this.l.lock(); @@ -433,7 +433,7 @@ impl Exclusive { // accessing the provided condition variable) are prohibited while inside // the Exclusive. Supporting that is a work in progress. #[inline] - pub unsafe fn with(&self, f: &fn(x: &mut T) -> U) -> U { + pub unsafe fn with(&self, f: |x: &mut T| -> U) -> U { let rec = self.x.get(); do (*rec).lock.lock { if (*rec).failed { @@ -447,14 +447,14 @@ impl Exclusive { } #[inline] - pub unsafe fn with_imm(&self, f: &fn(x: &T) -> U) -> U { + pub unsafe fn with_imm(&self, f: |x: &T| -> U) -> U { do self.with |x| { f(cast::transmute_immut(x)) } } #[inline] - pub unsafe fn hold_and_signal(&self, f: &fn(x: &mut T)) { + pub unsafe fn hold_and_signal(&self, f: |x: &mut T|) { let rec = self.x.get(); do (*rec).lock.lock { if (*rec).failed { @@ -468,7 +468,7 @@ impl Exclusive { } #[inline] - pub unsafe fn hold_and_wait(&self, f: &fn(x: &T) -> bool) { + pub unsafe fn hold_and_wait(&self, f: |x: &T| -> bool) { let rec = self.x.get(); do (*rec).lock.lock_and_wait { if (*rec).failed { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index c2aa4c234d1..2bd6a00ed4a 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -132,7 +132,7 @@ use util; * Creates an owned vector of size `n_elts` and initializes the elements * to the value returned by the function `op`. */ -pub fn from_fn(n_elts: uint, op: &fn(uint) -> T) -> ~[T] { +pub fn from_fn(n_elts: uint, op: |uint| -> T) -> ~[T] { unsafe { let mut v = with_capacity(n_elts); let p = raw::to_mut_ptr(v); @@ -211,7 +211,7 @@ pub fn with_capacity(capacity: uint) -> ~[T] { * onto the vector being constructed. */ #[inline] -pub fn build(size: Option, builder: &fn(push: &fn(v: A))) -> ~[A] { +pub fn build(size: Option, builder: |push: |v: A||) -> ~[A] { let mut vec = with_capacity(size.unwrap_or(4)); builder(|x| vec.push(x)); vec @@ -338,7 +338,7 @@ pub fn append_one(lhs: ~[T], x: T) -> ~[T] { * Apply a function to each element of a vector and return a concatenation * of each result vector */ -pub fn flat_map(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] { +pub fn flat_map(v: &[T], f: |t: &T| -> ~[U]) -> ~[U] { let mut result = ~[]; for elem in v.iter() { result.push_all_move(f(elem)); } result @@ -946,7 +946,7 @@ pub trait ImmutableVector<'self, T> { * Apply a function to each element of a vector and return a concatenation * of each result vector */ - fn flat_map(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]; + fn flat_map(&self, f: |t: &T| -> ~[U]) -> ~[U]; /// Returns a pointer to the element at the given index, without doing /// bounds checking. unsafe fn unsafe_ref(&self, index: uint) -> *T; @@ -961,12 +961,12 @@ pub trait ImmutableVector<'self, T> { * Returns the index where the comparator returned `Equal`, or `None` if * not found. */ - fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option; + fn bsearch(&self, f: |&T| -> Ordering) -> Option; /// Deprecated, use iterators where possible /// (`self.iter().map(f)`). Apply a function to each element /// of a vector and return the results. - fn map(&self, &fn(t: &T) -> U) -> ~[U]; + fn map(&self, |t: &T| -> U) -> ~[U]; /** * Work with the buffer of a vector. @@ -974,7 +974,7 @@ pub trait ImmutableVector<'self, T> { * Allows for unsafe manipulation of vector contents, which is useful for * foreign interop. */ - fn as_imm_buf(&self, f: &fn(*T, uint) -> U) -> U; + fn as_imm_buf(&self, f: |*T, uint| -> U) -> U; } impl<'self,T> ImmutableVector<'self, T> for &'self [T] { @@ -1104,7 +1104,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } #[inline] - fn flat_map(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] { + fn flat_map(&self, f: |t: &T| -> ~[U]) -> ~[U] { flat_map(*self, f) } @@ -1113,7 +1113,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { self.repr().data.offset(index as int) } - fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option { + fn bsearch(&self, f: |&T| -> Ordering) -> Option { let mut base : uint = 0; let mut lim : uint = self.len(); @@ -1132,12 +1132,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { return None; } - fn map(&self, f: &fn(t: &T) -> U) -> ~[U] { + fn map(&self, f: |t: &T| -> U) -> ~[U] { self.iter().map(f).collect() } #[inline] - fn as_imm_buf(&self, f: &fn(*T, uint) -> U) -> U { + fn as_imm_buf(&self, f: |*T, uint| -> U) -> U { let s = self.repr(); f(s.data, s.len) } @@ -1212,7 +1212,7 @@ pub trait ImmutableCopyableVector { * Partitions the vector into those that satisfies the predicate, and * those that do not. */ - fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]); + fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]); /// Returns the element at the given index, without doing bounds checking. unsafe fn unsafe_get(&self, elem: uint) -> T; @@ -1223,7 +1223,7 @@ pub trait ImmutableCopyableVector { impl<'self,T:Clone> ImmutableCopyableVector for &'self [T] { #[inline] - fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) { + fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; @@ -1370,12 +1370,12 @@ pub trait OwnedVector { /** * Like `filter()`, but in place. Preserves order of `v`. Linear time. */ - fn retain(&mut self, f: &fn(t: &T) -> bool); + fn retain(&mut self, f: |t: &T| -> bool); /** * Partitions the vector into those that satisfies the predicate, and * those that do not. */ - fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]); + fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]); /** * Expands a vector in place, initializing the new elements to the result of @@ -1389,7 +1389,7 @@ pub trait OwnedVector { * * init_op - A function to call to retreive each appended element's * value */ - fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T); + fn grow_fn(&mut self, n: uint, op: |uint| -> T); } impl OwnedVector for ~[T] { @@ -1646,7 +1646,7 @@ impl OwnedVector for ~[T] { unsafe { raw::set_len(self, newlen); } } - fn retain(&mut self, f: &fn(t: &T) -> bool) { + fn retain(&mut self, f: |t: &T| -> bool) { let len = self.len(); let mut deleted: uint = 0; @@ -1664,7 +1664,7 @@ impl OwnedVector for ~[T] { } #[inline] - fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) { + fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; @@ -1678,7 +1678,7 @@ impl OwnedVector for ~[T] { (lefts, rights) } - fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T) { + fn grow_fn(&mut self, n: uint, op: |uint| -> T) { let new_len = self.len() + n; self.reserve_at_least(new_len); let mut i: uint = 0u; @@ -1919,7 +1919,7 @@ pub trait MutableVector<'self, T> { unsafe fn unsafe_set(self, index: uint, val: T); /// Similar to `as_imm_buf` but passing a `*mut T` - fn as_mut_buf(self, f: &fn(*mut T, uint) -> U) -> U; + fn as_mut_buf(self, f: |*mut T, uint| -> U) -> U; } impl<'self,T> MutableVector<'self, T> for &'self mut [T] { @@ -2016,7 +2016,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] { } #[inline] - fn as_mut_buf(self, f: &fn(*mut T, uint) -> U) -> U { + fn as_mut_buf(self, f: |*mut T, uint| -> U) -> U { let Slice{ data, len } = self.repr(); f(data as *mut T, len) } @@ -2107,9 +2107,8 @@ pub mod raw { * not bytes). */ #[inline] - pub unsafe fn buf_as_slice(p: *T, - len: uint, - f: &fn(v: &[T]) -> U) -> U { + pub unsafe fn buf_as_slice(p: *T, len: uint, f: |v: &[T]| -> U) + -> U { f(cast::transmute(Slice { data: p, len: len @@ -2121,9 +2120,12 @@ pub mod raw { * not bytes). */ #[inline] - pub unsafe fn mut_buf_as_slice(p: *mut T, - len: uint, - f: &fn(v: &mut [T]) -> U) -> U { + pub unsafe fn mut_buf_as_slice( + p: *mut T, + len: uint, + f: |v: &mut [T]| -> U) + -> U { f(cast::transmute(Slice { data: p as *T, len: len