diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index b3da9b4f16b88..4660036a774e0 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -220,7 +220,7 @@ impl MutexArc { * blocked on the mutex) will also fail immediately. */ #[inline] - pub unsafe fn unsafe_access(&self, blk: &fn(x: &mut T) -> U) -> U { + pub unsafe fn unsafe_access(&self, blk: |x: &mut T| -> U) -> U { let state = self.x.get(); // Borrowck would complain about this if the function were // not already unsafe. See borrow_rwlock, far below. @@ -234,8 +234,7 @@ impl MutexArc { /// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond(). #[inline] pub unsafe fn unsafe_access_cond(&self, - blk: &fn(x: &mut T, - c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { let state = self.x.get(); do (&(*state).lock).lock_cond |cond| { @@ -284,15 +283,14 @@ impl MutexArc { * unsafe_access_cond. */ #[inline] - pub fn access(&self, blk: &fn(x: &mut T) -> U) -> U { + pub fn access(&self, blk: |x: &mut T| -> U) -> U { unsafe { self.unsafe_access(blk) } } /// As unsafe_access_cond but safe and Freeze. #[inline] pub fn access_cond(&self, - blk: &fn(x: &mut T, - c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { unsafe { self.unsafe_access_cond(blk) } } @@ -389,7 +387,7 @@ impl RWArc { * poison the Arc, so subsequent readers and writers will both also fail. */ #[inline] - pub fn write(&self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&self, blk: |x: &mut T| -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write { @@ -403,7 +401,7 @@ impl RWArc { /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline] pub fn write_cond(&self, - blk: &fn(x: &mut T, c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { unsafe { let state = self.x.get(); @@ -427,7 +425,7 @@ impl RWArc { * Failing will unlock the Arc while unwinding. However, unlike all other * access modes, this will not poison the Arc. */ - pub fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: |x: &T| -> U) -> U { unsafe { let state = self.x.get(); do (*state).lock.read { @@ -457,7 +455,7 @@ impl RWArc { * } * ``` */ - pub fn write_downgrade(&self, blk: &fn(v: RWWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: |v: RWWriteMode| -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write_downgrade |write_mode| { @@ -539,7 +537,7 @@ pub struct RWReadMode<'self, T> { impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { /// Access the pre-downgrade RWArc in write mode. - pub fn write(&mut self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&mut self, blk: |x: &mut T| -> U) -> U { match *self { RWWriteMode { data: &ref mut data, @@ -555,7 +553,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { /// Access the pre-downgrade RWArc in write mode with a condvar. pub fn write_cond(&mut self, - blk: &fn(x: &mut T, c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { match *self { RWWriteMode { @@ -580,7 +578,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { impl<'self, T:Freeze + Send> RWReadMode<'self, T> { /// Access the post-downgrade rwlock in read mode. - pub fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: |x: &T| -> U) -> U { match *self { RWReadMode { data: data, diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index b684e0d429e31..2bb36e25fcb04 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -184,7 +184,7 @@ impl Arena { } #[inline] - fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let tydesc = get_tydesc::(); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); @@ -241,7 +241,7 @@ impl Arena { } #[inline] - fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = @@ -263,7 +263,7 @@ impl Arena { // The external interface #[inline] - pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T { + pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T { unsafe { // XXX: Borrow check let this = transmute_mut(self); diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 96123ad75b250..c68133dac1010 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -40,7 +40,7 @@ impl SmallBitv { pub fn bits_op(&mut self, right_bits: uint, nbits: uint, - f: &fn(uint, uint) -> uint) + f: |uint, uint| -> uint) -> bool { let mask = small_mask(nbits); let old_b: uint = self.bits; @@ -140,7 +140,7 @@ impl BigBitv { pub fn process(&mut self, b: &BigBitv, nbits: uint, - op: &fn(uint, uint) -> uint) + op: |uint, uint| -> uint) -> bool { let len = b.storage.len(); assert_eq!(self.storage.len(), len); @@ -161,7 +161,7 @@ impl BigBitv { } #[inline] - pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool { + pub fn each_storage(&mut self, op: |v: &mut uint| -> bool) -> bool { self.storage.mut_iter().advance(|elt| op(elt)) } @@ -512,7 +512,7 @@ impl Bitv { true } - pub fn ones(&self, f: &fn(uint) -> bool) -> bool { + pub fn ones(&self, f: |uint| -> bool) -> bool { range(0u, self.nbits).advance(|i| !self.get(i) || f(i)) } @@ -542,7 +542,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv { * Create a `Bitv` of the specified length where the value at each * index is `f(index)`. */ -pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv { +pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv { let mut bitv = Bitv::new(len, false); for i in range(0u, len) { bitv.set(i, f(i)); @@ -557,7 +557,7 @@ impl ops::Index for Bitv { } #[inline] -fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool { +fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool { if bits == 0 { return true; } @@ -675,7 +675,7 @@ impl BitvSet { } #[inline] - fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) { + fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) { fn nbits(mut w: uint) -> uint { let mut bits = 0; for _ in range(0u, uint::bits) { @@ -722,7 +722,7 @@ impl BitvSet { BitvSetIterator {set: self, next_idx: 0} } - pub fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 & !w2, |b| f(&b)) { return false @@ -734,8 +734,8 @@ impl BitvSet { ) } - pub fn symmetric_difference(&self, other: &BitvSet, - f: &fn(&uint) -> bool) -> bool { + pub fn symmetric_difference(&self, other: &BitvSet, f: |&uint| -> bool) + -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 ^ w2, |b| f(&b)) { return false @@ -744,11 +744,11 @@ impl BitvSet { self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b))) } - pub fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn intersection(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { self.common_iter(other).advance(|(i, w1, w2)| iterate_bits(i, w1 & w2, |b| f(&b))) } - pub fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn union(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 | w2, |b| f(&b)) { return false diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index f29cbd6ee5294..418b8256189f9 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -320,7 +320,7 @@ impl DList { /// or at the end. /// /// O(N) - pub fn insert_when(&mut self, elt: T, f: &fn(&T, &T) -> bool) { + pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) { { let mut it = self.mut_iter(); loop { @@ -339,7 +339,7 @@ impl DList { /// put `a` in the result if `f(a, b)` is true, else `b`. /// /// O(max(N, M)) - pub fn merge(&mut self, mut other: DList, f: &fn(&T, &T) -> bool) { + pub fn merge(&mut self, mut other: DList, f: |&T, &T| -> bool) { { let mut it = self.mut_iter(); loop { diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index c249a8c09f29b..c82ee733a4cbe 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -216,7 +216,7 @@ pub mod reader { } } - pub fn docs(d: Doc, it: &fn(uint, Doc) -> bool) -> bool { + pub fn docs(d: Doc, it: |uint, Doc| -> bool) -> bool { let mut pos = d.start; while pos < d.end { let elt_tag = vuint_at(*d.data, pos); @@ -230,7 +230,7 @@ pub mod reader { return true; } - pub fn tagged_docs(d: Doc, tg: uint, it: &fn(Doc) -> bool) -> bool { + pub fn tagged_docs(d: Doc, tg: uint, it: |Doc| -> bool) -> bool { let mut pos = d.start; while pos < d.end { let elt_tag = vuint_at(*d.data, pos); @@ -247,7 +247,7 @@ pub mod reader { return true; } - pub fn with_doc_data(d: Doc, f: &fn(x: &[u8]) -> T) -> T { + pub fn with_doc_data(d: Doc, f: |x: &[u8]| -> T) -> T { f(d.data.slice(d.start, d.end)) } @@ -332,7 +332,7 @@ pub mod reader { } fn push_doc(&mut self, exp_tag: EbmlEncoderTag, - f: &fn(&mut Decoder) -> T) -> T { + f: |&mut Decoder| -> T) -> T { let d = self.next_doc(exp_tag); let old_parent = self.parent; let old_pos = self.pos; @@ -352,8 +352,7 @@ pub mod reader { } impl Decoder { - pub fn read_opaque(&mut self, op: &fn(&mut Decoder, Doc) -> R) - -> R { + pub fn read_opaque(&mut self, op: |&mut Decoder, Doc| -> R) -> R { let doc = self.next_doc(EsOpaque); let (old_parent, old_pos) = (self.parent, self.pos); @@ -424,10 +423,7 @@ pub mod reader { } // Compound types: - fn read_enum(&mut self, - name: &str, - f: &fn(&mut Decoder) -> T) - -> T { + fn read_enum(&mut self, name: &str, f: |&mut Decoder| -> T) -> T { debug!("read_enum({})", name); self._check_label(name); @@ -446,7 +442,7 @@ pub mod reader { fn read_enum_variant(&mut self, _: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_variant()"); let idx = self._next_uint(EsEnumVid); @@ -467,14 +463,14 @@ pub mod reader { fn read_enum_variant_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) -> T { + f: |&mut Decoder| -> T) -> T { debug!("read_enum_variant_arg(idx={})", idx); f(self) } fn read_enum_struct_variant(&mut self, _: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_struct_variant()"); let idx = self._next_uint(EsEnumVid); @@ -496,7 +492,7 @@ pub mod reader { fn read_enum_struct_variant_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx); f(self) @@ -505,7 +501,7 @@ pub mod reader { fn read_struct(&mut self, name: &str, _: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct(name={})", name); f(self) @@ -514,19 +510,19 @@ pub mod reader { fn read_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct_field(name={}, idx={})", name, idx); self._check_label(name); f(self) } - fn read_tuple(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_tuple(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple()"); self.read_seq(f) } - fn read_tuple_arg(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_tuple_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_tuple_arg(idx={})", idx); self.read_seq_elt(idx, f) @@ -534,7 +530,7 @@ pub mod reader { fn read_tuple_struct(&mut self, name: &str, - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple_struct(name={})", name); self.read_tuple(f) @@ -542,13 +538,13 @@ pub mod reader { fn read_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_tuple_struct_arg(idx={})", idx); self.read_tuple_arg(idx, f) } - fn read_option(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { + fn read_option(&mut self, f: |&mut Decoder, bool| -> T) -> T { debug!("read_option()"); do self.read_enum("Option") |this| { do this.read_enum_variant(["None", "Some"]) |this, idx| { @@ -561,7 +557,7 @@ pub mod reader { } } - fn read_seq(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); do self.push_doc(EsVec) |d| { let len = d._next_uint(EsVecLen); @@ -570,13 +566,13 @@ pub mod reader { } } - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_seq_elt(idx={})", idx); self.push_doc(EsVecElt, f) } - fn read_map(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); do self.push_doc(EsMap) |d| { let len = d._next_uint(EsMapLen); @@ -585,17 +581,13 @@ pub mod reader { } } - fn read_map_elt_key(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_key(idx={})", idx); self.push_doc(EsMapKey, f) } - fn read_map_elt_val(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_val(idx={})", idx); self.push_doc(EsMapVal, f) @@ -682,7 +674,7 @@ pub mod writer { debug!("End tag (size = {})", size); } - pub fn wr_tag(&mut self, tag_id: uint, blk: &fn()) { + pub fn wr_tag(&mut self, tag_id: uint, blk: ||) { self.start_tag(tag_id); blk(); self.end_tag(); @@ -779,7 +771,7 @@ pub mod writer { } impl Encoder { - pub fn emit_opaque(&mut self, f: &fn(&mut Encoder)) { + pub fn emit_opaque(&mut self, f: |&mut Encoder|) { self.start_tag(EsOpaque as uint); f(self); self.end_tag(); @@ -841,7 +833,7 @@ pub mod writer { self.wr_tagged_str(EsStr as uint, v) } - fn emit_enum(&mut self, name: &str, f: &fn(&mut Encoder)) { + fn emit_enum(&mut self, name: &str, f: |&mut Encoder|) { self._emit_label(name); self.start_tag(EsEnum as uint); f(self); @@ -852,14 +844,14 @@ pub mod writer { _: &str, v_id: uint, _: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self._emit_tagged_uint(EsEnumVid, v_id); self.start_tag(EsEnumBody as uint); f(self); self.end_tag(); } - fn emit_enum_variant_arg(&mut self, _: uint, f: &fn(&mut Encoder)) { + fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder|) { f(self) } @@ -867,83 +859,83 @@ pub mod writer { v_name: &str, v_id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant(v_name, v_id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant_arg(idx, f) } - fn emit_struct(&mut self, _: &str, _len: uint, f: &fn(&mut Encoder)) { + fn emit_struct(&mut self, _: &str, _len: uint, f: |&mut Encoder|) { f(self) } fn emit_struct_field(&mut self, name: &str, _: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self._emit_label(name); f(self) } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _: &str, len: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut Encoder)) { + fn emit_option(&mut self, f: |&mut Encoder|) { self.emit_enum("Option", f); } fn emit_option_none(&mut self) { self.emit_enum_variant("None", 0, 0, |_| ()) } - fn emit_option_some(&mut self, f: &fn(&mut Encoder)) { + fn emit_option_some(&mut self, f: |&mut Encoder|) { self.emit_enum_variant("Some", 1, 1, f) } - fn emit_seq(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_seq(&mut self, len: uint, f: |&mut Encoder|) { self.start_tag(EsVec as uint); self._emit_tagged_uint(EsVecLen, len); f(self); self.end_tag(); } - fn emit_seq_elt(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsVecElt as uint); f(self); self.end_tag(); } - fn emit_map(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_map(&mut self, len: uint, f: |&mut Encoder|) { self.start_tag(EsMap as uint); self._emit_tagged_uint(EsMapLen, len); f(self); self.end_tag(); } - fn emit_map_elt_key(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsMapKey as uint); f(self); self.end_tag(); } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsMapVal as uint); f(self); self.end_tag(); diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 918952132ab05..d0df9dbe83832 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -768,9 +768,8 @@ pub mod groups { /// /// Fails during iteration if the string contains a non-whitespace /// sequence longer than the limit. - fn each_split_within<'a>(ss: &'a str, - lim: uint, - it: &fn(&'a str) -> bool) -> bool { + fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) + -> bool { // Just for fun, let's write this as a state machine: enum SplitWithinState { @@ -795,14 +794,14 @@ pub mod groups { let mut lim = lim; let mut cont = true; - let slice: &fn() = || { cont = it(ss.slice(slice_start, last_end)) }; + let slice: || = || { cont = it(ss.slice(slice_start, last_end)) }; // if the limit is larger than the string, lower it to save cycles if (lim >= fake_i) { lim = fake_i; } - let machine: &fn((uint, char)) -> bool = |(i, c)| { + let machine: |(uint, char)| -> bool = |(i, c)| { let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr }; let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 7370dfafba9c8..64655ca2b70f8 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -129,13 +129,13 @@ impl serialize::Encoder for Encoder { write!(self.wr, "{}", escape_str(v)) } - fn emit_enum(&mut self, _name: &str, f: &fn(&mut Encoder)) { f(self) } + fn emit_enum(&mut self, _name: &str, f: |&mut Encoder|) { f(self) } fn emit_enum_variant(&mut self, name: &str, _id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { // enums are encoded as strings or objects // Bunny => "Bunny" // Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]} @@ -150,7 +150,7 @@ impl serialize::Encoder for Encoder { } } - fn emit_enum_variant_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_enum_variant_arg(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ","); } @@ -161,18 +161,18 @@ impl serialize::Encoder for Encoder { name: &str, id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant(name, id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant_arg(idx, f) } - fn emit_struct(&mut self, _: &str, _: uint, f: &fn(&mut Encoder)) { + fn emit_struct(&mut self, _: &str, _: uint, f: |&mut Encoder|) { write!(self.wr, r"\{"); f(self); write!(self.wr, r"\}"); @@ -181,58 +181,58 @@ impl serialize::Encoder for Encoder { fn emit_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ",") } write!(self.wr, "{}:", escape_str(name)); f(self); } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _name: &str, len: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut Encoder)) { f(self); } + fn emit_option(&mut self, f: |&mut Encoder|) { f(self); } fn emit_option_none(&mut self) { self.emit_nil(); } - fn emit_option_some(&mut self, f: &fn(&mut Encoder)) { f(self); } + fn emit_option_some(&mut self, f: |&mut Encoder|) { f(self); } - fn emit_seq(&mut self, _len: uint, f: &fn(&mut Encoder)) { + fn emit_seq(&mut self, _len: uint, f: |&mut Encoder|) { write!(self.wr, "["); f(self); write!(self.wr, "]"); } - fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_seq_elt(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ","); } f(self) } - fn emit_map(&mut self, _len: uint, f: &fn(&mut Encoder)) { + fn emit_map(&mut self, _len: uint, f: |&mut Encoder|) { write!(self.wr, r"\{"); f(self); write!(self.wr, r"\}"); } - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ",") } f(self) } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) { write!(self.wr, ":"); f(self) } @@ -284,7 +284,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { write!(self.wr, "{}", escape_str(v)); } - fn emit_enum(&mut self, _name: &str, f: &fn(&mut PrettyEncoder)) { + fn emit_enum(&mut self, _name: &str, f: |&mut PrettyEncoder|) { f(self) } @@ -292,7 +292,7 @@ impl serialize::Encoder for PrettyEncoder { name: &str, _: uint, cnt: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if cnt == 0 { write!(self.wr, "{}", escape_str(name)); } else { @@ -306,7 +306,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_enum_variant_arg(&mut self, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if idx != 0 { write!(self.wr, ",\n"); } @@ -318,14 +318,14 @@ impl serialize::Encoder for PrettyEncoder { name: &str, id: uint, cnt: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_enum_variant(name, id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_enum_variant_arg(idx, f) } @@ -333,7 +333,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_struct(&mut self, _: &str, len: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "\\{\\}"); } else { @@ -348,7 +348,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -358,30 +358,30 @@ impl serialize::Encoder for PrettyEncoder { f(self); } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut PrettyEncoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut PrettyEncoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _: &str, len: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_seq(len, f) } fn emit_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); } + fn emit_option(&mut self, f: |&mut PrettyEncoder|) { f(self); } fn emit_option_none(&mut self) { self.emit_nil(); } - fn emit_option_some(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); } + fn emit_option_some(&mut self, f: |&mut PrettyEncoder|) { f(self); } - fn emit_seq(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_seq(&mut self, len: uint, f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "[]"); } else { @@ -393,7 +393,7 @@ impl serialize::Encoder for PrettyEncoder { } } - fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_seq_elt(&mut self, idx: uint, f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -403,7 +403,7 @@ impl serialize::Encoder for PrettyEncoder { f(self) } - fn emit_map(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map(&mut self, len: uint, f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "\\{\\}"); } else { @@ -415,7 +415,7 @@ impl serialize::Encoder for PrettyEncoder { } } - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -425,7 +425,7 @@ impl serialize::Encoder for PrettyEncoder { f(self); } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut PrettyEncoder|) { write!(self.wr, ": "); f(self); } @@ -921,14 +921,14 @@ impl serialize::Decoder for Decoder { } } - fn read_enum(&mut self, name: &str, f: &fn(&mut Decoder) -> T) -> T { + fn read_enum(&mut self, name: &str, f: |&mut Decoder| -> T) -> T { debug!("read_enum({})", name); f(self) } fn read_enum_variant(&mut self, names: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_variant(names={:?})", names); let name = match self.stack.pop() { @@ -957,9 +957,7 @@ impl serialize::Decoder for Decoder { f(self, idx) } - fn read_enum_variant_arg(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_enum_variant_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_enum_variant_arg(idx={})", idx); f(self) @@ -967,7 +965,7 @@ impl serialize::Decoder for Decoder { fn read_enum_struct_variant(&mut self, names: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_struct_variant(names={:?})", names); self.read_enum_variant(names, f) @@ -977,7 +975,7 @@ impl serialize::Decoder for Decoder { fn read_enum_struct_variant_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx); self.read_enum_variant_arg(idx, f) @@ -986,7 +984,7 @@ impl serialize::Decoder for Decoder { fn read_struct(&mut self, name: &str, len: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct(name={}, len={})", name, len); let value = f(self); @@ -997,7 +995,7 @@ impl serialize::Decoder for Decoder { fn read_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct_field(name={}, idx={})", name, idx); match self.stack.pop() { @@ -1017,22 +1015,19 @@ impl serialize::Decoder for Decoder { } } - fn read_tuple(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_tuple(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple()"); self.read_seq(f) } - fn read_tuple_arg(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) - -> T { + fn read_tuple_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_tuple_arg(idx={})", idx); self.read_seq_elt(idx, f) } fn read_tuple_struct(&mut self, name: &str, - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple_struct(name={})", name); self.read_tuple(f) @@ -1040,20 +1035,20 @@ impl serialize::Decoder for Decoder { fn read_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_tuple_struct_arg(idx={})", idx); self.read_tuple_arg(idx, f) } - fn read_option(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { + fn read_option(&mut self, f: |&mut Decoder, bool| -> T) -> T { match self.stack.pop() { Null => f(self, false), value => { self.stack.push(value); f(self, true) } } } - fn read_seq(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); let len = match self.stack.pop() { List(list) => { @@ -1068,12 +1063,12 @@ impl serialize::Decoder for Decoder { f(self, len) } - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) -> T { + fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_seq_elt(idx={})", idx); f(self) } - fn read_map(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); let len = match self.stack.pop() { Object(obj) => { @@ -1089,15 +1084,13 @@ impl serialize::Decoder for Decoder { f(self, len) } - fn read_map_elt_key(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_key(idx={})", idx); f(self) } - fn read_map_elt_val(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_val(idx={})", idx); f(self) @@ -1482,7 +1475,7 @@ mod tests { assert_eq!(a.clone(), from_str(a.to_pretty_str()).unwrap()); } - fn with_str_writer(f: &fn(@mut io::Writer)) -> ~str { + fn with_str_writer(f: |@mut io::Writer|) -> ~str { use std::io::mem::MemWriter; use std::io::Decorator; use std::str; diff --git a/src/libextra/list.rs b/src/libextra/list.rs index 5eada3dfb1a4e..22d273e5747cd 100644 --- a/src/libextra/list.rs +++ b/src/libextra/list.rs @@ -44,7 +44,7 @@ pub fn from_vec(v: &[T]) -> @List { * * z - The initial value * * f - The function to apply */ -pub fn foldl(z: T, ls: @List, f: &fn(&T, &U) -> T) -> T { +pub fn foldl(z: T, ls: @List, f: |&T, &U| -> T) -> T { let mut accum: T = z; do iter(ls) |elt| { accum = f(&accum, elt);} accum @@ -57,7 +57,7 @@ pub fn foldl(z: T, ls: @List, f: &fn(&T, &U) -> T) -> T { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pub fn find(ls: @List, f: &fn(&T) -> bool) -> Option { +pub fn find(ls: @List, f: |&T| -> bool) -> Option { let mut ls = ls; loop { ls = match *ls { @@ -131,7 +131,7 @@ fn push(ll: &mut @list, vv: T) { */ /// Iterate over a list -pub fn iter(l: @List, f: &fn(&T)) { +pub fn iter(l: @List, f: |&T|) { let mut cur = l; loop { cur = match *cur { @@ -145,7 +145,7 @@ pub fn iter(l: @List, f: &fn(&T)) { } /// Iterate over a list -pub fn each(l: @List, f: &fn(&T) -> bool) -> bool { +pub fn each(l: @List, f: |&T| -> bool) -> bool { let mut cur = l; loop { cur = match *cur { @@ -160,7 +160,7 @@ pub fn each(l: @List, f: &fn(&T) -> bool) -> bool { impl MutList { /// Iterate over a mutable list - pub fn each(@mut self, f: &fn(&mut T) -> bool) -> bool { + pub fn each(@mut self, f: |&mut T| -> bool) -> bool { let mut cur = self; loop { let borrowed = &mut *cur; diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index 0ab38cdb5df83..3de71c83c49be 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -145,8 +145,8 @@ condition! { bad_parse: () -> (); } -fn take_nonempty_prefix>(rdr: &mut T, - pred: &fn(char) -> bool) -> (~str, Option) { +fn take_nonempty_prefix>(rdr: &mut T, pred: |char| -> bool) + -> (~str, Option) { let mut buf = ~""; let mut ch = rdr.next(); loop { diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index fb87414c8c364..8e75be651cfa6 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -47,48 +47,48 @@ pub trait Encoder { fn emit_str(&mut self, v: &str); // Compound types: - fn emit_enum(&mut self, name: &str, f: &fn(&mut Self)); + fn emit_enum(&mut self, name: &str, f: |&mut Self|); fn emit_enum_variant(&mut self, v_name: &str, v_id: uint, len: uint, - f: &fn(&mut Self)); - fn emit_enum_variant_arg(&mut self, a_idx: uint, f: &fn(&mut Self)); + f: |&mut Self|); + fn emit_enum_variant_arg(&mut self, a_idx: uint, f: |&mut Self|); fn emit_enum_struct_variant(&mut self, v_name: &str, v_id: uint, len: uint, - f: &fn(&mut Self)); + f: |&mut Self|); fn emit_enum_struct_variant_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self)); + f: |&mut Self|); - fn emit_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self)); + fn emit_struct(&mut self, name: &str, len: uint, f: |&mut Self|); fn emit_struct_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self)); + f: |&mut Self|); - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Self)); - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Self)); + fn emit_tuple(&mut self, len: uint, f: |&mut Self|); + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Self|); - fn emit_tuple_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self)); - fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: &fn(&mut Self)); + fn emit_tuple_struct(&mut self, name: &str, len: uint, f: |&mut Self|); + fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: |&mut Self|); // Specialized types: - fn emit_option(&mut self, f: &fn(&mut Self)); + fn emit_option(&mut self, f: |&mut Self|); fn emit_option_none(&mut self); - fn emit_option_some(&mut self, f: &fn(&mut Self)); + fn emit_option_some(&mut self, f: |&mut Self|); - fn emit_seq(&mut self, len: uint, f: &fn(this: &mut Self)); - fn emit_seq_elt(&mut self, idx: uint, f: &fn(this: &mut Self)); + fn emit_seq(&mut self, len: uint, f: |this: &mut Self|); + fn emit_seq_elt(&mut self, idx: uint, f: |this: &mut Self|); - fn emit_map(&mut self, len: uint, f: &fn(&mut Self)); - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self)); - fn emit_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self)); + fn emit_map(&mut self, len: uint, f: |&mut Self|); + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Self|); + fn emit_map_elt_val(&mut self, idx: uint, f: |&mut Self|); } pub trait Decoder { @@ -111,59 +111,56 @@ pub trait Decoder { fn read_str(&mut self) -> ~str; // Compound types: - fn read_enum(&mut self, name: &str, f: &fn(&mut Self) -> T) -> T; + fn read_enum(&mut self, name: &str, f: |&mut Self| -> T) -> T; fn read_enum_variant(&mut self, names: &[&str], - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_enum_variant_arg(&mut self, a_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; fn read_enum_struct_variant(&mut self, names: &[&str], - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_enum_struct_variant_field(&mut self, &f_name: &str, f_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; - fn read_struct(&mut self, - s_name: &str, - len: uint, - f: &fn(&mut Self) -> T) + fn read_struct(&mut self, s_name: &str, len: uint, f: |&mut Self| -> T) -> T; fn read_struct_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; - fn read_tuple(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_tuple_arg(&mut self, a_idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_tuple(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_tuple_arg(&mut self, a_idx: uint, f: |&mut Self| -> T) -> T; fn read_tuple_struct(&mut self, s_name: &str, - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_tuple_struct_arg(&mut self, a_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; // Specialized types: - fn read_option(&mut self, f: &fn(&mut Self, bool) -> T) -> T; + fn read_option(&mut self, f: |&mut Self, bool| -> T) -> T; - fn read_seq(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_seq(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_seq_elt(&mut self, idx: uint, f: |&mut Self| -> T) -> T; - fn read_map(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; - fn read_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_map(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Self| -> T) -> T; + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Self| -> T) -> T; } pub trait Encodable { @@ -892,11 +889,11 @@ impl< // In some cases, these should eventually be coded as traits. pub trait EncoderHelpers { - fn emit_from_vec(&mut self, v: &[T], f: &fn(&mut Self, v: &T)); + fn emit_from_vec(&mut self, v: &[T], f: |&mut Self, v: &T|); } impl EncoderHelpers for S { - fn emit_from_vec(&mut self, v: &[T], f: &fn(&mut S, &T)) { + fn emit_from_vec(&mut self, v: &[T], f: |&mut S, &T|) { do self.emit_seq(v.len()) |this| { for (i, e) in v.iter().enumerate() { do this.emit_seq_elt(i) |this| { @@ -908,11 +905,11 @@ impl EncoderHelpers for S { } pub trait DecoderHelpers { - fn read_to_vec(&mut self, f: &fn(&mut Self) -> T) -> ~[T]; + fn read_to_vec(&mut self, f: |&mut Self| -> T) -> ~[T]; } impl DecoderHelpers for D { - fn read_to_vec(&mut self, f: &fn(&mut D) -> T) -> ~[T] { + fn read_to_vec(&mut self, f: |&mut D| -> T) -> ~[T] { do self.read_seq |this, len| { do vec::from_fn(len) |i| { this.read_seq_elt(i, |this| f(this)) diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 0ca0ff66039d8..119988735a75e 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -164,8 +164,11 @@ impl SmallIntMap { } impl SmallIntMap { - pub fn update_with_key(&mut self, key: uint, val: V, - ff: &fn(uint, V, V) -> V) -> bool { + pub fn update_with_key(&mut self, + key: uint, + val: V, + ff: |uint, V, V| -> V) + -> bool { let new_val = match self.find(&key) { None => val, Some(orig) => ff(key, (*orig).clone(), val) @@ -173,8 +176,7 @@ impl SmallIntMap { self.insert(key, new_val) } - pub fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) - -> bool { + pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool { self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) } } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 1988da2b0bafc..f01eb7ef2afe9 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -133,7 +133,7 @@ impl Sem { } } - pub fn access(&self, blk: &fn() -> U) -> U { + pub fn access(&self, blk: || -> U) -> U { do task::unkillable { do (|| { self.acquire(); @@ -305,8 +305,12 @@ impl<'self> Condvar<'self> { // something else next on success. #[inline] #[doc(hidden)] -fn check_cvar_bounds(out_of_bounds: Option, id: uint, act: &str, - blk: &fn() -> U) -> U { +fn check_cvar_bounds( + out_of_bounds: Option, + id: uint, + act: &str, + blk: || -> U) + -> U { match out_of_bounds { Some(0) => fail!("{} with illegal ID {} - this lock has no condvars!", act, id), @@ -320,7 +324,7 @@ fn check_cvar_bounds(out_of_bounds: Option, id: uint, act: &str, impl Sem<~[WaitQueue]> { // The only other places that condvars get built are rwlock.write_cond() // and rwlock_write_mode. - pub fn access_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn access_cond(&self, blk: |c: &Condvar| -> U) -> U { do self.access { blk(&Condvar { sem: self, order: Nothing, token: NonCopyable::new() }) } @@ -361,7 +365,7 @@ impl Semaphore { pub fn release(&self) { (&self.sem).release() } /// Run a function with ownership of one of the semaphore's resources. - pub fn access(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } + pub fn access(&self, blk: || -> U) -> U { (&self.sem).access(blk) } } /**************************************************************************** @@ -399,12 +403,12 @@ impl Mutex { /// Run a function with ownership of the mutex. - pub fn lock(&self, blk: &fn() -> U) -> U { + pub fn lock(&self, blk: || -> U) -> U { (&self.sem).access(blk) } /// Run a function with ownership of the mutex and a handle to a condvar. - pub fn lock_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn lock_cond(&self, blk: |c: &Condvar| -> U) -> U { (&self.sem).access_cond(blk) } } @@ -478,7 +482,7 @@ impl RWLock { * Run a function with the rwlock in read mode. Calls to 'read' from other * tasks may run concurrently with this one. */ - pub fn read(&self, blk: &fn() -> U) -> U { + pub fn read(&self, blk: || -> U) -> U { unsafe { do task::unkillable { do (&self.order_lock).access { @@ -513,7 +517,7 @@ impl RWLock { * Run a function with the rwlock in write mode. No calls to 'read' or * 'write' from other tasks will run concurrently with this one. */ - pub fn write(&self, blk: &fn() -> U) -> U { + pub fn write(&self, blk: || -> U) -> U { do task::unkillable { (&self.order_lock).acquire(); do (&self.access_lock).access { @@ -531,7 +535,7 @@ impl RWLock { * the waiting task is signalled. (Note: a writer that waited and then * was signalled might reacquire the lock before other waiting writers.) */ - pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: |c: &Condvar| -> U) -> U { // It's important to thread our order lock into the condvar, so that // when a cond.wait() wakes up, it uses it while reacquiring the // access lock. If we permitted a waking-up writer to "cut in line", @@ -592,7 +596,7 @@ impl RWLock { * } * ``` */ - pub fn write_downgrade(&self, blk: &fn(v: RWLockWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: |v: RWLockWriteMode| -> U) -> U { // Implementation slightly different from the slicker 'write's above. // The exit path is conditional on whether the caller downgrades. do task::unkillable { @@ -671,9 +675,9 @@ pub struct RWLockReadMode<'self> { priv lock: &'self RWLock, impl<'self> RWLockWriteMode<'self> { /// Access the pre-downgrade rwlock in write mode. - pub fn write(&self, blk: &fn() -> U) -> U { blk() } + pub fn write(&self, blk: || -> U) -> U { blk() } /// Access the pre-downgrade rwlock in write mode with a condvar. - pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: |c: &Condvar| -> U) -> U { // Need to make the condvar use the order lock when reacquiring the // access lock. See comment in RWLock::write_cond for why. blk(&Condvar { sem: &self.lock.access_lock, @@ -684,7 +688,7 @@ impl<'self> RWLockWriteMode<'self> { impl<'self> RWLockReadMode<'self> { /// Access the post-downgrade rwlock in read mode. - pub fn read(&self, blk: &fn() -> U) -> U { blk() } + pub fn read(&self, blk: || -> U) -> U { blk() } } /**************************************************************************** @@ -1060,7 +1064,7 @@ mod tests { #[cfg(test)] pub enum RWLockMode { Read, Write, Downgrade, DowngradeRead } #[cfg(test)] - fn lock_rwlock_in_mode(x: &RWLock, mode: RWLockMode, blk: &fn()) { + fn lock_rwlock_in_mode(x: &RWLock, mode: RWLockMode, blk: ||) { match mode { Read => x.read(blk), Write => x.write(blk), @@ -1221,7 +1225,7 @@ mod tests { dg1: bool, dg2: bool) { // Much like the mutex broadcast test. Downgrade-enabled. - fn lock_cond(x: &RWLock, downgrade: bool, blk: &fn(c: &Condvar)) { + fn lock_cond(x: &RWLock, downgrade: bool, blk: |c: &Condvar|) { if downgrade { do x.write_downgrade |mode| { do mode.write_cond |c| { blk(c) } diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 64fb954764a83..37deba43e3a15 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -49,7 +49,7 @@ impl TaskPool { /// local data to be kept around in that task. pub fn new(n_tasks: uint, opt_sched_mode: Option, - init_fn_factory: &fn() -> proc(uint) -> T) + init_fn_factory: || -> proc(uint) -> T) -> TaskPool { assert!(n_tasks >= 1); @@ -97,7 +97,7 @@ impl TaskPool { #[test] fn test_task_pool() { - let f: &fn() -> proc(uint) -> uint = || { + let f: || -> proc(uint) -> uint = || { let g: proc(uint) -> uint = |i| i; g }; diff --git a/src/libextra/test.rs b/src/libextra/test.rs index acb3d538c982a..e9f38471d4862 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -715,8 +715,7 @@ type MonitorMsg = (TestDesc, TestResult); fn run_tests(opts: &TestOpts, tests: ~[TestDescAndFn], - callback: &fn(e: TestEvent)) { - + callback: |e: TestEvent|) { let filtered_tests = filter_tests(opts, tests); let filtered_descs = filtered_tests.map(|t| t.desc.clone()); @@ -1058,7 +1057,7 @@ impl MetricMap { impl BenchHarness { /// Callback for benchmark functions to run in their body. - pub fn iter(&mut self, inner:&fn()) { + pub fn iter(&mut self, inner: ||) { self.ns_start = precise_time_ns(); let k = self.iterations; for _ in range(0u64, k) { @@ -1083,7 +1082,7 @@ impl BenchHarness { } } - pub fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) { + pub fn bench_n(&mut self, n: u64, f: |&mut BenchHarness|) { self.iterations = n; debug!("running benchmark for {} iterations", n as uint); @@ -1091,7 +1090,7 @@ impl BenchHarness { } // This is a more statistics-driven benchmark algorithm - pub fn auto_bench(&mut self, f: &fn(&mut BenchHarness)) -> stats::Summary { + pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary { // Initial bench run to get ballpark figure. let mut n = 1_u64; @@ -1161,8 +1160,7 @@ impl BenchHarness { pub mod bench { use test::{BenchHarness, BenchSamples}; - pub fn benchmark(f: &fn(&mut BenchHarness)) -> BenchSamples { - + pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples { let mut bs = BenchHarness { iterations: 0, ns_start: 0, diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index db5b12f021e5f..a19f501010e89 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -136,7 +136,7 @@ impl TreeMap { pub fn new() -> TreeMap { TreeMap{root: None, length: 0} } /// Iterate over the map and mutate the contained values - pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool { + pub fn mutate_values(&mut self, f: |&K, &mut V| -> bool) -> bool { mutate_values(&mut self.root, f) } @@ -678,9 +678,12 @@ impl TreeNode { } } -fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, - f: &fn(&'r K, &'r mut V) -> bool) - -> bool { +fn mutate_values<'r, + K:TotalOrd, + V>( + node: &'r mut Option<~TreeNode>, + f: |&'r K, &'r mut V| -> bool) + -> bool { match *node { Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left, right: ref mut right, _}) => { @@ -1400,8 +1403,10 @@ mod test_set { } } - fn check(a: &[int], b: &[int], expected: &[int], - f: &fn(&TreeSet, &TreeSet, f: &fn(&int) -> bool) -> bool) { + fn check(a: &[int], + b: &[int], + expected: &[int], + f: |&TreeSet, &TreeSet, f: |&int| -> bool| -> bool) { let mut set_a = TreeSet::new(); let mut set_b = TreeSet::new(); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 7ea7b513f4bd1..09f95800b3dc1 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -295,7 +295,12 @@ impl Context { Prep::new(self, fn_name) } - pub fn with_prep<'a, T>(&'a self, fn_name: &'a str, blk: &fn(p: &mut Prep) -> T) -> T { + pub fn with_prep<'a, + T>( + &'a self, + fn_name: &'a str, + blk: |p: &mut Prep| -> T) + -> T { let mut p = self.prep(fn_name); blk(&mut p) } diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index d08127501b4d2..f752b68fea5fe 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -386,8 +386,7 @@ pub fn basic_options() -> @options { } // Seems out of place, but it uses session, so I'm putting it here -pub fn expect(sess: Session, opt: Option, msg: &fn() -> ~str) - -> T { +pub fn expect(sess: Session, opt: Option, msg: || -> ~str) -> T { diagnostic::expect(sess.diagnostic(), opt, msg) } diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index c11208b0d3eb3..296e8578cbe7c 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -42,7 +42,7 @@ impl<'self> fold::ast_fold for Context<'self> { } pub fn strip_items(crate: ast::Crate, - in_cfg: &fn(attrs: &[ast::Attribute]) -> bool) + in_cfg: |attrs: &[ast::Attribute]| -> bool) -> ast::Crate { let ctxt = Context { in_cfg: in_cfg, diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index fdda6b38462e3..9c9dba524534b 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -44,7 +44,8 @@ pub fn get_type_param_count(cstore: @mut cstore::CStore, def: ast::DefId) /// Iterates over all the language items in the given crate. pub fn each_lang_item(cstore: @mut cstore::CStore, cnum: ast::CrateNum, - f: &fn(ast::NodeId, uint) -> bool) -> bool { + f: |ast::NodeId, uint| -> bool) + -> bool { let crate_data = cstore::get_crate_data(cstore, cnum); decoder::each_lang_item(crate_data, f) } @@ -52,8 +53,9 @@ pub fn each_lang_item(cstore: @mut cstore::CStore, /// Iterates over each child of the given item. pub fn each_child_of_item(cstore: @mut cstore::CStore, def_id: ast::DefId, - callback: &fn(decoder::DefLike, ast::Ident, - ast::visibility)) { + callback: |decoder::DefLike, + ast::Ident, + ast::visibility|) { let crate_data = cstore::get_crate_data(cstore, def_id.crate); let get_crate_data: decoder::GetCrateDataCb = |cnum| { cstore::get_crate_data(cstore, cnum) @@ -68,9 +70,9 @@ pub fn each_child_of_item(cstore: @mut cstore::CStore, /// Iterates over each top-level crate item. pub fn each_top_level_item_of_crate(cstore: @mut cstore::CStore, cnum: ast::CrateNum, - callback: &fn(decoder::DefLike, - ast::Ident, - ast::visibility)) { + callback: |decoder::DefLike, + ast::Ident, + ast::visibility|) { let crate_data = cstore::get_crate_data(cstore, cnum); let get_crate_data: decoder::GetCrateDataCb = |cnum| { cstore::get_crate_data(cstore, cnum) @@ -178,7 +180,7 @@ pub fn get_static_methods_if_impl(cstore: @mut cstore::CStore, pub fn get_item_attrs(cstore: @mut cstore::CStore, def_id: ast::DefId, - f: &fn(~[@ast::MetaItem])) { + f: |~[@ast::MetaItem]|) { let cdata = cstore::get_crate_data(cstore, def_id.crate); decoder::get_item_attrs(cdata, def_id.node, f) } @@ -262,21 +264,21 @@ pub fn get_item_visibility(cstore: @mut cstore::CStore, pub fn each_impl(cstore: @mut cstore::CStore, crate_num: ast::CrateNum, - callback: &fn(ast::DefId)) { + callback: |ast::DefId|) { let cdata = cstore::get_crate_data(cstore, crate_num); decoder::each_impl(cdata, callback) } pub fn each_implementation_for_type(cstore: @mut cstore::CStore, def_id: ast::DefId, - callback: &fn(ast::DefId)) { + callback: |ast::DefId|) { let cdata = cstore::get_crate_data(cstore, def_id.crate); decoder::each_implementation_for_type(cdata, def_id.node, callback) } pub fn each_implementation_for_trait(cstore: @mut cstore::CStore, def_id: ast::DefId, - callback: &fn(ast::DefId)) { + callback: |ast::DefId|) { let cdata = cstore::get_crate_data(cstore, def_id.crate); decoder::each_implementation_for_trait(cdata, def_id.node, callback) } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 3c79ea2fe5e3f..135d1ac8ac047 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -82,8 +82,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::CrateNum) -> bool { cstore.metas.contains_key(&cnum) } -pub fn iter_crate_data(cstore: &CStore, - i: &fn(ast::CrateNum, @crate_metadata)) { +pub fn iter_crate_data(cstore: &CStore, i: |ast::CrateNum, @crate_metadata|) { for (&k, &v) in cstore.metas.iter() { i(k, v); } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 0680968703f94..fbe3d7bbe9eea 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -51,7 +51,7 @@ type Cmd = @crate_metadata; // what crate that's in and give us a def_id that makes sense for the current // build. -fn lookup_hash(d: ebml::Doc, eq_fn: &fn(x:&[u8]) -> bool, hash: u64) -> +fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) -> Option { let index = reader::get_doc(d, tag_index); let table = reader::get_doc(index, tag_index_table); @@ -205,7 +205,7 @@ fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option { } } -fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) -> bool { +fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool { reader::tagged_docs(d, tag_items_data_item_reexport, f) } @@ -509,7 +509,7 @@ pub fn def_like_to_def(def_like: DefLike) -> ast::Def { } /// Iterates over the language items in the given crate. -pub fn each_lang_item(cdata: Cmd, f: &fn(ast::NodeId, uint) -> bool) -> bool { +pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { let root = reader::Doc(cdata.data); let lang_items = reader::get_doc(root, tag_lang_items); do reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| { @@ -733,8 +733,9 @@ fn each_child_of_item_or_crate(intr: @ident_interner, cdata: Cmd, item_doc: ebml::Doc, get_crate_data: GetCrateDataCb, - callback: &fn(DefLike, ast::Ident, - ast::visibility)) { + callback: |DefLike, + ast::Ident, + ast::visibility|) { // Iterate over all children. let _ = do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| { let child_def_id = reader::with_doc_data(child_info_doc, @@ -861,7 +862,7 @@ pub fn each_child_of_item(intr: @ident_interner, cdata: Cmd, id: ast::NodeId, get_crate_data: GetCrateDataCb, - callback: &fn(DefLike, ast::Ident, ast::visibility)) { + callback: |DefLike, ast::Ident, ast::visibility|) { // Find the item. let root_doc = reader::Doc(cdata.data); let items = reader::get_doc(root_doc, tag_items); @@ -881,8 +882,9 @@ pub fn each_child_of_item(intr: @ident_interner, pub fn each_top_level_item_of_crate(intr: @ident_interner, cdata: Cmd, get_crate_data: GetCrateDataCb, - callback: &fn(DefLike, ast::Ident, - ast::visibility)) { + callback: |DefLike, + ast::Ident, + ast::visibility|) { let root_doc = reader::Doc(cdata.data); let misc_info_doc = reader::get_doc(root_doc, tag_misc_info); let crate_items_doc = reader::get_doc(misc_info_doc, @@ -1201,8 +1203,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner, pub fn get_item_attrs(cdata: Cmd, node_id: ast::NodeId, - f: &fn(~[@ast::MetaItem])) { - + f: |~[@ast::MetaItem]|) { let item = lookup_item(node_id, cdata.data); do reader::tagged_docs(item, tag_attributes) |attributes| { do reader::tagged_docs(attributes, tag_attribute) |attribute| { @@ -1474,7 +1475,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { } } -pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) { +pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) { let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls); let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| { callback(item_def_id(impl_doc, cdata)); @@ -1484,7 +1485,7 @@ pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) { pub fn each_implementation_for_type(cdata: Cmd, id: ast::NodeId, - callback: &fn(ast::DefId)) { + callback: |ast::DefId|) { let item_doc = lookup_item(id, cdata.data); do reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl) |impl_doc| { @@ -1496,7 +1497,7 @@ pub fn each_implementation_for_type(cdata: Cmd, pub fn each_implementation_for_trait(cdata: Cmd, id: ast::NodeId, - callback: &fn(ast::DefId)) { + callback: |ast::DefId|) { let item_doc = lookup_item(id, cdata.data); let _ = do reader::tagged_docs(item_doc, diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index be45bf81867fc..340a4241da23b 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -535,8 +535,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, /// * For enums, iterates through the node IDs of the variants. /// /// * For newtype structs, iterates through the node ID of the constructor. -fn each_auxiliary_node_id(item: @item, callback: &fn(NodeId) -> bool) - -> bool { +fn each_auxiliary_node_id(item: @item, callback: |NodeId| -> bool) -> bool { let mut continue_ = true; match item.node { item_enum(ref enum_def, _) => { @@ -912,7 +911,7 @@ fn encode_info_for_item(ecx: &EncodeContext, index: @mut ~[entry]) { index.push(entry { val: item.id as i64, pos: ebml_w.writer.tell() }); } - let add_to_index: &fn() = || add_to_index(item, ebml_w, index); + let add_to_index: || = || add_to_index(item, ebml_w, index); debug!("encoding info for item at {}", ecx.tcx.sess.codemap.span_to_str(item.span)); @@ -1412,7 +1411,7 @@ fn create_index( fn encode_index( ebml_w: &mut writer::Encoder, buckets: ~[@~[entry]], - write_fn: &fn(@mut MemWriter, &T)) { + write_fn: |@mut MemWriter, &T|) { ebml_w.start_tag(tag_index); let mut bucket_locs = ~[]; ebml_w.start_tag(tag_index_buckets); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 237c50ab29410..32beb4bbaf375 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -35,7 +35,7 @@ pub fn pick_file(file: Path, path: &Path) -> Option { pub trait FileSearch { fn sysroot(&self) -> @Path; - fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch); + fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch); fn get_target_lib_path(&self) -> Path; fn get_target_lib_file_path(&self, file: &Path) -> Path; } @@ -51,7 +51,8 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>, } impl FileSearch for FileSearchImpl { fn sysroot(&self) -> @Path { self.sysroot } - fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch) { + + fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) { let mut visited_dirs = HashSet::new(); let mut found = false; diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 31561e730d541..281998b081146 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -79,9 +79,7 @@ fn next_byte(st: &mut PState) -> u8 { return b; } -fn scan(st: &mut PState, is_last: &fn(char) -> bool, - op: &fn(&[u8]) -> R) -> R -{ +fn scan(st: &mut PState, is_last: |char| -> bool, op: |&[u8]| -> R) -> R { let start_pos = st.pos; debug!("scan: '{}' (start)", st.data[st.pos] as char); while !is_last(st.data[st.pos] as char) { @@ -98,7 +96,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident { return parse_ident_(st, |a| is_last(last, a) ); } -fn parse_ident_(st: &mut PState, is_last: &fn(char) -> bool) -> ast::Ident { +fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident { let rslt = scan(st, is_last, str::from_utf8); return st.tcx.sess.ident_of(rslt); } @@ -292,7 +290,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region { } } -fn parse_opt(st: &mut PState, f: &fn(&mut PState) -> T) -> Option { +fn parse_opt(st: &mut PState, f: |&mut PState| -> T) -> Option { match next(st) { 'n' => None, 's' => Some(f(st)), diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 49afb29488d9d..f1207b07ada89 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -120,7 +120,7 @@ fn enc_mt(w: @mut MemWriter, cx: @ctxt, mt: ty::mt) { enc_ty(w, cx, mt.ty); } -fn enc_opt(w: @mut MemWriter, t: Option, enc_f: &fn(T)) { +fn enc_opt(w: @mut MemWriter, t: Option, enc_f: |T|) { match t { None => mywrite!(w, "n"), Some(v) => { diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 97d46cd3a0b17..7f8816bd6137d 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -845,14 +845,12 @@ impl ebml_writer_helpers for writer::Encoder { } trait write_tag_and_id { - fn tag(&mut self, tag_id: c::astencode_tag, f: &fn(&mut Self)); + fn tag(&mut self, tag_id: c::astencode_tag, f: |&mut Self|); fn id(&mut self, id: ast::NodeId); } impl write_tag_and_id for writer::Encoder { - fn tag(&mut self, - tag_id: c::astencode_tag, - f: &fn(&mut writer::Encoder)) { + fn tag(&mut self, tag_id: c::astencode_tag, f: |&mut writer::Encoder|) { self.start_tag(tag_id as uint); f(self); self.end_tag(); diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 77dec4ede1080..d6aec7738a161 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -124,9 +124,7 @@ impl<'self> CheckLoanCtxt<'self> { pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx } - pub fn each_issued_loan(&self, - scope_id: ast::NodeId, - op: &fn(&Loan) -> bool) + pub fn each_issued_loan(&self, scope_id: ast::NodeId, op: |&Loan| -> bool) -> bool { //! Iterates over each loan that has been issued //! on entrance to `scope_id`, regardless of whether it is @@ -142,7 +140,7 @@ impl<'self> CheckLoanCtxt<'self> { pub fn each_in_scope_loan(&self, scope_id: ast::NodeId, - op: &fn(&Loan) -> bool) + op: |&Loan| -> bool) -> bool { //! Like `each_issued_loan()`, but only considers loans that are //! currently in scope. @@ -160,7 +158,7 @@ impl<'self> CheckLoanCtxt<'self> { pub fn each_in_scope_restriction(&self, scope_id: ast::NodeId, loan_path: @LoanPath, - op: &fn(&Loan, &Restriction) -> bool) + op: |&Loan, &Restriction| -> bool) -> bool { //! Iterates through all the in-scope restrictions for the //! given `loan_path` diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 55daff90e62e2..ef2c172acdf22 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -533,7 +533,7 @@ impl BorrowckCtxt { pub fn cat_pattern(&self, cmt: mc::cmt, pat: @ast::Pat, - op: &fn(mc::cmt, @ast::Pat)) { + op: |mc::cmt, @ast::Pat|) { let mc = self.mc_ctxt(); mc.cat_pattern(cmt, pat, op); } diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index e031420996789..a0a9ba11db2f0 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -412,9 +412,7 @@ impl MoveData { } } - fn each_base_path(&self, - index: MovePathIndex, - f: &fn(MovePathIndex) -> bool) + fn each_base_path(&self, index: MovePathIndex, f: |MovePathIndex| -> bool) -> bool { let mut p = index; while p != InvalidMovePathIndex { @@ -428,7 +426,8 @@ impl MoveData { fn each_extending_path(&self, index: MovePathIndex, - f: &fn(MovePathIndex) -> bool) -> bool { + f: |MovePathIndex| -> bool) + -> bool { if !f(index) { return false; } @@ -446,7 +445,8 @@ impl MoveData { fn each_applicable_move(&self, index0: MovePathIndex, - f: &fn(MoveIndex) -> bool) -> bool { + f: |MoveIndex| -> bool) + -> bool { let mut ret = true; do self.each_extending_path(index0) |index| { let mut p = self.path(index).first_move; @@ -505,7 +505,7 @@ impl FlowedMoveData { pub fn each_path_moved_by(&self, id: ast::NodeId, - f: &fn(&Move, @LoanPath) -> bool) + f: |&Move, @LoanPath| -> bool) -> bool { /*! * Iterates through each path moved by `id` @@ -521,7 +521,7 @@ impl FlowedMoveData { pub fn each_move_of(&self, id: ast::NodeId, loan_path: @LoanPath, - f: &fn(&Move, @LoanPath) -> bool) + f: |&Move, @LoanPath| -> bool) -> bool { /*! * Iterates through each move of `loan_path` (or some base path @@ -587,7 +587,7 @@ impl FlowedMoveData { pub fn each_assignment_of(&self, id: ast::NodeId, loan_path: @LoanPath, - f: &fn(&Assignment) -> bool) + f: |&Assignment| -> bool) -> bool { /*! * Iterates through every assignment to `loan_path` that diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 3885ebfc4b652..04d6266d405f0 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -121,7 +121,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) { for pat in arm.pats.iter() { // Check that we do not match against a static NaN (#6804) - let pat_matches_nan: &fn(&Pat) -> bool = |p| { + let pat_matches_nan: |&Pat| -> bool = |p| { match cx.tcx.def_map.find(&p.id) { Some(&DefStatic(did, false)) => { let const_expr = lookup_const_by_id(cx.tcx, did).unwrap(); @@ -900,7 +900,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, } } - let check_move: &fn(&Pat, Option<@Pat>) = |p, sub| { + let check_move: |&Pat, Option<@Pat>| = |p, sub| { // check legality of moving out of the enum // x @ Foo(*) is legal, but x @ Foo(y) isn't. diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 6b46da0621127..96970e13fcbc3 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -234,7 +234,8 @@ impl DataFlowContext { pub fn each_bit_on_entry_frozen(&self, id: ast::NodeId, - f: &fn(uint) -> bool) -> bool { + f: |uint| -> bool) + -> bool { //! Iterates through each bit that is set on entry to `id`. //! Only useful after `propagate()` has been called. if !self.nodeid_to_bitset.contains_key(&id) { @@ -249,7 +250,8 @@ impl DataFlowContext { pub fn each_bit_on_entry(&mut self, id: ast::NodeId, - f: &fn(uint) -> bool) -> bool { + f: |uint| -> bool) + -> bool { //! Iterates through each bit that is set on entry to `id`. //! Only useful after `propagate()` has been called. @@ -260,9 +262,8 @@ impl DataFlowContext { self.each_bit(on_entry, f) } - pub fn each_gen_bit(&mut self, - id: ast::NodeId, - f: &fn(uint) -> bool) -> bool { + pub fn each_gen_bit(&mut self, id: ast::NodeId, f: |uint| -> bool) + -> bool { //! Iterates through each bit in the gen set for `id`. let (start, end) = self.compute_id_range(id); @@ -272,9 +273,8 @@ impl DataFlowContext { self.each_bit(gens, f) } - pub fn each_gen_bit_frozen(&self, - id: ast::NodeId, - f: &fn(uint) -> bool) -> bool { + pub fn each_gen_bit_frozen(&self, id: ast::NodeId, f: |uint| -> bool) + -> bool { //! Iterates through each bit in the gen set for `id`. if !self.nodeid_to_bitset.contains_key(&id) { return true; @@ -286,9 +286,7 @@ impl DataFlowContext { self.each_bit(gens, f) } - fn each_bit(&self, - words: &[uint], - f: &fn(uint) -> bool) -> bool { + fn each_bit(&self, words: &[uint], f: |uint| -> bool) -> bool { //! Helper for iterating over the bits in a bit set. for (word_index, &word) in words.iter().enumerate() { @@ -978,9 +976,8 @@ fn join_bits(oper: &O, } #[inline] -fn bitwise(out_vec: &mut [uint], - in_vec: &[uint], - op: &fn(uint, uint) -> uint) -> bool { +fn bitwise(out_vec: &mut [uint], in_vec: &[uint], op: |uint, uint| -> uint) + -> bool { assert_eq!(out_vec.len(), in_vec.len()); let mut changed = false; for (out_elt, in_elt) in out_vec.mut_iter().zip(in_vec.iter()) { diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 87dce84d23dc5..7a842364d1e33 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -185,19 +185,20 @@ impl Graph { /////////////////////////////////////////////////////////////////////////// // Iterating over nodes, edges - pub fn each_node(&self, f: &fn(NodeIndex, &Node) -> bool) -> bool { + pub fn each_node(&self, f: |NodeIndex, &Node| -> bool) -> bool { //! Iterates over all edges defined in the graph. self.nodes.iter().enumerate().advance(|(i, node)| f(NodeIndex(i), node)) } - pub fn each_edge(&self, f: &fn(EdgeIndex, &Edge) -> bool) -> bool { + pub fn each_edge(&self, f: |EdgeIndex, &Edge| -> bool) -> bool { //! Iterates over all edges defined in the graph self.edges.iter().enumerate().advance(|(i, edge)| f(EdgeIndex(i), edge)) } pub fn each_outgoing_edge(&self, source: NodeIndex, - f: &fn(EdgeIndex, &Edge) -> bool) -> bool { + f: |EdgeIndex, &Edge| -> bool) + -> bool { //! Iterates over all outgoing edges from the node `from` self.each_adjacent_edge(source, Outgoing, f) @@ -205,7 +206,8 @@ impl Graph { pub fn each_incoming_edge(&self, target: NodeIndex, - f: &fn(EdgeIndex, &Edge) -> bool) -> bool { + f: |EdgeIndex, &Edge| -> bool) + -> bool { //! Iterates over all incoming edges to the node `target` self.each_adjacent_edge(target, Incoming, f) @@ -214,7 +216,8 @@ impl Graph { pub fn each_adjacent_edge(&self, node: NodeIndex, dir: Direction, - f: &fn(EdgeIndex, &Edge) -> bool) -> bool { + f: |EdgeIndex, &Edge| -> bool) + -> bool { //! Iterates over all edges adjacent to the node `node` //! in the direction `dir` (either `Outgoing` or `Incoming) @@ -239,9 +242,10 @@ impl Graph { // computation. pub fn iterate_until_fixed_point(&self, - op: &fn(iter_index: uint, - edge_index: EdgeIndex, - edge: &Edge) -> bool) { + op: |iter_index: uint, + edge_index: EdgeIndex, + edge: &Edge| + -> bool) { let mut iteration = 0; let mut changed = true; while changed { @@ -254,7 +258,7 @@ impl Graph { } } -pub fn each_edge_index(max_edge_index: EdgeIndex, f: &fn(EdgeIndex) -> bool) { +pub fn each_edge_index(max_edge_index: EdgeIndex, f: |EdgeIndex| -> bool) { let mut i = 0; let n = *max_edge_index; while i < n { diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index a570160ce9572..b6b1516d05a02 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -167,8 +167,9 @@ fn check_item(cx: &mut Context, item: @item) { // Yields the appropriate function to check the kind of closed over // variables. `id` is the NodeId for some expression that creates the // closure. -fn with_appropriate_checker(cx: &Context, id: NodeId, - b: &fn(checker: &fn(&Context, @freevar_entry))) { +fn with_appropriate_checker(cx: &Context, + id: NodeId, + b: |checker: |&Context, @freevar_entry||) { fn check_for_uniq(cx: &Context, fv: &freevar_entry, bounds: ty::BuiltinBounds) { // all captured data must be owned, regardless of whether it is // moved in or copied in. @@ -351,9 +352,10 @@ fn check_ty(cx: &mut Context, aty: &Ty) { } // Calls "any_missing" if any bounds were missing. -pub fn check_builtin_bounds(cx: &Context, ty: ty::t, bounds: ty::BuiltinBounds, - any_missing: &fn(ty::BuiltinBounds)) -{ +pub fn check_builtin_bounds(cx: &Context, + ty: ty::t, + bounds: ty::BuiltinBounds, + any_missing: |ty::BuiltinBounds|) { let kind = ty::type_contents(cx.tcx, ty); let mut missing = ty::EmptyBuiltinBounds(); for bound in bounds.iter() { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 9395ebefe8725..24e76709ff50d 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -417,8 +417,9 @@ impl<'self> Context<'self> { * current lint context, call the provided function, then reset the * lints in effect to their previous state. */ - fn with_lint_attrs(&mut self, attrs: &[ast::Attribute], - f: &fn(&mut Context)) { + fn with_lint_attrs(&mut self, + attrs: &[ast::Attribute], + f: |&mut Context|) { // Parse all of the lint attributes, and then add them all to the // current dictionary of lint information. Along the way, keep a history // of what we changed so we can roll everything back after invoking the @@ -468,7 +469,7 @@ impl<'self> Context<'self> { } } - fn visit_ids(&self, f: &fn(&mut ast_util::IdVisitor)) { + fn visit_ids(&self, f: |&mut ast_util::IdVisitor|) { let mut v = ast_util::IdVisitor { operation: self, pass_through_items: false, @@ -480,7 +481,8 @@ impl<'self> Context<'self> { pub fn each_lint(sess: session::Session, attrs: &[ast::Attribute], - f: &fn(@ast::MetaItem, level, @str) -> bool) -> bool { + f: |@ast::MetaItem, level, @str| -> bool) + -> bool { let xs = [allow, warn, deny, forbid]; for &level in xs.iter() { let level_name = level_to_str(level); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 05c154c5c8d53..3220ab08ede44 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -657,7 +657,7 @@ impl Liveness { pub fn pat_bindings(&self, pat: @Pat, - f: &fn(LiveNode, Variable, Span, NodeId)) { + f: |LiveNode, Variable, Span, NodeId|) { let def_map = self.tcx.def_map; do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); @@ -668,7 +668,7 @@ impl Liveness { pub fn arm_pats_bindings(&self, pats: &[@Pat], - f: &fn(LiveNode, Variable, Span, NodeId)) { + f: |LiveNode, Variable, Span, NodeId|) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoratative" set of ids @@ -729,7 +729,7 @@ impl Liveness { self.assigned_on_entry(self.successors[*ln], var) } - pub fn indices(&self, ln: LiveNode, op: &fn(uint)) { + pub fn indices(&self, ln: LiveNode, op: |uint|) { let node_base_idx = self.idx(ln, Variable(0)); for var_idx in range(0u, self.ir.num_vars) { op(node_base_idx + var_idx) @@ -739,7 +739,7 @@ impl Liveness { pub fn indices2(&self, ln: LiveNode, succ_ln: LiveNode, - op: &fn(uint, uint)) { + op: |uint, uint|) { let node_base_idx = self.idx(ln, Variable(0u)); let succ_base_idx = self.idx(succ_ln, Variable(0u)); for var_idx in range(0u, self.ir.num_vars) { @@ -750,7 +750,7 @@ impl Liveness { pub fn write_vars(&self, wr: &mut io::Writer, ln: LiveNode, - test: &fn(uint) -> LiveNode) { + test: |uint| -> LiveNode) { let node_base_idx = self.idx(ln, Variable(0)); for var_idx in range(0u, self.ir.num_vars) { let idx = node_base_idx + var_idx; @@ -1406,12 +1406,13 @@ impl Liveness { cond_ln } - pub fn with_loop_nodes(&self, - loop_node_id: NodeId, - break_ln: LiveNode, - cont_ln: LiveNode, - f: &fn() -> R) - -> R { + pub fn with_loop_nodes( + &self, + loop_node_id: NodeId, + break_ln: LiveNode, + cont_ln: LiveNode, + f: || -> R) + -> R { debug!("with_loop_nodes: {} {}", loop_node_id, *break_ln); self.loop_scope.push(loop_node_id); self.break_ln.insert(loop_node_id, break_ln); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index d8f6641937913..89e19631dae8a 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -63,7 +63,7 @@ pub enum categorization { cat_rvalue(ast::NodeId), // temporary val, argument is its scope cat_static_item, cat_copied_upvar(CopiedUpvar), // upvar copied into @fn or ~fn env - cat_stack_upvar(cmt), // by ref upvar from &fn + cat_stack_upvar(cmt), // by ref upvar from || cat_local(ast::NodeId), // local variable cat_arg(ast::NodeId), // formal argument cat_deref(cmt, uint, PointerKind), // deref of a ptr @@ -822,7 +822,7 @@ impl mem_categorization_ctxt { pub fn cat_pattern(&self, cmt: cmt, pat: @ast::Pat, - op: &fn(cmt, @ast::Pat)) { + op: |cmt, @ast::Pat|) { // Here, `cmt` is the categorization for the value being // matched and pat is the pattern it is being matched against. // diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 36a47578e2700..8493a7e00ddbe 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -148,7 +148,7 @@ use syntax::codemap::Span; pub enum CaptureMode { CapCopy, // Copy the value into the closure. CapMove, // Move the value into the closure. - CapRef, // Reference directly from parent stack frame (used by `&fn()`). + CapRef, // Reference directly from parent stack frame (used by `||`). } #[deriving(Encodable, Decodable)] @@ -686,7 +686,7 @@ impl VisitContext { let sigil = ty::ty_closure_sigil(fn_ty); let freevars = freevars::get_freevars(self.tcx, fn_expr_id); if sigil == BorrowedSigil { - // &fn() captures everything by ref + // || captures everything by ref at_vec::from_fn(freevars.len(), |i| { let fvar = &freevars[i]; CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef} diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 878f0876918f0..6e5cd2e0bf2d8 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -70,8 +70,9 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @Pat) -> bool { } } -pub fn pat_bindings(dm: resolve::DefMap, pat: @Pat, - it: &fn(BindingMode, NodeId, Span, &Path)) { +pub fn pat_bindings(dm: resolve::DefMap, + pat: @Pat, + it: |BindingMode, NodeId, Span, &Path|) { do walk_pat(pat) |p| { match p.node { PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 4861fa19f7e8f..fdf2e170e3256 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1538,10 +1538,10 @@ impl Resolver { /// Constructs the reduced graph for one foreign item. fn build_reduced_graph_for_foreign_item(&mut self, - foreign_item: @foreign_item, - parent: ReducedGraphParent, - f: &fn(&mut Resolver, - ReducedGraphParent)) { + foreign_item: @foreign_item, + parent: ReducedGraphParent, + f: |&mut Resolver, + ReducedGraphParent|) { let name = foreign_item.ident; let is_public = foreign_item.vis == ast::public; let (name_bindings, new_parent) = @@ -3331,7 +3331,7 @@ impl Resolver { // generate a fake "implementation scope" containing all the // implementations thus found, for compatibility with old resolve pass. - fn with_scope(&mut self, name: Option, f: &fn(&mut Resolver)) { + fn with_scope(&mut self, name: Option, f: |&mut Resolver|) { let orig_module = self.current_module; // Move down in the graph. @@ -3692,8 +3692,8 @@ impl Resolver { } fn with_type_parameter_rib(&mut self, - type_parameters: TypeParameters, - f: &fn(&mut Resolver)) { + type_parameters: TypeParameters, + f: |&mut Resolver|) { match type_parameters { HasTypeParameters(generics, node_id, initial_index, rib_kind) => { @@ -3735,13 +3735,13 @@ impl Resolver { } } - fn with_label_rib(&mut self, f: &fn(&mut Resolver)) { + fn with_label_rib(&mut self, f: |&mut Resolver|) { self.label_ribs.push(@Rib::new(NormalRibKind)); f(self); self.label_ribs.pop(); } - fn with_constant_rib(&mut self, f: &fn(&mut Resolver)) { + fn with_constant_rib(&mut self, f: |&mut Resolver|) { self.value_ribs.push(@Rib::new(ConstantItemRibKind)); self.type_ribs.push(@Rib::new(ConstantItemRibKind)); f(self); @@ -4888,7 +4888,7 @@ impl Resolver { } } - fn with_no_errors(&mut self, f: &fn(&mut Resolver) -> T) -> T { + fn with_no_errors(&mut self, f: |&mut Resolver| -> T) -> T { self.emit_errors = false; let rs = f(self); self.emit_errors = true; @@ -4901,10 +4901,8 @@ impl Resolver { } } - fn find_best_match_for_name(&mut self, - name: &str, - max_distance: uint) - -> Option<@str> { + fn find_best_match_for_name(&mut self, name: &str, max_distance: uint) + -> Option<@str> { let this = &mut *self; let mut maybes: ~[@str] = ~[]; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index b48260de766a7..92913983d8659 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -2066,7 +2066,8 @@ fn mk_binding_alloca(mut bcx: @mut Block, p_id: ast::NodeId, path: &ast::Path, binding_mode: IrrefutablePatternBindingMode, - populate: &fn(@mut Block, ty::t, ValueRef) -> @mut Block) -> @mut Block { + populate: |@mut Block, ty::t, ValueRef| -> @mut Block) + -> @mut Block { let var_ty = node_id_type(bcx, p_id); let ident = ast_util::path_to_ident(path); let llval = alloc_ty(bcx, var_ty, bcx.ident(ident)); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 6c1a50031215c..80b3455e9fa76 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -93,7 +93,7 @@ pub use middle::trans::context::task_llcx; local_data_key!(task_local_insn_key: ~[&'static str]) -pub fn with_insn_ctxt(blk: &fn(&[&'static str])) { +pub fn with_insn_ctxt(blk: |&[&'static str]|) { do local_data::get(task_local_insn_key) |c| { match c { Some(ctx) => blk(*ctx), @@ -787,10 +787,11 @@ pub fn cast_shift_const_rhs(op: ast::BinOp, } pub fn cast_shift_rhs(op: ast::BinOp, - lhs: ValueRef, rhs: ValueRef, - trunc: &fn(ValueRef, Type) -> ValueRef, - zext: &fn(ValueRef, Type) -> ValueRef) - -> ValueRef { + lhs: ValueRef, + rhs: ValueRef, + trunc: |ValueRef, Type| -> ValueRef, + zext: |ValueRef, Type| -> ValueRef) + -> ValueRef { // Shifts may have any size int on the rhs unsafe { if ast_util::is_shift_binop(op) { @@ -966,7 +967,7 @@ pub fn have_cached_lpad(bcx: @mut Block) -> bool { return res; } -pub fn in_lpad_scope_cx(bcx: @mut Block, f: &fn(si: &mut ScopeInfo)) { +pub fn in_lpad_scope_cx(bcx: @mut Block, f: |si: &mut ScopeInfo|) { let mut bcx = bcx; let mut cur_scope = bcx.scope; loop { @@ -1430,7 +1431,8 @@ pub fn leave_block(bcx: @mut Block, out_of: @mut Block) -> @mut Block { pub fn with_scope(bcx: @mut Block, opt_node_info: Option, name: &str, - f: &fn(@mut Block) -> @mut Block) -> @mut Block { + f: |@mut Block| -> @mut Block) + -> @mut Block { let _icx = push_ctxt("with_scope"); debug!("with_scope(bcx={}, opt_node_info={:?}, name={})", @@ -1448,7 +1450,8 @@ pub fn with_scope(bcx: @mut Block, pub fn with_scope_result(bcx: @mut Block, opt_node_info: Option, _name: &str, - f: &fn(@mut Block) -> Result) -> Result { + f: |@mut Block| -> Result) + -> Result { let _icx = push_ctxt("with_scope_result"); let scope = simple_block_scope(bcx.scope, opt_node_info); @@ -1462,9 +1465,11 @@ pub fn with_scope_result(bcx: @mut Block, rslt(out_bcx, val) } -pub fn with_scope_datumblock(bcx: @mut Block, opt_node_info: Option, - name: &str, f: &fn(@mut Block) -> datum::DatumBlock) - -> datum::DatumBlock { +pub fn with_scope_datumblock(bcx: @mut Block, + opt_node_info: Option, + name: &str, + f: |@mut Block| -> datum::DatumBlock) + -> datum::DatumBlock { use middle::trans::datum::DatumBlock; let _icx = push_ctxt("with_scope_result"); @@ -1474,7 +1479,7 @@ pub fn with_scope_datumblock(bcx: @mut Block, opt_node_info: Option, DatumBlock {bcx: leave_block(bcx, scope_cx), datum: datum} } -pub fn block_locals(b: &ast::Block, it: &fn(@ast::Local)) { +pub fn block_locals(b: &ast::Block, it: |@ast::Local|) { for s in b.stmts.iter() { match s.node { ast::StmtDecl(d, _) => { @@ -1488,7 +1493,10 @@ pub fn block_locals(b: &ast::Block, it: &fn(@ast::Local)) { } } -pub fn with_cond(bcx: @mut Block, val: ValueRef, f: &fn(@mut Block) -> @mut Block) -> @mut Block { +pub fn with_cond(bcx: @mut Block, + val: ValueRef, + f: |@mut Block| -> @mut Block) + -> @mut Block { let _icx = push_ctxt("with_cond"); let next_cx = base::sub_block(bcx, "next"); let cond_cx = base::sub_block(bcx, "cond"); @@ -1885,7 +1893,7 @@ pub fn trans_closure(ccx: @mut CrateContext, id: ast::NodeId, _attributes: &[ast::Attribute], output_type: ty::t, - maybe_load_env: &fn(@mut FunctionContext)) { + maybe_load_env: |@mut FunctionContext|) { ccx.stats.n_closures += 1; let _icx = push_ctxt("trans_closure"); set_uwtable(llfndecl); diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 1e22c46dd5db5..ebd7bb6937ef4 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -337,9 +337,9 @@ pub fn compute_abi_info(_ccx: &mut CrateContext, rty: Type, ret_def: bool) -> FnType { fn x86_64_ty(ty: Type, - is_mem_cls: &fn(cls: &[RegClass]) -> bool, - attr: Attribute) -> ArgType { - + is_mem_cls: |cls: &[RegClass]| -> bool, + attr: Attribute) + -> ArgType { if !ty.is_reg_ty() { let cls = classify_ty(ty); if is_mem_cls(cls) { diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index ecb53efbad788..d78311c8a398a 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -600,7 +600,7 @@ pub fn trans_call_inner(in_cx: @mut Block, call_info: Option, callee_ty: ty::t, ret_ty: ty::t, - get_callee: &fn(@mut Block) -> Callee, + get_callee: |@mut Block| -> Callee, args: CallArgs, dest: Option, autoref_arg: AutorefArg) diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 9629615c64dd9..baccd9c7028e3 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -51,7 +51,7 @@ use syntax::parse::token::special_idents; // }; // // Note that the closure is itself a rust_opaque_box. This is true -// even for ~fn and &fn, because we wish to keep binary compatibility +// even for ~fn and ||, because we wish to keep binary compatibility // between all kinds of closures. The allocation strategy for this // closure depends on the closure type. For a sendfn, the closure // (and the referenced type descriptors) will be allocated in the @@ -422,11 +422,12 @@ pub fn trans_expr_fn(bcx: @mut Block, return bcx; } -pub fn make_closure_glue( - cx: @mut Block, - v: ValueRef, - t: ty::t, - glue_fn: &fn(@mut Block, v: ValueRef, t: ty::t) -> @mut Block) -> @mut Block { +pub fn make_closure_glue(cx: @mut Block, + v: ValueRef, + t: ty::t, + glue_fn: |@mut Block, v: ValueRef, t: ty::t| + -> @mut Block) + -> @mut Block { let _icx = push_ctxt("closure::make_closure_glue"); let bcx = cx; let tcx = cx.tcx(); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index c002584a7fff9..48602534a3d89 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -769,7 +769,9 @@ pub fn val_ty(v: ValueRef) -> Type { } } -pub fn in_scope_cx(cx: @mut Block, scope_id: Option, f: &fn(si: &mut ScopeInfo)) { +pub fn in_scope_cx(cx: @mut Block, + scope_id: Option, + f: |si: &mut ScopeInfo|) { let mut cur = cx; let mut cur_scope = cur.scope; loop { diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 01cf102275023..1806dee6c8f20 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -524,7 +524,7 @@ impl Datum { bcx: @mut Block, ty: ty::t, source: DatumCleanup, - gep: &fn(ValueRef) -> ValueRef) + gep: |ValueRef| -> ValueRef) -> Datum { let base_val = self.to_ref_llval(bcx); Datum { diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index d4b6295331423..676af30b2eeba 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -2274,9 +2274,9 @@ fn populate_scope_map(cx: &mut CrateContext, scope_span: Span, scope_stack: &mut ~[ScopeStackEntry], scope_map: &mut HashMap, - inner_walk: &fn(&mut CrateContext, - &mut ~[ScopeStackEntry], - &mut HashMap)) { + inner_walk: |&mut CrateContext, + &mut ~[ScopeStackEntry], + &mut HashMap|) { // Create a new lexical scope and push it onto the stack let loc = cx.sess.codemap.lookup_char_pos(scope_span.lo); let file_metadata = file_metadata(cx, loc.file.name); diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index ddf9354ad3835..9d8b539bac83b 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1151,10 +1151,12 @@ pub fn trans_local_var(bcx: @mut Block, def: ast::Def) -> Datum { // The optional node ID here is the node ID of the path identifying the enum // variant in use. If none, this cannot possibly an enum variant (so, if it // is and `node_id_opt` is none, this function fails). -pub fn with_field_tys(tcx: ty::ctxt, - ty: ty::t, - node_id_opt: Option, - op: &fn(ty::Disr, (&[ty::field])) -> R) -> R { +pub fn with_field_tys( + tcx: ty::ctxt, + ty: ty::t, + node_id_opt: Option, + op: |ty::Disr, (&[ty::field])| -> R) + -> R { match ty::get(ty).sty { ty::ty_struct(did, ref substs) => { op(0, struct_fields(tcx, did, substs)) diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 7da80507df07d..33036aab65be1 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -510,11 +510,13 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext, // Array for the arguments we will pass to the rust function. let mut llrust_args = ~[]; let mut next_foreign_arg_counter: c_uint = 0; - let next_foreign_arg: &fn(pad: bool) -> c_uint = { - |pad: bool| { - next_foreign_arg_counter += if pad { 2 } else { 1 }; - next_foreign_arg_counter - 1 - } + let next_foreign_arg: |pad: bool| -> c_uint = |pad: bool| { + next_foreign_arg_counter += if pad { + 2 + } else { + 1 + }; + next_foreign_arg_counter - 1 }; // If there is an out pointer on the foreign function diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 0781f724d48c3..b1dc17a123998 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -121,7 +121,7 @@ impl Reflector { pub fn bracketed(&mut self, bracket_name: &str, extra: &[ValueRef], - inner: &fn(&mut Reflector)) { + inner: |&mut Reflector|) { self.visit("enter_" + bracket_name, extra); inner(self); self.visit("leave_" + bracket_name, extra); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 10a02e1e8bedf..2a8db56eec649 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -247,7 +247,7 @@ pub enum AutoRef { /// Convert from @[]/~[]/&[] to &&[] (or str) AutoBorrowVecRef(Region, ast::Mutability), - /// Convert from @fn()/~fn()/&fn() to &fn() + /// Convert from @fn()/~fn()/|| to || AutoBorrowFn(Region), /// Convert from T to *T @@ -651,7 +651,7 @@ pub enum sty { // "Fake" types, used for trans purposes ty_type, // type_desc* ty_opaque_box, // used by monomorphizer to represent any @ box - ty_opaque_closure_ptr(Sigil), // ptr to env for &fn, @fn, ~fn + ty_opaque_closure_ptr(Sigil), // ptr to env for ||, @fn, ~fn ty_unboxed_vec(mt), } @@ -1348,11 +1348,11 @@ pub fn mk_opaque_closure_ptr(cx: ctxt, sigil: ast::Sigil) -> t { pub fn mk_opaque_box(cx: ctxt) -> t { mk_t(cx, ty_opaque_box) } -pub fn walk_ty(ty: t, f: &fn(t)) { +pub fn walk_ty(ty: t, f: |t|) { maybe_walk_ty(ty, |t| { f(t); true }); } -pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) { +pub fn maybe_walk_ty(ty: t, f: |t| -> bool) { if !f(ty) { return; } @@ -1382,25 +1382,19 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) { } // Folds types from the bottom up. -pub fn fold_ty(cx: ctxt, t0: t, fldop: &fn(t) -> t) -> t { +pub fn fold_ty(cx: ctxt, t0: t, fldop: |t| -> t) -> t { let mut f = ty_fold::BottomUpFolder {tcx: cx, fldop: fldop}; f.fold_ty(t0) } -pub fn walk_regions_and_ty(cx: ctxt, - ty: t, - fldr: &fn(r: Region), - fldt: &fn(t: t)) +pub fn walk_regions_and_ty(cx: ctxt, ty: t, fldr: |r: Region|, fldt: |t: t|) -> t { ty_fold::RegionFolder::general(cx, |r| { fldr(r); r }, |t| { fldt(t); t }).fold_ty(ty) } -pub fn fold_regions(cx: ctxt, - ty: t, - fldr: &fn(r: Region) -> Region) - -> t { +pub fn fold_regions(cx: ctxt, ty: t, fldr: |r: Region| -> Region) -> t { ty_fold::RegionFolder::regions(cx, fldr).fold_ty(ty) } @@ -1886,7 +1880,7 @@ impl TypeContents { *self & TC::ReachesAll) } - pub fn union(v: &[T], f: &fn(&T) -> TypeContents) -> TypeContents { + pub fn union(v: &[T], f: |&T| -> TypeContents) -> TypeContents { v.iter().fold(TC::None, |tc, t| tc | f(t)) } @@ -2223,7 +2217,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { fn each_inherited_builtin_bound(cx: ctxt, bounds: BuiltinBounds, traits: &[@TraitRef], - f: &fn(BuiltinBound)) { + f: |BuiltinBound|) { for bound in bounds.iter() { f(bound); } @@ -2351,10 +2345,8 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { !subtypes_require(cx, &mut seen, r_ty, r_ty) } -pub fn type_structurally_contains(cx: ctxt, - ty: t, - test: &fn(x: &sty) -> bool) - -> bool { +pub fn type_structurally_contains(cx: ctxt, ty: t, test: |x: &sty| -> bool) + -> bool { let sty = &get(ty).sty; debug!("type_structurally_contains: {}", ::util::ppaux::ty_to_str(cx, ty)); @@ -2969,7 +2961,7 @@ pub fn adjust_ty(cx: ctxt, } impl AutoRef { - pub fn map_region(&self, f: &fn(Region) -> Region) -> AutoRef { + pub fn map_region(&self, f: |Region| -> Region) -> AutoRef { match *self { ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m), ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m), @@ -3525,11 +3517,10 @@ pub fn trait_ref_supertraits(cx: ctxt, trait_ref: &ty::TraitRef) -> ~[@TraitRef] } fn lookup_locally_or_in_crate_store( - descr: &str, - def_id: ast::DefId, - map: &mut HashMap, - load_external: &fn() -> V) -> V -{ + descr: &str, + def_id: ast::DefId, + map: &mut HashMap, + load_external: || -> V) -> V { /*! * Helper for looking things up in the various maps * that are populated during typeck::collect (e.g., @@ -3961,7 +3952,7 @@ pub fn lookup_trait_def(cx: ctxt, did: ast::DefId) -> @ty::TraitDef { /// Iterate over meta_items of a definition. // (This should really be an iterator, but that would require csearch and // decoder to use iterators instead of higher-order functions.) -pub fn each_attr(tcx: ctxt, did: DefId, f: &fn(@MetaItem) -> bool) -> bool { +pub fn each_attr(tcx: ctxt, did: DefId, f: |@MetaItem| -> bool) -> bool { if is_local(did) { match tcx.items.find(&did.node) { Some(&ast_map::node_item(@ast::item {attrs: ref attrs, _}, _)) => @@ -4341,7 +4332,8 @@ pub fn determine_inherited_purity(parent: (ast::purity, ast::NodeId), // list. pub fn each_bound_trait_and_supertraits(tcx: ctxt, bounds: &[@TraitRef], - f: &fn(@TraitRef) -> bool) -> bool { + f: |@TraitRef| -> bool) + -> bool { for &bound_trait_ref in bounds.iter() { let mut supertrait_set = HashMap::new(); let mut trait_refs = ~[]; diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 57581306b5d5d..7feb82788fc44 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -33,7 +33,7 @@ * scopes and (b) the default region may change. To understand case (a), * consider something like: * - * type foo = { x: &a.int, y: &fn(&a.int) } + * type foo = { x: &a.int, y: |&a.int| } * * The type of `x` is an error because there is no region `a` in scope. * In the type of `y`, however, region `a` is considered a bound region @@ -290,13 +290,14 @@ pub fn ast_ty_to_ty( // Handle @, ~, and & being able to mean estrs and evecs. // If a_seq_ty is a str or a vec, make it an estr/evec. // Also handle first-class trait types. - fn mk_pointer( - this: &AC, - rscope: &RS, - a_seq_ty: &ast::mt, - vst: ty::vstore, - constr: &fn(ty::mt) -> ty::t) -> ty::t - { + fn mk_pointer( + this: &AC, + rscope: &RS, + a_seq_ty: &ast::mt, + vst: ty::vstore, + constr: |ty::mt| -> ty::t) + -> ty::t { let tcx = this.tcx(); debug!("mk_pointer(vst={:?})", vst); @@ -715,7 +716,7 @@ pub fn ty_of_closure( ty::ReStatic } ast::BorrowedSigil => { - // &fn() defaults as normal for an omitted lifetime: + // || defaults as normal for an omitted lifetime: opt_ast_region_to_region(this, rscope, span, opt_lifetime) } } diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 63f439e43e311..0785ba002aacb 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -655,7 +655,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, span: Span, expected: ty::t) { let fcx = pcx.fcx; - let check_inner: &fn(ty::mt) = |e_inner| { + let check_inner: |ty::mt| = |e_inner| { check_pat(pcx, inner, e_inner.ty); fcx.write_ty(pat_id, expected); }; diff --git a/src/librustc/middle/typeck/check/demand.rs b/src/librustc/middle/typeck/check/demand.rs index dc718bbef752f..5973d791f525c 100644 --- a/src/librustc/middle/typeck/check/demand.rs +++ b/src/librustc/middle/typeck/check/demand.rs @@ -31,9 +31,11 @@ pub fn subtype(fcx: @mut FnCtxt, sp: Span, expected: ty::t, actual: ty::t) { } pub fn suptype_with_fn(fcx: @mut FnCtxt, - sp: Span, b_is_expected: bool, - ty_a: ty::t, ty_b: ty::t, - handle_err: &fn(Span, ty::t, ty::t, &ty::type_err)) { + sp: Span, + b_is_expected: bool, + ty_a: ty::t, + ty_b: ty::t, + handle_err: |Span, ty::t, ty::t, &ty::type_err|) { // n.b.: order of actual, expected is reversed match infer::mk_subty(fcx.infcx(), b_is_expected, infer::Misc(sp), ty_b, ty_a) { diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 870b29882fd6e..8eaf3824ff408 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -483,12 +483,13 @@ impl<'self> LookupContext<'self> { // Do a search through a list of bounds, using a callback to actually // create the candidates. - fn push_inherent_candidates_from_bounds_inner( - &self, - bounds: &[@TraitRef], - mk_cand: &fn(trait_ref: @TraitRef, m: @ty::Method, method_num: uint, - bound_num: uint) -> Candidate) { - + fn push_inherent_candidates_from_bounds_inner(&self, + bounds: &[@TraitRef], + mk_cand: |tr: @TraitRef, + m: @ty::Method, + method_num: uint, + bound_num: uint| + -> Candidate) { let tcx = self.tcx(); let mut next_bound_idx = 0; // count only trait bounds @@ -783,12 +784,12 @@ impl<'self> LookupContext<'self> { } fn search_for_some_kind_of_autorefd_method( - &self, - kind: &fn(Region, ast::Mutability) -> ty::AutoRef, - autoderefs: uint, - mutbls: &[ast::Mutability], - mk_autoref_ty: &fn(ast::Mutability, ty::Region) -> ty::t) - -> Option { + &self, + kind: |Region, ast::Mutability| -> ty::AutoRef, + autoderefs: uint, + mutbls: &[ast::Mutability], + mk_autoref_ty: |ast::Mutability, ty::Region| -> ty::t) + -> Option { // This is hokey. We should have mutability inference as a // variable. But for now, try &const, then &, then &mut: let region = diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e46b92ae49537..8d643ef220042 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1194,7 +1194,7 @@ impl FnCtxt { pub fn opt_node_ty_substs(&self, id: ast::NodeId, - f: &fn(&ty::substs) -> bool) + f: |&ty::substs| -> bool) -> bool { match self.inh.node_type_substs.find(&id) { Some(s) => f(s), @@ -1257,8 +1257,7 @@ impl FnCtxt { infer::mk_subr(self.infcx(), a_is_expected, origin, sub, sup) } - pub fn with_region_lb(@mut self, lb: ast::NodeId, f: &fn() -> R) - -> R { + pub fn with_region_lb(@mut self, lb: ast::NodeId, f: || -> R) -> R { let old_region_lb = self.region_lb; self.region_lb = lb; let v = f(); @@ -1268,7 +1267,7 @@ impl FnCtxt { pub fn type_error_message(&self, sp: Span, - mk_msg: &fn(~str) -> ~str, + mk_msg: |~str| -> ~str, actual_ty: ty::t, err: Option<&ty::type_err>) { self.infcx().type_error_message(sp, mk_msg, actual_ty, err); @@ -1629,7 +1628,7 @@ fn check_type_parameter_positions_in_path(function_context: @mut FnCtxt, pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr: @ast::Expr, expected: Option, - unifier: &fn()) { + unifier: ||) { debug!(">> typechecking"); fn check_method_argument_types( @@ -2014,7 +2013,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, args: ~[@ast::Expr], deref_args: DerefArgs, autoderef_receiver: AutoderefReceiverFlag, - unbound_method: &fn(), + unbound_method: ||, _expected_result: Option ) -> ty::t { @@ -2198,10 +2197,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // through the `unpack` function. It there is no expected type or // resolution is not possible (e.g., no constraints yet present), just // returns `none`. - fn unpack_expected(fcx: @mut FnCtxt, - expected: Option, - unpack: &fn(&ty::sty) -> Option) - -> Option { + fn unpack_expected( + fcx: @mut FnCtxt, + expected: Option, + unpack: |&ty::sty| -> Option) + -> Option { match expected { Some(t) => { match resolve_type(fcx.infcx(), t, force_tvar) { diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index ec11adbfa3dab..ebdd4b5f48c2f 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -20,12 +20,11 @@ use util::ppaux; // Helper functions related to manipulating region types. pub fn replace_bound_regions_in_fn_sig( - tcx: ty::ctxt, - opt_self_ty: Option, - fn_sig: &ty::FnSig, - mapf: &fn(ty::BoundRegion) -> ty::Region) - -> (HashMap, Option, ty::FnSig) -{ + tcx: ty::ctxt, + opt_self_ty: Option, + fn_sig: &ty::FnSig, + mapf: |ty::BoundRegion| -> ty::Region) + -> (HashMap, Option, ty::FnSig) { debug!("replace_bound_regions_in_fn_sig(self_ty={}, fn_sig={})", opt_self_ty.repr(tcx), fn_sig.repr(tcx)); @@ -47,12 +46,10 @@ pub fn replace_bound_regions_in_fn_sig( (map, opt_self_ty, fn_sig) } -pub fn relate_nested_regions( - tcx: ty::ctxt, - opt_region: Option, - ty: ty::t, - relate_op: &fn(ty::Region, ty::Region)) -{ +pub fn relate_nested_regions(tcx: ty::ctxt, + opt_region: Option, + ty: ty::t, + relate_op: |ty::Region, ty::Region|) { /*! * This rather specialized function walks each region `r` that appear * in `ty` and invokes `relate_op(r_encl, r)` for each one. `r_encl` diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index bf00bee270943..78aa3f8fe4077 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -451,7 +451,7 @@ impl CoherenceChecker { } } - pub fn iter_impls_of_trait(&self, trait_def_id: DefId, f: &fn(@Impl)) { + pub fn iter_impls_of_trait(&self, trait_def_id: DefId, f: |@Impl|) { match self.crate_context.tcx.trait_impls.find(&trait_def_id) { Some(impls) => { for &im in impls.iter() { diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index e1f65f79e4fb7..e2ea08244006d 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -161,9 +161,7 @@ impl Coerce { } } - pub fn unpack_actual_value(&self, - a: ty::t, - f: &fn(&ty::sty) -> CoerceResult) + pub fn unpack_actual_value(&self, a: ty::t, f: |&ty::sty| -> CoerceResult) -> CoerceResult { match resolve_type(self.infcx, a, try_resolve_tvar_shallow) { Ok(t) => { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 9febef1c7c399..af7a23a4dfcdc 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -196,7 +196,7 @@ impl Combine for Glb { // NB---I do not believe this algorithm computes // (necessarily) the GLB. As written it can // spuriously fail. In particular, if there is a case - // like: &fn(fn(&a)) and fn(fn(&b)), where a and b are + // like: |fn(&a)| and fn(fn(&b)), where a and b are // free, it will return fn(&c) where c = GLB(a,b). If // however this GLB is not defined, then the result is // an error, even though something like diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index eafc7e262f191..cde9dd135b311 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -442,12 +442,12 @@ pub fn resolve_region(cx: @mut InferCtxt, r: ty::Region, modes: uint) } trait then { - fn then(&self, f: &fn() -> Result) + fn then(&self, f: || -> Result) -> Result; } impl then for ures { - fn then(&self, f: &fn() -> Result) + fn then(&self, f: || -> Result) -> Result { self.and_then(|_i| f()) } @@ -467,11 +467,11 @@ impl ToUres for cres { } trait CresCompare { - fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres; + fn compare(&self, t: T, f: || -> ty::type_err) -> cres; } impl CresCompare for cres { - fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres { + fn compare(&self, t: T, f: || -> ty::type_err) -> cres { do (*self).clone().and_then |s| { if s == t { (*self).clone() @@ -549,7 +549,7 @@ impl InferCtxt { } /// Execute `f` and commit the bindings if successful - pub fn commit(@mut self, f: &fn() -> Result) -> Result { + pub fn commit(@mut self, f: || -> Result) -> Result { assert!(!self.in_snapshot()); debug!("commit()"); @@ -564,7 +564,7 @@ impl InferCtxt { } /// Execute `f`, unroll bindings on failure - pub fn try(@mut self, f: &fn() -> Result) -> Result { + pub fn try(@mut self, f: || -> Result) -> Result { debug!("try()"); let snapshot = self.start_snapshot(); let r = f(); @@ -579,7 +579,7 @@ impl InferCtxt { } /// Execute `f` then unroll any bindings it creates - pub fn probe(@mut self, f: &fn() -> Result) -> Result { + pub fn probe(@mut self, f: || -> Result) -> Result { debug!("probe()"); do indent { let snapshot = self.start_snapshot(); @@ -721,7 +721,7 @@ impl InferCtxt { // errors. pub fn type_error_message_str(@mut self, sp: Span, - mk_msg: &fn(Option<~str>, ~str) -> ~str, + mk_msg: |Option<~str>, ~str| -> ~str, actual_ty: ~str, err: Option<&ty::type_err>) { self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err) @@ -729,9 +729,9 @@ impl InferCtxt { pub fn type_error_message_str_with_expected(@mut self, sp: Span, - mk_msg: - &fn(Option<~str>, ~str) -> - ~str, + mk_msg: |Option<~str>, + ~str| + -> ~str, expected_ty: Option, actual_ty: ~str, err: Option<&ty::type_err>) { @@ -760,7 +760,7 @@ impl InferCtxt { pub fn type_error_message(@mut self, sp: Span, - mk_msg: &fn(~str) -> ~str, + mk_msg: |~str| -> ~str, actual_ty: ty::t, err: Option<&ty::type_err>) { let actual_ty = self.resolve_type_vars_if_possible(actual_ty); @@ -813,11 +813,10 @@ impl InferCtxt { } } -pub fn fold_regions_in_sig( - tcx: ty::ctxt, - fn_sig: &ty::FnSig, - fldr: &fn(r: ty::Region) -> ty::Region) -> ty::FnSig -{ +pub fn fold_regions_in_sig(tcx: ty::ctxt, + fn_sig: &ty::FnSig, + fldr: |r: ty::Region| -> ty::Region) + -> ty::FnSig { ty_fold::RegionFolder::regions(tcx, fldr).fold_sig(fn_sig) } diff --git a/src/librustc/middle/typeck/infer/region_inference/doc.rs b/src/librustc/middle/typeck/infer/region_inference/doc.rs index df6d5dc1b2060..2b99a0a4f0ef4 100644 --- a/src/librustc/middle/typeck/infer/region_inference/doc.rs +++ b/src/librustc/middle/typeck/infer/region_inference/doc.rs @@ -389,7 +389,7 @@ The problem we are addressing is that there is a kind of subtyping between functions with bound region parameters. Consider, for example, whether the following relation holds: - fn(&'a int) <: &fn(&'b int)? (Yes, a => b) + fn(&'a int) <: |&'b int|? (Yes, a => b) The answer is that of course it does. These two types are basically the same, except that in one we used the name `a` and one we used @@ -406,7 +406,7 @@ Now let's consider two more function types. Here, we assume that the `self` lifetime is defined somewhere outside and hence is not a lifetime parameter bound by the function type (it "appears free"): - fn(&'a int) <: &fn(&'self int)? (Yes, a => self) + fn(&'a int) <: |&'self int|? (Yes, a => self) This subtyping relation does in fact hold. To see why, you have to consider what subtyping means. One way to look at `T1 <: T2` is to @@ -423,7 +423,7 @@ to the same thing: a function that accepts pointers with any lifetime So, what if we reverse the order of the two function types, like this: - fn(&'self int) <: &fn(&'a int)? (No) + fn(&'self int) <: |&'a int|? (No) Does the subtyping relationship still hold? The answer of course is no. In this case, the function accepts *only the lifetime `&self`*, @@ -432,8 +432,8 @@ accepted any lifetime. What about these two examples: - fn(&'a int, &'b int) <: &fn(&'a int, &'a int)? (Yes) - fn(&'a int, &'a int) <: &fn(&'a int, &'b int)? (No) + fn(&'a int, &'b int) <: |&'a int, &'a int|? (Yes) + fn(&'a int, &'a int) <: |&'a int, &'b int|? (No) Here, it is true that functions which take two pointers with any two lifetimes can be treated as if they only accepted two pointers with @@ -457,12 +457,12 @@ Let's walk through some examples and see how this algorithm plays out. We'll start with the first example, which was: - 1. fn(&'a T) <: &fn(&'b T)? Yes: a -> b + 1. fn(&'a T) <: |&'b T|? Yes: a -> b After steps 1 and 2 of the algorithm we will have replaced the types like so: - 1. fn(&'A T) <: &fn(&'x T)? + 1. fn(&'A T) <: |&'x T|? Here the upper case `&A` indicates a *region variable*, that is, a region whose value is being inferred by the system. I also replaced @@ -491,12 +491,12 @@ So far we have encountered no error, so the subtype check succeeds. Now let's look first at the third example, which was: - 3. fn(&'self T) <: &fn(&'b T)? No! + 3. fn(&'self T) <: |&'b T|? No! After steps 1 and 2 of the algorithm we will have replaced the types like so: - 3. fn(&'self T) <: &fn(&'x T)? + 3. fn(&'self T) <: |&'x T|? This looks pretty much the same as before, except that on the LHS `&self` was not bound, and hence was left as-is and not replaced with @@ -511,7 +511,7 @@ You may be wondering about that mysterious last step in the algorithm. So far it has not been relevant. The purpose of that last step is to catch something like *this*: - fn() -> fn(&'a T) <: &fn() -> fn(&'b T)? No. + fn() -> fn(&'a T) <: || -> fn(&'b T)? No. Here the function types are the same but for where the binding occurs. The subtype returns a function that expects a value in precisely one @@ -525,15 +525,15 @@ So let's step through what happens when we perform this subtype check. We first replace the bound regions in the subtype (the supertype has no bound regions). This gives us: - fn() -> fn(&'A T) <: &fn() -> fn(&'b T)? + fn() -> fn(&'A T) <: || -> fn(&'b T)? Now we compare the return types, which are covariant, and hence we have: - fn(&'A T) <: &fn(&'b T)? + fn(&'A T) <: |&'b T|? Here we skolemize the bound region in the supertype to yield: - fn(&'A T) <: &fn(&'x T)? + fn(&'A T) <: |&'x T|? And then proceed to compare the argument types: @@ -550,7 +550,7 @@ The difference between this example and the first one is that the variable `A` already existed at the point where the skolemization occurred. In the first example, you had two functions: - fn(&'a T) <: &fn(&'b T) + fn(&'a T) <: |&'b T| and hence `&A` and `&x` were created "together". In general, the intention of the skolemized names is that they are supposed to be diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index e613aa4ba28de..ff4b20d369b6f 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -359,9 +359,9 @@ impl RegionVarBindings { a: Region, b: Region, origin: SubregionOrigin, - relate: &fn(this: &mut RegionVarBindings, - old_r: Region, - new_r: Region)) + relate: |this: &mut RegionVarBindings, + old_r: Region, + new_r: Region|) -> Region { let vars = TwoRegions { a: a, b: b }; match self.combine_map(t).find(&vars) { @@ -1254,7 +1254,7 @@ impl RegionVarBindings { fn iterate_until_fixed_point(&self, tag: &str, - body: &fn(constraint: &Constraint) -> bool) { + body: |constraint: &Constraint| -> bool) { let mut iteration = 0; let mut changed = true; while changed { diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 63ddc9addc55e..ed2b1d1db4b5a 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -282,15 +282,14 @@ pub fn no_params(t: ty::t) -> ty::ty_param_bounds_and_ty { } } -pub fn require_same_types( - tcx: ty::ctxt, - maybe_infcx: Option<@mut infer::InferCtxt>, - t1_is_expected: bool, - span: Span, - t1: ty::t, - t2: ty::t, - msg: &fn() -> ~str) -> bool { - +pub fn require_same_types(tcx: ty::ctxt, + maybe_infcx: Option<@mut infer::InferCtxt>, + t1_is_expected: bool, + span: Span, + t1: ty::t, + t2: ty::t, + msg: || -> ~str) + -> bool { let l_tcx; let l_infcx; match maybe_infcx { diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index 1b435d11404b1..985bcaf96d17e 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -150,8 +150,8 @@ constraints will be satisfied. As a simple example, consider: enum Option { Some(A), None } - enum OptionalFn { Some(&fn(B)), None } - enum OptionalMap { Some(&fn(C) -> C), None } + enum OptionalFn { Some(|B|), None } + enum OptionalMap { Some(|C| -> C), None } Here, we will generate the constraints: diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index ecc53ae5f8061..ffbea94c4774b 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -17,7 +17,7 @@ use syntax::visit::Visitor; use std::hashmap::HashSet; use extra; -pub fn time(do_it: bool, what: &str, u: U, f: &fn(U) -> T) -> T { +pub fn time(do_it: bool, what: &str, u: U, f: |U| -> T) -> T { if !do_it { return f(u); } let start = extra::time::precise_time_s(); let rv = f(u); @@ -26,7 +26,7 @@ pub fn time(do_it: bool, what: &str, u: U, f: &fn(U) -> T) -> T { rv } -pub fn indent(op: &fn() -> R) -> R { +pub fn indent(op: || -> R) -> R { // Use in conjunction with the log post-processor like `src/etc/indenter` // to make debug output more readable. debug!(">>"); @@ -79,7 +79,7 @@ impl<'self> Visitor<()> for LoopQueryVisitor<'self> { // Takes a predicate p, returns true iff p is true for any subexpressions // of b -- skipping any inner loops (loop, while, loop_body) -pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool { +pub fn loop_query(b: &ast::Block, p: |&ast::Expr_| -> bool) -> bool { let mut v = LoopQueryVisitor { p: p, flag: false, @@ -102,7 +102,7 @@ impl<'self> Visitor<()> for BlockQueryVisitor<'self> { // Takes a predicate p, returns true iff p is true for any subexpressions // of b -- skipping any inner loops (loop, while, loop_body) -pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool { +pub fn block_query(b: &ast::Block, p: |@ast::Expr| -> bool) -> bool { let mut v = BlockQueryVisitor { p: p, flag: false, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index c5d7db465e6a1..0364eb890fbb9 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -286,7 +286,7 @@ pub fn vstore_ty_to_str(cx: ctxt, mt: &mt, vs: ty::vstore) -> ~str { } } -pub fn vec_map_to_str(ts: &[T], f: &fn(t: &T) -> ~str) -> ~str { +pub fn vec_map_to_str(ts: &[T], f: |t: &T| -> ~str) -> ~str { let tstrs = ts.map(f); format!("[{}]", tstrs.connect(", ")) } diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index ddf7c934a49d5..c4641eff57269 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 90729966c18a6..a052ae87a41c5 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 7f91c5e4f9054..ce0a669659623 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 4d5c68ab7177b..a9c4d2cacde2c 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 a1459b780dfb3..54849a44f6d3b 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 6530755cb1dd6..c5a4dd1631df9 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 7bbc8bc32fa2a..a1f8509786562 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 cb9552b189ce5..56d5a8594012f 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 262cdaed492ac..d2874a6f7f578 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 a48b8578116de..427690a4aa589 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 c9a85e6d25e13..f15abff831690 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 edefd39ebb4d1..2d3e6431b0cd7 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 ebda2618dcf54..5eb2e72e96b21 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 cc3f8bacb24dc..930f58ef33f27 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 4b9c5ca5d4ab0..decdfb60bfbe5 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 c56189dbb2b17..1d0fef4889071 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 b2cb8f735cf15..abaeab609aaa0 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 71c6ce78a1ed1..6aa3ae65fc985 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 07240a4a50903..9c63108beef3e 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 1a2245ac442f7..b8cdbfc25cb4c 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 49cac428cb23e..1362d702f1c3a 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 3897f519e90d1..f736b10cc4fc5 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 684fb9c76d941..083de15008a27 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 ba1a7a4f912b8..9141e87bd722d 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 873d66d401e10..aeda3fa1cd193 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 d17c947ab5620..5d713f1a622cc 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 2ecbb79407e1b..1cc0c19150137 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 2974b402d4a76..49f270369f72c 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 0d9dc18726fb0..c5a10c75640ec 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 3ea6e18f9427c..3692bc303fb61 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 18f137e8b0e56..6f152fa2a4115 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 f14f100de73c9..86f1e7f6e86ae 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 8483b504c0137..d5bc6b85424f0 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 29ae88272a456..887f7f2e9a631 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 cc2f739ce98d8..9e83afa819c18 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 9769739b966b1..d0a6964917614 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 3f8da64b3d6d3..33e80d7fcaeec 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 03860c8ab2211..97daf8d7e60df 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 0d32d2d7dbae0..a173be6435670 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 e8f6c4055a022..2c1c5d84be154 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 bd528cbe61f06..d1f69ada301cb 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 8decaea1f4725..987b32c084674 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 f7abc33ce142d..fa4746a6bb77f 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 1ddc2f86f4bc4..d47dae96283a6 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 d5d1931a21725..862ecd6499a50 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 775f9d6c3be77..f83932f9ffa28 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 00895289b6a98..e317b76b24d0e 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 6d3eec9a9213b..3fe555de56c9e 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 f376a30efa718..c567fd0a8b312 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 5915dd45c08dc..f9b918d6d1215 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 d7d3e715ef9ca..66a2e8cc5e0d4 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 c561fb6cc8a45..f60d8641aca12 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 d7f84a6abfbf3..a8f56228dcb69 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 e0d284a32df1e..cdfbf8c004991 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 266a619c71037..78f1c3655ad6e 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 d784c1d38c60f..4ad4656af7bf2 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 3423b995fda78..ae4b5d4c6aa37 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 c2aa4c234d1b7..2bd6a00ed4a0e 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 diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 972d2f43e73f5..c2283bf1227ed 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -84,7 +84,7 @@ static AbiDatas: &'static [AbiData] = &[ AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch}, ]; -fn each_abi(op: &fn(abi: Abi) -> bool) -> bool { +fn each_abi(op: |abi: Abi| -> bool) -> bool { /*! * * Iterates through each of the defined ABIs. @@ -201,7 +201,7 @@ impl AbiSet { self.bits |= (1 << abi.index()); } - pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool { + pub fn each(&self, op: |abi: Abi| -> bool) -> bool { each_abi(|abi| !self.contains(abi) || op(abi)) } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f3d7ac1804db7..c5ad371491757 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -122,7 +122,7 @@ pub enum ast_node { } impl ast_node { - pub fn with_attrs(&self, f: &fn(Option<&[Attribute]>) -> T) -> T { + pub fn with_attrs(&self, f: |Option<&[Attribute]>| -> T) -> T { let attrs = match *self { node_item(i, _) => Some(i.attrs.as_slice()), node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()), @@ -480,9 +480,8 @@ pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str { } } -pub fn node_item_query(items: map, id: NodeId, - query: &fn(@item) -> Result, - error_msg: ~str) -> Result { +pub fn node_item_query(items: map, id: NodeId, query: |@item| -> Result, error_msg: ~str) + -> Result { match items.find(&id) { Some(&node_item(it, _)) => query(it), _ => fail!("{}", error_msg) diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index fb50a890c43f5..a49109911de42 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -636,7 +636,7 @@ pub fn is_item_impl(item: @ast::item) -> bool { } } -pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool { +pub fn walk_pat(pat: @Pat, it: |@Pat| -> bool) -> bool { if !it(pat) { return false; } @@ -665,7 +665,7 @@ pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool { } pub trait EachViewItem { - fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool; + fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool; } struct EachViewItemData<'self> { @@ -679,7 +679,7 @@ impl<'self> Visitor<()> for EachViewItemData<'self> { } impl EachViewItem for ast::Crate { - fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool { + fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool { let mut visit = EachViewItemData { callback: f, }; diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 0565399bdf4d6..15b8273062949 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -347,9 +347,11 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) { } } -pub fn expect(diag: @mut span_handler, - opt: Option, - msg: &fn() -> ~str) -> T { +pub fn expect( + diag: @mut span_handler, + opt: Option, + msg: || -> ~str) + -> T { match opt { Some(ref t) => (*t).clone(), None => diag.handler().bug(msg()), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 7ce73a4afef70..448f8ee88f90a 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -559,11 +559,11 @@ impl MapChain{ // should each_key and each_value operate on shadowed // names? I think not. // delaying implementing this.... - pub fn each_key (&self, _f: &fn (&K)->bool) { + pub fn each_key (&self, _f: |&K| -> bool) { fail!("unimplemented 2013-02-15T10:01"); } - pub fn each_value (&self, _f: &fn (&V) -> bool) { + pub fn each_value (&self, _f: |&V| -> bool) { fail!("unimplemented 2013-02-15T10:02"); } @@ -601,7 +601,11 @@ impl MapChain{ // ... there are definitely some opportunities for abstraction // here that I'm ignoring. (e.g., manufacturing a predicate on // the maps in the chain, and using an abstract "find". - pub fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) { + pub fn insert_into_frame(&mut self, + key: K, + ext: @V, + n: K, + pred: |&@V| -> bool) { match *self { BaseMapChain (~ref mut map) => { if satisfies_pred(map,&n,pred) { @@ -622,10 +626,12 @@ impl MapChain{ } // returns true if the binding for 'n' satisfies 'pred' in 'map' -fn satisfies_pred(map : &mut HashMap, - n: &K, - pred: &fn(&V)->bool) - -> bool { +fn satisfies_pred( + map: &mut HashMap, + n: &K, + pred: |&V| -> bool) + -> bool { match map.find(n) { Some(ref v) => (pred(*v)), None => false @@ -637,7 +643,8 @@ mod test { use super::MapChain; use std::hashmap::HashMap; - #[test] fn testenv () { + #[test] + fn testenv() { let mut a = HashMap::new(); a.insert (@"abc",@15); let m = MapChain::new(~a); diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 3f745d64a7b9b..2f9222ccb56f6 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -124,9 +124,12 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span, /// Create a decoder for a single enum variant/struct: /// - `outer_pat_ident` is the name of this enum variant/struct /// - `getarg` should retrieve the `uint`-th field with name `@str`. -fn decode_static_fields(cx: @ExtCtxt, outer_span: Span, outer_pat_ident: Ident, +fn decode_static_fields(cx: @ExtCtxt, + outer_span: Span, + outer_pat_ident: Ident, fields: &StaticFields, - getarg: &fn(Span, @str, uint) -> @Expr) -> @Expr { + getarg: |Span, @str, uint| -> @Expr) + -> @Expr { match *fields { Unnamed(ref fields) => { if fields.is_empty() { diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index aa83b7656a67c..23dc38fdc31e5 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -1064,14 +1064,13 @@ Fold the fields. `use_foldl` controls whether this is done left-to-right (`true`) or right-to-left (`false`). */ pub fn cs_fold(use_foldl: bool, - f: &fn(@ExtCtxt, Span, - old: @Expr, - self_f: @Expr, - other_fs: &[@Expr]) -> @Expr, + f: |@ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr, base: @Expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ExtCtxt, trait_span: Span, - substructure: &Substructure) -> @Expr { + cx: @ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> @Expr { match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { if use_foldl { @@ -1104,10 +1103,12 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1), ~~~ */ #[inline] -pub fn cs_same_method(f: &fn(@ExtCtxt, Span, ~[@Expr]) -> @Expr, +pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ExtCtxt, trait_span: Span, - substructure: &Substructure) -> @Expr { + cx: @ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> @Expr { match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) @@ -1136,11 +1137,13 @@ fields. `use_foldl` controls whether this is done left-to-right */ #[inline] pub fn cs_same_method_fold(use_foldl: bool, - f: &fn(@ExtCtxt, Span, @Expr, @Expr) -> @Expr, + f: |@ExtCtxt, Span, @Expr, @Expr| -> @Expr, base: @Expr, enum_nonmatch_f: EnumNonMatchFunc, - cx: @ExtCtxt, trait_span: Span, - substructure: &Substructure) -> @Expr { + cx: @ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> @Expr { cs_same_method( |cx, span, vals| { if use_foldl { diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 2a16d0b025de0..1877a6eb85bef 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -128,10 +128,12 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { _ => cx.bug("Non-static method in `deriving(Rand)`") }; - fn rand_thing(cx: @ExtCtxt, span: Span, + fn rand_thing(cx: @ExtCtxt, + span: Span, ctor_ident: Ident, summary: &StaticFields, - rand_call: &fn(Span) -> @Expr) -> @Expr { + rand_call: |Span| -> @Expr) + -> @Expr { match *summary { Unnamed(ref fields) => { if fields.is_empty() { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index bd99f58cde9d1..62592650416da 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -381,7 +381,7 @@ pub trait ast_fold { } } - fn map_exprs(&self, f: &fn(@Expr) -> @Expr, es: &[@Expr]) -> ~[@Expr] { + fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> ~[@Expr] { es.map(|x| f(*x)) } diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index 4d39d4df72f53..3a0b7c6adc44f 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -50,14 +50,14 @@ impl OptVec { *self = Vec(~[t]); } - pub fn map(&self, op: &fn(&T) -> U) -> OptVec { + pub fn map(&self, op: |&T| -> U) -> OptVec { match *self { Empty => Empty, Vec(ref v) => Vec(v.map(op)) } } - pub fn map_move(self, op: &fn(T) -> U) -> OptVec { + pub fn map_move(self, op: |T| -> U) -> OptVec { match self { Empty => Empty, Vec(v) => Vec(v.move_iter().map(op).collect()) @@ -91,11 +91,11 @@ impl OptVec { } #[inline] - pub fn map_to_vec(&self, op: &fn(&T) -> B) -> ~[B] { + pub fn map_to_vec(&self, op: |&T| -> B) -> ~[B] { self.iter().map(op).collect() } - pub fn mapi_to_vec(&self, op: &fn(uint, &T) -> B) -> ~[B] { + pub fn mapi_to_vec(&self, op: |uint, &T| -> B) -> ~[B] { let mut index = 0; self.map_to_vec(|a| { let i = index; diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 06a2c557e4228..26de9215dbfdb 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -216,16 +216,22 @@ fn byte_offset(rdr: &StringReader, pos: BytePos) -> BytePos { /// Calls `f` with a string slice of the source text spanning from `start` /// up to but excluding `rdr.last_pos`, meaning the slice does not include /// the character `rdr.curr`. -pub fn with_str_from(rdr: @mut StringReader, start: BytePos, f: &fn(s: &str) -> T) -> T { +pub fn with_str_from( + rdr: @mut StringReader, + start: BytePos, + f: |s: &str| -> T) + -> T { with_str_from_to(rdr, start, rdr.last_pos, f) } /// Calls `f` with astring slice of the source text spanning from `start` /// up to but excluding `end`. -fn with_str_from_to(rdr: @mut StringReader, - start: BytePos, - end: BytePos, - f: &fn(s: &str) -> T) -> T { +fn with_str_from_to( + rdr: @mut StringReader, + start: BytePos, + end: BytePos, + f: |s: &str| -> T) + -> T { f(rdr.src.slice( byte_offset(rdr, start).to_uint(), byte_offset(rdr, end).to_uint())) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 0e9a529f950b2..947f7a7fc29a8 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -177,19 +177,14 @@ pub fn parse_tts_from_source_str( // consumed all of the input before returning the function's // result. pub fn parse_from_source_str( - f: &fn(&Parser) -> T, - name: @str, ss: codemap::FileSubstr, - source: @str, - cfg: ast::CrateConfig, - sess: @mut ParseSess -) -> T { - let p = new_parser_from_source_substr( - sess, - cfg, - name, - ss, - source - ); + f: |&Parser| -> T, + name: @str, + ss: codemap::FileSubstr, + source: @str, + cfg: ast::CrateConfig, + sess: @mut ParseSess) + -> T { + let p = new_parser_from_source_substr(sess, cfg, name, ss, source); let r = f(&p); if !p.reader.is_eof() { p.reader.fatal(~"expected end-of-string"); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 189cc8e827c83..3adedf76eb840 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -82,7 +82,7 @@ impl ParserObsoleteMethods for Parser { ), ObsoleteBareFnType => ( "bare function type", - "use `&fn` or `extern fn` instead" + "use `|A| -> B` or `extern fn(A) -> B` instead" ), ObsoleteNamedExternModule => ( "named external module", diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2ea6878f4a370..6c2df4ad3142a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -581,10 +581,8 @@ impl Parser { } // Parse a sequence bracketed by `|` and `|`, stopping before the `|`. - fn parse_seq_to_before_or(&self, - sep: &token::Token, - f: &fn(&Parser) -> T) - -> ~[T] { + fn parse_seq_to_before_or(&self, sep: &token::Token, f: |&Parser| -> T) + -> ~[T] { let mut first = true; let mut vector = ~[]; while *self.token != token::BINOP(token::OR) && @@ -619,10 +617,11 @@ impl Parser { // parse a sequence bracketed by '<' and '>', stopping // before the '>'. - pub fn parse_seq_to_before_gt(&self, - sep: Option, - f: &fn(&Parser) -> T) - -> OptVec { + pub fn parse_seq_to_before_gt( + &self, + sep: Option, + f: |&Parser| -> T) + -> OptVec { let mut first = true; let mut v = opt_vec::Empty; while *self.token != token::GT @@ -639,10 +638,11 @@ impl Parser { return v; } - pub fn parse_seq_to_gt(&self, - sep: Option, - f: &fn(&Parser) -> T) - -> OptVec { + pub fn parse_seq_to_gt( + &self, + sep: Option, + f: |&Parser| -> T) + -> OptVec { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; @@ -651,11 +651,12 @@ impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - pub fn parse_seq_to_end(&self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T) - -> ~[T] { + pub fn parse_seq_to_end( + &self, + ket: &token::Token, + sep: SeqSep, + f: |&Parser| -> T) + -> ~[T] { let val = self.parse_seq_to_before_end(ket, sep, f); self.bump(); val @@ -664,11 +665,12 @@ impl Parser { // parse a sequence, not including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - pub fn parse_seq_to_before_end(&self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T) - -> ~[T] { + pub fn parse_seq_to_before_end( + &self, + ket: &token::Token, + sep: SeqSep, + f: |&Parser| -> T) + -> ~[T] { let mut first: bool = true; let mut v: ~[T] = ~[]; while *self.token != *ket { @@ -688,12 +690,13 @@ impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - pub fn parse_unspanned_seq(&self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T) - -> ~[T] { + pub fn parse_unspanned_seq( + &self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: |&Parser| -> T) + -> ~[T] { self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); @@ -702,12 +705,13 @@ impl Parser { // NB: Do not use this function unless you actually plan to place the // spanned list in the AST. - pub fn parse_seq(&self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T) - -> Spanned<~[T]> { + pub fn parse_seq( + &self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: |&Parser| -> T) + -> Spanned<~[T]> { let lo = self.span.lo; self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); @@ -765,8 +769,8 @@ impl Parser { } return (4 - *self.buffer_start) + *self.buffer_end; } - pub fn look_ahead(&self, distance: uint, f: &fn(&token::Token) -> R) - -> R { + pub fn look_ahead(&self, distance: uint, f: |&token::Token| -> R) + -> R { let dist = distance as int; while self.buffer_length() < dist { self.buffer[*self.buffer_end] = self.reader.next_token(); @@ -1272,7 +1276,8 @@ impl Parser { // parse the type following a @ or a ~ pub fn parse_box_or_uniq_pointee(&self, sigil: ast::Sigil, - ctor: &fn(v: mt) -> ty_) -> ty_ { + ctor: |v: mt| -> ty_) + -> ty_ { // ~'foo fn() or ~fn() are parsed directly as obsolete fn types: match *self.token { token::LIFETIME(*) => { @@ -2467,8 +2472,8 @@ impl Parser { // this is used both in parsing a lambda expr // and in parsing a block expr as e.g. in for... pub fn parse_lambda_expr_(&self, - parse_decl: &fn() -> fn_decl, - parse_body: &fn() -> @Expr) + parse_decl: || -> fn_decl, + parse_body: || -> @Expr) -> @Expr { let lo = self.last_span.lo; let decl = parse_decl(); @@ -2513,10 +2518,11 @@ impl Parser { // parse a 'for' or 'do'. // the 'for' and 'do' expressions parse as calls, but look like // function calls followed by a closure expression. - pub fn parse_sugary_call_expr(&self, lo: BytePos, + pub fn parse_sugary_call_expr(&self, + lo: BytePos, keyword: ~str, sugar: CallSugar, - ctor: &fn(v: @Expr) -> Expr_) + ctor: |v: @Expr| -> Expr_) -> @Expr { // Parse the callee `foo` in // for foo || { @@ -3611,11 +3617,12 @@ impl Parser { // parse the argument list and result type of a function // that may have a self type. - fn parse_fn_decl_with_self(&self, parse_arg_fn: &fn(&Parser) -> arg) - -> (explicit_self, fn_decl) { - - fn maybe_parse_explicit_self(cnstr: &fn(v: Mutability) -> ast::explicit_self_, - p: &Parser) -> ast::explicit_self_ { + fn parse_fn_decl_with_self(&self, parse_arg_fn: |&Parser| -> arg) + -> (explicit_self, fn_decl) { + fn maybe_parse_explicit_self(cnstr: |v: Mutability| -> + ast::explicit_self_, + p: &Parser) + -> ast::explicit_self_ { // We need to make sure it isn't a type if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) || ((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) || diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 68af73d4a01ca..8d31133e9e24a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -331,7 +331,7 @@ pub fn synth_comment(s: @ps, text: ~str) { word(s.s, "*/"); } -pub fn commasep(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T)) { +pub fn commasep(s: @ps, b: breaks, elts: &[T], op: |@ps, &T|) { box(s, 0u, b); let mut first = true; for elt in elts.iter() { @@ -342,8 +342,12 @@ pub fn commasep(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T)) { } -pub fn commasep_cmnt(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T), - get_span: &fn(&T) -> codemap::Span) { +pub fn commasep_cmnt( + s: @ps, + b: breaks, + elts: &[T], + op: |@ps, &T|, + get_span: |&T| -> codemap::Span) { box(s, 0u, b); let len = elts.len(); let mut i = 0u; @@ -2289,7 +2293,7 @@ pub fn print_string(s: @ps, st: &str, style: ast::StrStyle) { word(s.s, st); } -pub fn to_str(t: &T, f: &fn(@ps, &T), intr: @ident_interner) -> ~str { +pub fn to_str(t: &T, f: |@ps, &T|, intr: @ident_interner) -> ~str { let wr = @mut MemWriter::new(); let s = rust_printer(wr as @mut io::Writer, intr); f(s, t); diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 59a6f0adeb40e..3a2a8b10c9666 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -39,7 +39,7 @@ pub fn string_to_parser(source_str: @str) -> Parser { p } -fn with_error_checking_parse(s: @str, f: &fn(&mut Parser) -> T) -> T { +fn with_error_checking_parse(s: @str, f: |&mut Parser| -> T) -> T { let mut p = string_to_parser(s); let x = f(&mut p); p.abort_if_errors();