diff --git a/doc/po/ja/tutorial-tasks.md.po b/doc/po/ja/tutorial-tasks.md.po index 9cea63f0d0b5d..2276d0052a643 100644 --- a/doc/po/ja/tutorial-tasks.md.po +++ b/doc/po/ja/tutorial-tasks.md.po @@ -213,7 +213,7 @@ msgstr "" #. type: Plain text #: doc/tutorial-tasks.md:102 msgid "" -"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. " +"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. " "Because it accepts only owned closures, and owned closures contain only " "owned data, `spawn` can safely move the entire closure and all its " "associated state into an entirely different task for execution. Like any " diff --git a/doc/po/ja/tutorial.md.po b/doc/po/ja/tutorial.md.po index 26dc7bf0db866..2b4e6e2c148cb 100644 --- a/doc/po/ja/tutorial.md.po +++ b/doc/po/ja/tutorial.md.po @@ -3509,13 +3509,13 @@ msgstr "## 所有クロージャ" #. type: Plain text #: doc/tutorial.md:1510 msgid "" -"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to " +"Owned closures, written `proc`, hold on to " "things that can safely be sent between processes. They copy the values they " "close over, much like managed closures, but they also own them: that is, no " "other code can access them. Owned closures are used in concurrent code, " "particularly for spawning [tasks][tasks]." msgstr "" -"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス" +"`~` `proc` で書き表される所有クロージャは安全にプロセス" "間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ" "うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込" "められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に " @@ -3666,11 +3666,11 @@ msgstr "" #: doc/tutorial.md:1582 msgid "" "`do` is a convenient way to create tasks with the `task::spawn` function. " -"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a " +"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a " "function that takes an owned closure that takes no arguments." msgstr "" "`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。" -"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、" +"`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、" "`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで" "す。" diff --git a/doc/po/tutorial-tasks.md.pot b/doc/po/tutorial-tasks.md.pot index 483cde9d7d016..7a15fe196923f 100644 --- a/doc/po/tutorial-tasks.md.pot +++ b/doc/po/tutorial-tasks.md.pot @@ -213,7 +213,7 @@ msgstr "" #. type: Plain text #: doc/tutorial-tasks.md:102 msgid "" -"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. " +"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. " "Because it accepts only owned closures, and owned closures contain only " "owned data, `spawn` can safely move the entire closure and all its " "associated state into an entirely different task for execution. Like any " diff --git a/doc/po/tutorial.md.pot b/doc/po/tutorial.md.pot index a9c93aa6a8ba5..86937652da93b 100644 --- a/doc/po/tutorial.md.pot +++ b/doc/po/tutorial.md.pot @@ -2683,7 +2683,7 @@ msgstr "" #. type: Plain text #: doc/tutorial.md:1510 msgid "" -"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to " +"Owned closures, written `proc`, hold on to " "things that can safely be sent between processes. They copy the values they " "close over, much like managed closures, but they also own them: that is, no " "other code can access them. Owned closures are used in concurrent code, " @@ -2808,7 +2808,7 @@ msgstr "" #: doc/tutorial.md:1582 msgid "" "`do` is a convenient way to create tasks with the `task::spawn` function. " -"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a " +"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a " "function that takes an owned closure that takes no arguments." msgstr "" diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index adde4ab17e626..d357e3b335ebe 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -91,7 +91,7 @@ _owned types_. The language leaves the implementation details to the standard library. The `spawn` function has a very simple type signature: `fn spawn(f: -~fn())`. Because it accepts only owned closures, and owned closures +proc())`. Because it accepts only owned closures, and owned closures contain only owned data, `spawn` can safely move the entire closure and all its associated state into an entirely different task for execution. Like any closure, the function passed to `spawn` may capture diff --git a/doc/tutorial.md b/doc/tutorial.md index 1b414c4083440..313d36e38bf7e 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1409,7 +1409,7 @@ pervasively in Rust code. ## Owned closures -Owned closures, written `~fn` in analogy to the `~` pointer type, +Owned closures, written `proc`, hold on to things that can safely be sent between processes. They copy the values they close over, much like managed closures, but they also own them: that is, no other code can access @@ -1484,7 +1484,7 @@ parentheses, where it looks more like a typical block of code. `do` is a convenient way to create tasks with the `task::spawn` -function. `spawn` has the signature `spawn(fn: ~fn())`. In other +function. `spawn` has the signature `spawn(fn: proc())`. In other words, it is a function that takes an owned closure that takes no arguments. 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/future.rs b/src/libextra/future.rs index 8f28be4978253..640ced24badd1 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -36,7 +36,7 @@ pub struct Future { } enum FutureState { - Pending(~fn() -> A), + Pending(proc() -> A), Evaluating, Forced(A) } @@ -92,7 +92,7 @@ impl Future { Future {state: Forced(val)} } - pub fn from_fn(f: ~fn() -> A) -> Future { + pub fn from_fn(f: proc() -> A) -> Future { /*! * Create a future from a function. * @@ -120,7 +120,7 @@ impl Future { } } - pub fn spawn(blk: ~fn() -> A) -> Future { + pub fn spawn(blk: proc() -> A) -> Future { /*! * Create a future from a unique closure. * @@ -137,7 +137,7 @@ impl Future { Future::from_port(port) } - pub fn spawn_with(v: B, blk: ~fn(B) -> A) -> Future { + pub fn spawn_with(v: B, blk: proc(B) -> A) -> Future { /*! * Create a future from a unique closure taking one argument. * 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 f7db66dc4e0c4..37deba43e3a15 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -23,7 +23,7 @@ use std::vec; #[cfg(test)] use std::task::SingleThreaded; enum Msg { - Execute(~fn(&T)), + Execute(proc(&T)), Quit } @@ -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() -> ~fn(uint) -> T) + init_fn_factory: || -> proc(uint) -> T) -> TaskPool { assert!(n_tasks >= 1); @@ -57,7 +57,7 @@ impl TaskPool { let (port, chan) = comm::stream::>(); let init_fn = init_fn_factory(); - let task_body: ~fn() = || { + let task_body: proc() = || { let local_data = init_fn(i); loop { match port.recv() { @@ -88,7 +88,7 @@ impl TaskPool { /// Executes the function `f` on a task in the pool. The function /// receives a reference to the local data returned by the `init_fn`. - pub fn execute(&mut self, f: ~fn(&T)) { + pub fn execute(&mut self, f: proc(&T)) { self.channels[self.next_index].send(Execute(f)); self.next_index += 1; if self.next_index == self.channels.len() { self.next_index = 0; } @@ -97,8 +97,8 @@ impl TaskPool { #[test] fn test_task_pool() { - let f: ~fn() -> ~fn(uint) -> uint = || { - let g: ~fn(uint) -> uint = |i| i; + let f: || -> proc(uint) -> uint = || { + let g: proc(uint) -> uint = |i| i; g }; let mut pool = TaskPool::new(4, Some(SingleThreaded), f); diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 14fee38dada2c..e9f38471d4862 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -74,6 +74,11 @@ impl TestDesc { } } +/// Represents a benchmark function. +pub trait TDynBenchFn { + fn run(&self, harness: &mut BenchHarness); +} + // A function that runs a test. If the function returns successfully, // the test succeeds; if the function fails then the test fails. We // may need to come up with a more clever definition of test in order @@ -81,10 +86,10 @@ impl TestDesc { pub enum TestFn { StaticTestFn(extern fn()), StaticBenchFn(extern fn(&mut BenchHarness)), - StaticMetricFn(~fn(&mut MetricMap)), - DynTestFn(~fn()), - DynMetricFn(~fn(&mut MetricMap)), - DynBenchFn(~fn(&mut BenchHarness)) + StaticMetricFn(proc(&mut MetricMap)), + DynTestFn(proc()), + DynMetricFn(proc(&mut MetricMap)), + DynBenchFn(~TDynBenchFn) } impl TestFn { @@ -710,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()); @@ -859,7 +863,7 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, - testfn: ~fn()) { + testfn: proc()) { let testfn_cell = ::std::cell::Cell::new(testfn); do task::spawn { let mut task = task::task(); @@ -878,8 +882,8 @@ pub fn run_test(force_ignore: bool, } match testfn { - DynBenchFn(benchfn) => { - let bs = ::test::bench::benchmark(benchfn); + DynBenchFn(bencher) => { + let bs = ::test::bench::benchmark(|harness| bencher.run(harness)); monitor_ch.send((desc, TrBench(bs))); return; } @@ -1053,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) { @@ -1078,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); @@ -1086,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; @@ -1156,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 89e50f53ab464..8fbb9fc40db23 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) } @@ -394,14 +399,14 @@ impl<'self> Prep<'self> { pub fn exec + Decodable>( - &'self self, blk: ~fn(&mut Exec) -> T) -> T { + &'self self, blk: proc(&mut Exec) -> T) -> T { self.exec_work(blk).unwrap() } fn exec_work + Decodable>( // FIXME(#5121) - &'self self, blk: ~fn(&mut Exec) -> T) -> Work<'self, T> { + &'self self, blk: proc(&mut Exec) -> T) -> Work<'self, T> { let mut bo = Some(blk); debug!("exec_work: looking up {} and {:?}", self.fn_name, diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index f67de4456034b..ec4363e7f05dc 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -322,7 +322,7 @@ diagnostic emitter which records when we hit a fatal error. If the task fails without recording a fatal error then we've encountered a compiler bug and need to present an error. */ -pub fn monitor(f: ~fn(@diagnostic::Emitter)) { +pub fn monitor(f: proc(@diagnostic::Emitter)) { use std::comm::*; // XXX: This is a hack for newsched since it doesn't support split stacks. diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index dc6fbcec3f2a4..05f708355b0e7 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -1101,7 +1101,7 @@ mod test { let handle2 = Cell::new(sched2.make_handle()); let tasksFriendHandle = Cell::new(sched2.make_handle()); - let on_exit: ~fn(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = |exit_status| { handle1.take().send(Shutdown); handle2.take().send(Shutdown); assert!(exit_status.is_success()); @@ -1115,7 +1115,7 @@ mod test { } } - let test_function: ~fn() = || { + let test_function: proc() = || { let io = unsafe { local_io() }; let addr = next_test_ip4(); let maybe_socket = io.udp_bind(addr); 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 d5514eb14d3da..0a1cf05e6feee 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 5e39460ba6a4d..0dfd7adcc50b4 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -23,7 +23,7 @@ use result::{Result, Ok, Err}; use rt::rtio; use vec::ImmutableVector; -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; @@ -367,7 +367,7 @@ mod old_os { } /// Recursively walk a directory structure - pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool { + pub fn walk_dir(p: &Path, f: |&Path| -> bool) -> bool { let r = list_dir(p); r.iter().advance(|q| { let path = &p.join(q); 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/net/unix.rs b/src/libstd/io/net/unix.rs index c6b4a2f2a4268..438261ba8a0a3 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -157,7 +157,7 @@ mod tests { use io::*; use rt::comm::oneshot; - fn smalltest(server: ~fn(UnixStream), client: ~fn(UnixStream)) { + fn smalltest(server: proc(UnixStream), client: proc(UnixStream)) { let server = Cell::new(server); let client = Cell::new(client); do run_in_mt_newsched_task { diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 6df9ea6c60a6d..2d3ecd8a06280 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 213cf5dc07cd5..b10eab0da7510 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::finally::Finally; unsafe { 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 164dc75a5151d..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); } @@ -478,11 +478,11 @@ impl TyVisitor for MovePtrAdaptor { } fn visit_closure_ptr(&mut self, ck: uint) -> bool { - self.align_to::<~fn()>(); + self.align_to::(); if ! self.inner.visit_closure_ptr(ck) { return false } - self.bump_past::<~fn()>(); + self.bump_past::(); true } } 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 48e5887902685..03164fdcff59f 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -93,7 +93,7 @@ mod imp { }) } - fn with_lock(f: &fn() -> T) -> T { + fn with_lock(f: || -> T) -> T { do (|| { unsafe { rust_take_global_args_lock(); diff --git a/src/libstd/rt/basic.rs b/src/libstd/rt/basic.rs index 42ecbf5dc7856..5ac444fae5785 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/context.rs b/src/libstd/rt/context.rs index fcc30ded9542a..39a3e4d57abb3 100644 --- a/src/libstd/rt/context.rs +++ b/src/libstd/rt/context.rs @@ -25,7 +25,7 @@ pub static RED_ZONE: uint = 20 * 1024; // then misalign the regs again. pub struct Context { /// The context entry point, saved here for later destruction - priv start: Option<~~fn()>, + priv start: Option<~proc()>, /// Hold the registers while the task or scheduler is suspended priv regs: ~Registers, /// Lower bound and upper bound for the stack @@ -41,18 +41,24 @@ impl Context { } } - /// Create a new context that will resume execution by running ~fn() - pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context { + /// Create a new context that will resume execution by running proc() + pub fn new(start: proc(), stack: &mut StackSegment) -> Context { // FIXME #7767: Putting main into a ~ so it's a thin pointer and can // be passed to the spawn function. Another unfortunate // allocation let start = ~start; // The C-ABI function that is the task entry point - extern fn task_start_wrapper(f: &~fn()) { (*f)() } + extern fn task_start_wrapper(f: &proc()) { + // XXX(pcwalton): This may be sketchy. + unsafe { + let f: &|| = transmute(f); + (*f)() + } + } let fp: *c_void = task_start_wrapper as *c_void; - let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) }; + let argp: *c_void = unsafe { transmute::<&proc(), *c_void>(&*start) }; let sp: *uint = stack.end(); let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) }; // Save and then immediately load the current context, 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 2709c118191de..fa4746a6bb77f 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -110,7 +110,7 @@ see a failure from the grandchild task. While we could achieve this by having each intermediate task block on its handle, this keeps around the other resources the task was using. To be more efficient, this is accomplished via "tombstones". -A tombstone is a closure, ~fn() -> bool, which will perform any waiting necessary +A tombstone is a closure, proc() -> bool, which will perform any waiting necessary to collect the exit code of descendant tasks. In its environment is captured the KillHandle of whichever task created the tombstone, and perhaps also any tombstones that that task itself had, and finally also another tombstone, @@ -205,7 +205,7 @@ struct KillHandleInner { // Locklessly accessed; protected by the enclosing refcount's barriers. any_child_failed: bool, // A lazy list, consuming which may unwrap() many child tombstones. - child_tombstones: Option<~fn() -> bool>, + child_tombstones: Option bool>, // Protects multiple children simultaneously creating tombstones. graveyard_lock: LittleLock, } @@ -223,7 +223,7 @@ pub struct Death { priv watching_parent: Option, // Action to be done with the exit code. If set, also makes the task wait // until all its watched children exit before collecting the status. - on_exit: Option<~fn(UnwindResult)>, + on_exit: Option, // nesting level counter for task::unkillable calls (0 == killable). priv unkillable: int, // nesting level counter for unstable::atomically calls (0 == can deschedule). @@ -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,8 +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<~fn() -> bool>) -> ~fn() -> 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 f35b657d9ddce..d90dd9899b837 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -97,7 +97,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/mod.rs b/src/libstd/rt/mod.rs index c90aafff20cc4..72e1f6a6e8fac 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -207,7 +207,7 @@ pub mod borrowck; /// # Return value /// /// The return value is used as the process return code. 0 on success, 101 on error. -pub fn start(argc: int, argv: **u8, main: ~fn()) -> int { +pub fn start(argc: int, argv: **u8, main: proc()) -> int { init(argc, argv); let exit_code = run(main); @@ -221,7 +221,7 @@ pub fn start(argc: int, argv: **u8, main: ~fn()) -> int { /// /// This is appropriate for running code that must execute on the main thread, /// such as the platform event loop and GUI. -pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int { +pub fn start_on_main_thread(argc: int, argv: **u8, main: proc()) -> int { init(argc, argv); let exit_code = run_on_main_thread(main); cleanup(); @@ -254,15 +254,15 @@ pub fn cleanup() { /// Configures the runtime according to the environment, by default /// using a task scheduler with the same number of threads as cores. /// Returns a process exit code. -pub fn run(main: ~fn()) -> int { +pub fn run(main: proc()) -> int { run_(main, false) } -pub fn run_on_main_thread(main: ~fn()) -> int { +pub fn run_on_main_thread(main: proc()) -> int { run_(main, true) } -fn run_(main: ~fn(), use_main_sched: bool) -> int { +fn run_(main: proc(), use_main_sched: bool) -> int { static DEFAULT_ERROR_CODE: int = 101; let nscheds = util::default_sched_threads(); @@ -341,7 +341,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { // When the main task exits, after all the tasks in the main // task tree, shut down the schedulers and set the exit code. let handles = Cell::new(handles); - let on_exit: ~fn(UnwindResult) = |exit_success| { + let on_exit: proc(UnwindResult) = |exit_success| { unsafe { assert!(!(*exited_already.get()).swap(true, SeqCst), "the runtime already exited"); diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index 35fb8baa6ce68..76c7a024fe791 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 26cd405efe2e4..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 @@ -990,7 +990,9 @@ mod test { assert!(Task::on_appropriate_sched()); }; - let on_exit: ~fn(UnwindResult) = |exit_status| rtassert!(exit_status.is_success()); + let on_exit: proc(UnwindResult) = |exit_status| { + rtassert!(exit_status.is_success()) + }; task.death.on_exit = Some(on_exit); sched.bootstrap(task); diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index e73d15abb6c76..3fe555de56c9e 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -139,7 +139,10 @@ impl Task { // A helper to build a new task using the dynamically found // scheduler and task. Only works in GreenTask context. - pub fn build_homed_child(stack_size: Option, f: ~fn(), home: SchedHome) -> ~Task { + pub fn build_homed_child(stack_size: Option, + f: proc(), + home: SchedHome) + -> ~Task { let f = Cell::new(f); let home = Cell::new(home); do Local::borrow |running_task: &mut Task| { @@ -153,11 +156,14 @@ impl Task { } } - pub fn build_child(stack_size: Option, f: ~fn()) -> ~Task { + pub fn build_child(stack_size: Option, f: proc()) -> ~Task { Task::build_homed_child(stack_size, f, AnySched) } - pub fn build_homed_root(stack_size: Option, f: ~fn(), home: SchedHome) -> ~Task { + pub fn build_homed_root(stack_size: Option, + f: proc(), + home: SchedHome) + -> ~Task { let f = Cell::new(f); let home = Cell::new(home); do Local::borrow |running_task: &mut Task| { @@ -171,7 +177,7 @@ impl Task { } } - pub fn build_root(stack_size: Option, f: ~fn()) -> ~Task { + pub fn build_root(stack_size: Option, f: proc()) -> ~Task { Task::build_homed_root(stack_size, f, AnySched) } @@ -196,21 +202,21 @@ impl Task { pub fn new_root(stack_pool: &mut StackPool, stack_size: Option, - start: ~fn()) -> Task { + start: proc()) -> Task { Task::new_root_homed(stack_pool, stack_size, AnySched, start) } pub fn new_child(&mut self, stack_pool: &mut StackPool, stack_size: Option, - start: ~fn()) -> Task { + start: proc()) -> Task { self.new_child_homed(stack_pool, stack_size, AnySched, start) } pub fn new_root_homed(stack_pool: &mut StackPool, stack_size: Option, home: SchedHome, - start: ~fn()) -> Task { + start: proc()) -> Task { Task { heap: LocalHeap::new(), gc: GarbageCollector, @@ -233,7 +239,7 @@ impl Task { stack_pool: &mut StackPool, stack_size: Option, home: SchedHome, - start: ~fn()) -> Task { + start: proc()) -> Task { Task { heap: LocalHeap::new(), gc: GarbageCollector, @@ -276,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 @@ -404,7 +410,10 @@ impl Drop for Task { impl Coroutine { - pub fn new(stack_pool: &mut StackPool, stack_size: Option, start: ~fn()) -> Coroutine { + pub fn new(stack_pool: &mut StackPool, + stack_size: Option, + start: proc()) + -> Coroutine { let stack_size = match stack_size { Some(size) => size, None => env::min_stack() @@ -425,9 +434,9 @@ impl Coroutine { } } - fn build_start_wrapper(start: ~fn()) -> ~fn() { + fn build_start_wrapper(start: proc()) -> proc() { let start_cell = Cell::new(start); - let wrapper: ~fn() = || { + let wrapper: proc() = || { // First code after swap to this new context. Run our // cleanup job. unsafe { @@ -485,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 { @@ -503,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/rt/test.rs b/src/libstd/rt/test.rs index 19ab36a6ac4d9..53e504fe8fb8d 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -65,28 +65,28 @@ pub fn new_test_sched() -> Scheduler { return sched; } -pub fn run_in_uv_task(f: ~fn()) { +pub fn run_in_uv_task(f: proc()) { let f = Cell::new(f); do run_in_bare_thread { run_in_uv_task_core(f.take()); } } -pub fn run_in_newsched_task(f: ~fn()) { +pub fn run_in_newsched_task(f: proc()) { let f = Cell::new(f); do run_in_bare_thread { run_in_newsched_task_core(f.take()); } } -pub fn run_in_uv_task_core(f: ~fn()) { +pub fn run_in_uv_task_core(f: proc()) { use rt::sched::Shutdown; let mut sched = ~new_test_uv_sched(); let exit_handle = Cell::new(sched.make_handle()); - let on_exit: ~fn(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = |exit_status| { exit_handle.take().send(Shutdown); rtassert!(exit_status.is_success()); }; @@ -96,13 +96,13 @@ pub fn run_in_uv_task_core(f: ~fn()) { sched.bootstrap(task); } -pub fn run_in_newsched_task_core(f: ~fn()) { +pub fn run_in_newsched_task_core(f: proc()) { use rt::sched::Shutdown; let mut sched = ~new_test_sched(); let exit_handle = Cell::new(sched.make_handle()); - let on_exit: ~fn(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = |exit_status| { exit_handle.take().send(Shutdown); rtassert!(exit_status.is_success()); }; @@ -196,7 +196,7 @@ pub fn prepare_for_lots_of_tests() { /// Create more than one scheduler and run a function in a task /// in one of the schedulers. The schedulers will stay alive /// until the function `f` returns. -pub fn run_in_mt_newsched_task(f: ~fn()) { +pub fn run_in_mt_newsched_task(f: proc()) { use os; use from_str::FromStr; use rt::sched::Shutdown; @@ -246,7 +246,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { } let handles = Cell::new(handles); - let on_exit: ~fn(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = |exit_status| { let mut handles = handles.take(); // Tell schedulers to exit for handle in handles.mut_iter() { @@ -295,16 +295,16 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { } /// Test tasks will abort on failure instead of unwinding -pub fn spawntask(f: ~fn()) { +pub fn spawntask(f: proc()) { Scheduler::run_task(Task::build_child(None, f)); } /// Create a new task and run it right now. Aborts on failure -pub fn spawntask_later(f: ~fn()) { +pub fn spawntask_later(f: proc()) { Scheduler::run_task_later(Task::build_child(None, f)); } -pub fn spawntask_random(f: ~fn()) { +pub fn spawntask_random(f: proc()) { use rand::{Rand, rng}; let mut rng = rng(); @@ -317,11 +317,11 @@ pub fn spawntask_random(f: ~fn()) { } } -pub fn spawntask_try(f: ~fn()) -> Result<(),()> { +pub fn spawntask_try(f: proc()) -> Result<(),()> { let (port, chan) = oneshot(); let chan = Cell::new(chan); - let on_exit: ~fn(UnwindResult) = |exit_status| chan.take().send(exit_status); + let on_exit: proc(UnwindResult) = |exit_status| chan.take().send(exit_status); let mut new_task = Task::build_root(None, f); new_task.death.on_exit = Some(on_exit); @@ -334,7 +334,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> { } /// Spawn a new task in a new scheduler and return a thread handle. -pub fn spawntask_thread(f: ~fn()) -> Thread { +pub fn spawntask_thread(f: proc()) -> Thread { let f = Cell::new(f); @@ -346,7 +346,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread { } /// Get a ~Task for testing purposes other than actually scheduling it. -pub fn with_test_task(blk: ~fn(~Task) -> ~Task) { +pub fn with_test_task(blk: proc(~Task) -> ~Task) { do run_in_bare_thread { let mut sched = ~new_test_sched(); let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{})); diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index 5e535d994f9ef..e364e5a6603f4 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -35,7 +35,7 @@ static DEFAULT_STACK_SIZE: libc::size_t = 1024*1024; impl Thread { - pub fn start(main: ~fn()) -> Thread { + pub fn start(main: proc()) -> Thread { // This is the starting point of rust os threads. The first thing we do // is make sure that we don't trigger __morestack (also why this has a // no_split_stack annotation), and then we extract the main function @@ -45,7 +45,7 @@ impl Thread { use rt::context; unsafe { context::record_stack_bounds(0, uint::max_value); - let f: ~~fn() = cast::transmute(trampoline); + let f: ~proc() = cast::transmute(trampoline); (*f)(); } unsafe { cast::transmute(0) } @@ -67,7 +67,7 @@ impl Thread { #[cfg(windows)] fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return, - tramp: ~~fn()) -> rust_thread { + tramp: ~proc()) -> rust_thread { unsafe { let ptr: *mut libc::c_void = cast::transmute(tramp); CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, thread_start, ptr, 0, ptr::mut_null()) @@ -82,7 +82,7 @@ fn native_thread_join(native: rust_thread) { #[cfg(unix)] fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return, - tramp: ~~fn()) -> rust_thread { + tramp: ~proc()) -> rust_thread { use unstable::intrinsics; let mut native: libc::pthread_t = unsafe { intrinsics::uninit() }; 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 51c11b69972fb..d024d50664a2a 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -195,7 +195,7 @@ pub struct TaskOpts { // FIXME (#3724): Replace the 'consumed' bit with move mode on self pub struct TaskBuilder { opts: TaskOpts, - priv gen_body: Option<~fn(v: ~fn()) -> ~fn()>, + priv gen_body: Option proc()>, priv can_not_copy: Option, priv consumed: bool, } @@ -340,18 +340,18 @@ impl TaskBuilder { * generator by applying the task body which results from the * existing body generator to the new body generator. */ - pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { + pub fn add_wrapper(&mut self, wrapper: proc(v: proc()) -> proc()) { let prev_gen_body = self.gen_body.take(); let prev_gen_body = match prev_gen_body { Some(gen) => gen, None => { - let f: ~fn(~fn()) -> ~fn() = |body| body; + let f: proc(proc()) -> proc() = |body| body; f } }; let prev_gen_body = Cell::new(prev_gen_body); let next_gen_body = { - let f: ~fn(~fn()) -> ~fn() = |body| { + let f: proc(proc()) -> proc() = |body| { let prev_gen_body = prev_gen_body.take(); wrapper(prev_gen_body(body)) }; @@ -372,7 +372,7 @@ impl TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - pub fn spawn(&mut self, f: ~fn()) { + pub fn spawn(&mut self, f: proc()) { let gen_body = self.gen_body.take(); let notify_chan = self.opts.notify_chan.take(); let name = self.opts.name.take(); @@ -399,7 +399,7 @@ impl TaskBuilder { } /// Runs a task, while transferring ownership of one argument to the child. - pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { + pub fn spawn_with(&mut self, arg: A, f: proc(v: A)) { let arg = Cell::new(arg); do self.spawn { f(arg.take()); @@ -419,7 +419,7 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - pub fn try(&mut self, f: ~fn() -> T) -> Result { + pub fn try(&mut self, f: proc() -> T) -> Result { let (po, ch) = stream::(); let result = self.future_result(); @@ -468,20 +468,20 @@ pub fn default_task_opts() -> TaskOpts { /// the provided unique closure. /// /// This function is equivalent to `task().spawn(f)`. -pub fn spawn(f: ~fn()) { +pub fn spawn(f: proc()) { let mut task = task(); task.spawn(f) } /// Creates a child task unlinked from the current one. If either this /// task or the child task fails, the other will not be killed. -pub fn spawn_unlinked(f: ~fn()) { +pub fn spawn_unlinked(f: proc()) { let mut task = task(); task.unlinked(); task.spawn(f) } -pub fn spawn_supervised(f: ~fn()) { +pub fn spawn_supervised(f: proc()) { /*! * Creates a child task supervised by the current one. If the child * task fails, the parent will not be killed, but if the parent fails, @@ -498,13 +498,13 @@ pub fn spawn_supervised(f: ~fn()) { /// (Note that this convenience wrapper still uses linked-failure, so the /// child's children will still be killable by the parent. For the fastest /// possible spawn mode, use task::task().unlinked().indestructible().spawn.) -pub fn spawn_indestructible(f: ~fn()) { +pub fn spawn_indestructible(f: proc()) { let mut task = task(); task.indestructible(); task.spawn(f) } -pub fn spawn_with(arg: A, f: ~fn(v: A)) { +pub fn spawn_with(arg: A, f: proc(v: A)) { /*! * Runs a task, while transferring ownership of one argument to the * child. @@ -519,7 +519,7 @@ pub fn spawn_with(arg: A, f: ~fn(v: A)) { task.spawn_with(arg, f) } -pub fn spawn_sched(mode: SchedMode, f: ~fn()) { +pub fn spawn_sched(mode: SchedMode, f: proc()) { /*! * Creates a new task on a new or existing scheduler. * @@ -537,7 +537,7 @@ pub fn spawn_sched(mode: SchedMode, f: ~fn()) { task.spawn(f) } -pub fn try(f: ~fn() -> T) -> Result { +pub fn try(f: proc() -> T) -> Result { /*! * Execute a function in another task and return either the return value * of the function or result::err. @@ -554,7 +554,7 @@ pub fn try(f: ~fn() -> 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 { @@ -1033,7 +1033,7 @@ fn test_add_wrapper() { let ch = Cell::new(ch); do b0.add_wrapper |body| { let ch = Cell::new(ch.take()); - let result: ~fn() = || { + let result: proc() = || { let ch = ch.take(); body(); ch.send(()); @@ -1211,7 +1211,7 @@ fn test_spawn_sched_blocking() { } #[cfg(test)] -fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) { +fn avoid_copying_the_body(spawnfn: |v: proc()|) { let (p, ch) = stream::(); let x = ~1; @@ -1337,7 +1337,7 @@ fn test_child_doesnt_ref_parent() { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) static generations: uint = 16; - fn child_no(x: uint) -> ~fn() { + fn child_no(x: uint) -> proc() { return || { if x < generations { let mut t = task(); diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index b1d72c063ac8e..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. @@ -562,13 +564,13 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc, result } -pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { +pub fn spawn_raw(mut opts: TaskOpts, f: proc()) { assert!(in_green_task_context()); let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised)); let indestructible = opts.indestructible; - let child_wrapper: ~fn() = || { + let child_wrapper: proc() = || { // Child task runs this code. // If child data is 'None', the enlist is vacuously successful. @@ -589,12 +591,14 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { } } }; + // Should be run after the local-borrowed task is returned. + let f_cell = Cell::new(f); if enlist_success { if indestructible { - do unkillable { f() } + do unkillable { f_cell.take()() } } else { - f() + f_cell.take()() } } }; @@ -683,7 +687,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { if opts.notify_chan.is_some() { let notify_chan = opts.notify_chan.take_unwrap(); let notify_chan = Cell::new(notify_chan); - let on_exit: ~fn(UnwindResult) = |task_result| { + let on_exit: proc(UnwindResult) = |task_result| { notify_chan.take().send(task_result) }; task.death.on_exit = Some(on_exit); 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 1ce228250c971..a6ca8974577d6 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -153,7 +153,7 @@ 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 { unsafe { // dlerror isn't thread safe, so we need to lock around this entire // sequence. `atomically` asserts that we don't do anything that @@ -227,7 +227,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 c1365a44bc913..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 }; @@ -54,7 +54,6 @@ impl<'self,T> Finally for &'self fn() -> T { } } -finally_fn!(~fn() -> T) finally_fn!(extern "Rust" fn() -> T) struct Finallyalizer<'self> { @@ -96,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); } @@ -109,12 +108,3 @@ fn test_compact() { but_always_run_this_function); } -#[test] -fn test_owned() { - fn spawn_with_finalizer(f: ~fn()) { - do spawn { do f.finally { } } - } - let owned: ~fn() = || { }; - spawn_with_finalizer(owned); -} - diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index ea03ea6f551c2..d1ac5611e6ecb 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -35,7 +35,7 @@ for it to terminate. The executing thread has no access to a task pointer and will be using a normal large stack. */ -pub fn run_in_bare_thread(f: ~fn()) { +pub fn run_in_bare_thread(f: proc()) { use cell::Cell; use rt::thread::Thread; 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 0e1f5fc1bdcfc..a7b4c66b695c3 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; @@ -343,7 +343,7 @@ impl LittleLock { } } - pub unsafe fn lock(&self, f: &fn() -> T) -> T { + pub unsafe fn lock(&self, f: || -> T) -> T { do atomically { rust_lock_little_lock(self.l); do (|| { @@ -354,7 +354,7 @@ impl LittleLock { } } - pub unsafe fn try_lock(&self, f: &fn() -> T) -> Option { + pub unsafe fn try_lock(&self, f: || -> T) -> Option { do atomically { if rust_trylock_little_lock(self.l) { Some(do (|| { @@ -372,7 +372,7 @@ impl LittleLock { rust_signal_little_lock(self.l); } - pub unsafe fn lock_and_wait(&self, f: &fn() -> bool) { + pub unsafe fn lock_and_wait(&self, f: || -> bool) { do atomically { rust_lock_little_lock(self.l); do (|| { @@ -432,7 +432,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 { @@ -446,14 +446,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 { @@ -467,7 +467,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/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 2af6d141aa178..189cc8e827c83 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -41,7 +41,8 @@ pub enum ObsoleteSyntax { ObsoleteLoopAsContinue, ObsoleteEnumWildcard, ObsoleteStructWildcard, - ObsoleteVecDotDotWildcard + ObsoleteVecDotDotWildcard, + ObsoleteBoxedClosure, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -128,6 +129,11 @@ impl ParserObsoleteMethods for Parser { "vec slice wildcard", "use `..` instead of `.._` for matching slices" ), + ObsoleteBoxedClosure => ( + "managed or owned closure", + "managed closures have been removed and owned closures are \ + now written `proc()`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1b2e18f3ca514..2ea6878f4a370 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1273,15 +1273,17 @@ impl Parser { pub fn parse_box_or_uniq_pointee(&self, sigil: ast::Sigil, ctor: &fn(v: mt) -> ty_) -> ty_ { - // ~'foo fn() or ~fn() are parsed directly as fn types: + // ~'foo fn() or ~fn() are parsed directly as obsolete fn types: match *self.token { token::LIFETIME(*) => { let lifetime = self.parse_lifetime(); + self.obsolete(*self.last_span, ObsoleteBoxedClosure); return self.parse_ty_closure(Some(sigil), Some(lifetime)); } - token::IDENT(*) => { + token::IDENT(*) if sigil == ast::BorrowedSigil => { if self.token_is_old_style_closure_keyword() { + self.obsolete(*self.last_span, ObsoleteBoxedClosure); return self.parse_ty_closure(Some(sigil), None); } } diff --git a/src/test/bench/task-perf-linked-failure.rs b/src/test/bench/task-perf-linked-failure.rs index 54a05c7257e83..73ecd33bc7ca9 100644 --- a/src/test/bench/task-perf-linked-failure.rs +++ b/src/test/bench/task-perf-linked-failure.rs @@ -53,7 +53,7 @@ fn grandchild_group(num_tasks: uint) { // Master grandchild task exits early. } -fn spawn_supervised_blocking(myname: &str, f: ~fn()) { +fn spawn_supervised_blocking(myname: &str, f: proc()) { let mut builder = task::task(); let res = builder.future_result(); builder.supervised(); diff --git a/src/test/compile-fail/borrowck-call-sendfn.rs b/src/test/compile-fail/borrowck-call-sendfn.rs index 8dc86c9a16310..42dee384116c9 100644 --- a/src/test/compile-fail/borrowck-call-sendfn.rs +++ b/src/test/compile-fail/borrowck-call-sendfn.rs @@ -11,7 +11,7 @@ // xfail-test #2978 struct Foo { - f: ~fn() + f: proc() } fn call(x: @Foo) { diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index 5994b9e85d5ae..aa50f9ac3fee0 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -1,13 +1,8 @@ pub fn main() { - let foo = ~3; - let _pfoo = &foo; - let _f: ~fn() -> int = || *foo + 5; - //~^ ERROR cannot move `foo` - // FIXME(#2202) - Due to the way that borrowck treats closures, // you get two error reports here. let bar = ~3; let _g = || { //~ ERROR capture of moved value - let _h: ~fn() -> int = || *bar; //~ ERROR capture of moved value + let _h: proc() -> int = || *bar; //~ ERROR capture of moved value }; } diff --git a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs index 5e789e99c0559..b6ad3ed95a4b4 100644 --- a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs +++ b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs @@ -1,4 +1,4 @@ -fn call_f(f: ~fn:Send() -> int) -> int { +fn call_f(f: proc() -> int) -> int { f() } diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index 525f8f4a932b1..00eb31485b9d7 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -9,10 +9,10 @@ // except according to those terms. struct X { - field: ~fn:Send(), + field: &'static fn:Send(), } -fn foo(blk: ~fn:()) -> X { +fn foo(blk: &'static fn:()) -> X { return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds } diff --git a/src/test/compile-fail/issue-8615.rs b/src/test/compile-fail/issue-8615.rs deleted file mode 100644 index 10d3e9ed3f10c..0000000000000 --- a/src/test/compile-fail/issue-8615.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let _: @'static whatever fn(); //~ ERROR expected `fn`, found `whatever` - let _: @'static fn(); -} diff --git a/src/test/compile-fail/kindck-nonsendable-1.rs b/src/test/compile-fail/kindck-nonsendable-1.rs index 4472f042242ac..308eb637cd0b9 100644 --- a/src/test/compile-fail/kindck-nonsendable-1.rs +++ b/src/test/compile-fail/kindck-nonsendable-1.rs @@ -14,7 +14,7 @@ fn foo(_x: @uint) {} fn main() { let x = @3u; - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` + let _: proc() = || foo(x); //~ ERROR does not fulfill `Send` + let _: proc() = || foo(x); //~ ERROR does not fulfill `Send` + let _: proc() = || foo(x); //~ ERROR does not fulfill `Send` } diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs index bb5851ac5c8f1..bfef15ea1731c 100644 --- a/src/test/compile-fail/kindck-send.rs +++ b/src/test/compile-fail/kindck-send.rs @@ -47,7 +47,7 @@ fn test<'a,T,U:Send>(_: &'a int) { // but closure and object types can have lifetime bounds which make // them not ok (FIXME #5121) - // assert_send::<~fn:'a()>(); // ERROR does not fulfill `Send` + // assert_send::(); // ERROR does not fulfill `Send` // assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send` // unsafe ptrs are ok unless they point at unsendable things diff --git a/src/test/compile-fail/moves-sru-moved-field.rs b/src/test/compile-fail/moves-sru-moved-field.rs index 660e5596ca552..57c1cb5ecc640 100644 --- a/src/test/compile-fail/moves-sru-moved-field.rs +++ b/src/test/compile-fail/moves-sru-moved-field.rs @@ -1,4 +1,4 @@ -type Noncopyable = ~fn(); +type Noncopyable = proc(); struct Foo { copied: int, diff --git a/src/test/compile-fail/once-cant-call-twice-on-heap.rs b/src/test/compile-fail/once-cant-call-twice-on-heap.rs index e266a56ded44b..81e140567e4f4 100644 --- a/src/test/compile-fail/once-cant-call-twice-on-heap.rs +++ b/src/test/compile-fail/once-cant-call-twice-on-heap.rs @@ -16,7 +16,7 @@ extern mod extra; use extra::arc; use std::util; -fn foo(blk: ~once fn()) { +fn foo(blk: proc()) { blk(); blk(); //~ ERROR use of moved value } diff --git a/src/test/compile-fail/once-cant-move-out-of-non-once-on-heap.rs b/src/test/compile-fail/once-cant-move-out-of-non-once-on-heap.rs deleted file mode 100644 index cc40fb6b8d88e..0000000000000 --- a/src/test/compile-fail/once-cant-move-out-of-non-once-on-heap.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Testing guarantees provided by once functions. -// This program would segfault if it were legal. - -extern mod extra; -use extra::arc; -use std::util; - -fn foo(blk: ~fn()) { - blk(); - blk(); -} - -fn main() { - let x = arc::Arc::new(true); - do foo { - assert!(*x.get()); - util::ignore(x); //~ ERROR cannot move out of captured outer variable - } -} diff --git a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs index 5c979955ec9ae..a743ff81b301a 100644 --- a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs +++ b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs @@ -11,7 +11,7 @@ // check that the &int here does not cause us to think that `foo` // contains region pointers -struct foo(~fn(x: &int)); +struct foo(proc(x: &int)); fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters diff --git a/src/test/debug-info/lexical-scope-in-unique-closure.rs b/src/test/debug-info/lexical-scope-in-unique-closure.rs index 63a223a330bfb..da9220322dd74 100644 --- a/src/test/debug-info/lexical-scope-in-unique-closure.rs +++ b/src/test/debug-info/lexical-scope-in-unique-closure.rs @@ -51,7 +51,7 @@ fn main() { zzz(); sentinel(); - let unique_closure: ~fn(int) = |x| { + let unique_closure: proc(int) = |x| { zzz(); sentinel(); diff --git a/src/test/debug-info/var-captured-in-sendable-closure.rs b/src/test/debug-info/var-captured-in-sendable-closure.rs index efc93d135a28c..664e377c9fbe9 100644 --- a/src/test/debug-info/var-captured-in-sendable-closure.rs +++ b/src/test/debug-info/var-captured-in-sendable-closure.rs @@ -39,7 +39,7 @@ fn main() { let owned = ~5; - let closure: ~fn() = || { + let closure: proc() = || { zzz(); do_something(&constant, &a_struct.a, owned); }; diff --git a/src/test/pretty/fn-types.rs b/src/test/pretty/fn-types.rs index 27e56fb6074a1..ffa6f03909b02 100644 --- a/src/test/pretty/fn-types.rs +++ b/src/test/pretty/fn-types.rs @@ -12,5 +12,5 @@ fn from_foreign_fn(_x: fn()) { } fn from_stack_closure(_x: ||) { } -fn from_unique_closure(_x: ~fn()) { } +fn from_unique_closure(_x: proc()) { } fn main() { } diff --git a/src/test/run-fail/unwind-box-fn-unique.rs b/src/test/run-fail/unwind-box-fn-unique.rs index 1f1b57aa7048a..b28a2a6f1f032 100644 --- a/src/test/run-fail/unwind-box-fn-unique.rs +++ b/src/test/run-fail/unwind-box-fn-unique.rs @@ -18,7 +18,7 @@ fn failfn() { fn main() { let y = ~0; - let x: @~fn() = @(|| { + let x: @proc() = @(|| { error!("{:?}", y.clone()); }); failfn(); diff --git a/src/test/run-pass/block-arg-call-as.rs b/src/test/run-pass/block-arg-call-as.rs index 6a59278982ad3..5aa28258792e6 100644 --- a/src/test/run-pass/block-arg-call-as.rs +++ b/src/test/run-pass/block-arg-call-as.rs @@ -10,7 +10,7 @@ extern mod extra; -fn asSendfn( f : ~fn()->uint ) -> uint { +fn asSendfn( f : proc()->uint ) -> uint { return f(); } diff --git a/src/test/run-pass/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck-move-by-capture-ok.rs index f6328c8c65822..2f186cc3fba30 100644 --- a/src/test/run-pass/borrowck-move-by-capture-ok.rs +++ b/src/test/run-pass/borrowck-move-by-capture-ok.rs @@ -1,5 +1,5 @@ pub fn main() { let bar = ~3; - let h: ~fn() -> int = || *bar; + let h: proc() -> int = || *bar; assert_eq!(h(), 3); } diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs index 64be8dab6e702..c6227fdcc5eff 100644 --- a/src/test/run-pass/cap-clause-move.rs +++ b/src/test/run-pass/cap-clause-move.rs @@ -13,11 +13,11 @@ use std::ptr; pub fn main() { let x = ~3; let y = ptr::to_unsafe_ptr(&(*x)) as uint; - let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; + let snd_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert_eq!(snd_move(), y); let x = ~4; let y = ptr::to_unsafe_ptr(&(*x)) as uint; - let lam_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; + let lam_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; assert_eq!(lam_move(), y); } diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs index f6a7856dccccf..cceb0f353fb3a 100644 --- a/src/test/run-pass/clone-with-exterior.rs +++ b/src/test/run-pass/clone-with-exterior.rs @@ -19,7 +19,7 @@ struct Pair { pub fn main() { let z = ~Pair { a : 10, b : 12}; - let f: ~fn() = || { + let f: proc() = || { assert_eq!(z.a, 10); assert_eq!(z.b, 12); }; diff --git a/src/test/run-pass/closure-bounds-can-capture-chan.rs b/src/test/run-pass/closure-bounds-can-capture-chan.rs index d35d6d9f07e4e..16c7eaf1037fd 100644 --- a/src/test/run-pass/closure-bounds-can-capture-chan.rs +++ b/src/test/run-pass/closure-bounds-can-capture-chan.rs @@ -10,7 +10,7 @@ use std::comm; -fn foo(blk: ~fn:Send()) { +fn foo(blk: proc()) { blk(); } diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index 80e16af922847..023381949a357 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -15,8 +15,8 @@ extern mod extra; * * The hash should concentrate entropy in the lower bits. */ -type HashFn = ~fn(K) -> uint; -type EqFn = ~fn(K, K) -> bool; +type HashFn = proc(K) -> uint; +type EqFn = proc(K, K) -> bool; struct LM { resize_at: uint, size: uint } diff --git a/src/test/run-pass/issue-2190-1.rs b/src/test/run-pass/issue-2190-1.rs index f3a81771c2137..0aaaa58fdd257 100644 --- a/src/test/run-pass/issue-2190-1.rs +++ b/src/test/run-pass/issue-2190-1.rs @@ -11,7 +11,7 @@ // xfail-test static generations: uint = 1024+256+128+49; -fn child_no(x: uint) -> ~fn() { +fn child_no(x: uint) -> proc() { || { if x < generations { task::spawn(child_no(x+1)); diff --git a/src/test/run-pass/issue-2190.rs b/src/test/run-pass/issue-2190.rs index 05869952fb8b5..aeb4aad7d8315 100644 --- a/src/test/run-pass/issue-2190.rs +++ b/src/test/run-pass/issue-2190.rs @@ -10,7 +10,7 @@ // xfail-test type t = { - f: ~fn() + f: proc() }; pub fn main() { diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index f860426ffd270..0b8fcdfbd8494 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -17,7 +17,7 @@ use std::path::{Path}; use std::path; use std::result; -type rsrc_loader = ~fn(path: &Path) -> result::Result<~str, ~str>; +type rsrc_loader = proc(path: &Path) -> result::Result<~str, ~str>; fn tester() { diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index 8ed70a7ee32d2..b283ba67d59bd 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -4,7 +4,7 @@ use std::comm::Chan; use std::task; type RingBuffer = ~[f64]; -type SamplesFn = ~fn(samples: &RingBuffer); +type SamplesFn = proc(samples: &RingBuffer); enum Msg { diff --git a/src/test/run-pass/issue-6141-leaking-owned-fn.rs b/src/test/run-pass/issue-6141-leaking-owned-fn.rs deleted file mode 100644 index 98d2ca5d9424e..0000000000000 --- a/src/test/run-pass/issue-6141-leaking-owned-fn.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn run(f: &fn()) { - f() -} - -pub fn main() { - let f: ~fn() = || (); - run(f); -} diff --git a/src/test/run-pass/newlambdas-ret-infer.rs b/src/test/run-pass/newlambdas-ret-infer.rs index 6d6757890ad3e..e5844785a50f9 100644 --- a/src/test/run-pass/newlambdas-ret-infer.rs +++ b/src/test/run-pass/newlambdas-ret-infer.rs @@ -11,7 +11,7 @@ // Test that the lambda kind is inferred correctly as a return // expression -fn unique() -> ~fn() { return || (); } +fn unique() -> proc() { return || (); } pub fn main() { } diff --git a/src/test/run-pass/newlambdas-ret-infer2.rs b/src/test/run-pass/newlambdas-ret-infer2.rs index 17ff8ce94d90f..ccf1997498be1 100644 --- a/src/test/run-pass/newlambdas-ret-infer2.rs +++ b/src/test/run-pass/newlambdas-ret-infer2.rs @@ -11,7 +11,7 @@ // Test that the lambda kind is inferred correctly as a return // expression -fn unique() -> ~fn() { || () } +fn unique() -> proc() { || () } pub fn main() { } diff --git a/src/test/run-pass/once-move-out-on-heap.rs b/src/test/run-pass/once-move-out-on-heap.rs index 858f8ec07c4d9..bf0af534597e7 100644 --- a/src/test/run-pass/once-move-out-on-heap.rs +++ b/src/test/run-pass/once-move-out-on-heap.rs @@ -17,7 +17,7 @@ extern mod extra; use extra::arc; use std::util; -fn foo(blk: ~once fn()) { +fn foo(blk: proc()) { blk(); } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 05aa1e7460839..5dd8ea96d3738 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -69,6 +69,6 @@ pub fn main() { assert_eq!(q.y, !(p.y)); // Issue #1733 - let result: ~fn(int) = |_|(); + let result: proc(int) = |_|(); result(p[true]); } diff --git a/src/test/run-pass/sendfn-generic-fn.rs b/src/test/run-pass/sendfn-generic-fn.rs deleted file mode 100644 index d077db69c2a8c..0000000000000 --- a/src/test/run-pass/sendfn-generic-fn.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-fast - -use std::task; - -pub fn main() { test05(); } - -#[deriving(Clone)] -struct Pair { - a: A, - b: B, -} - -fn make_generic_record(a: A, b: B) -> Pair { - return Pair {a: a, b: b}; -} - -fn test05_start(f: &~fn(v: f64, v: ~str) -> Pair) { - let p = (*f)(22.22, ~"Hi"); - info!("{:?}", p.clone()); - assert!(p.a == 22.22); - assert!(p.b == ~"Hi"); - - let q = (*f)(44.44, ~"Ho"); - info!("{:?}", q.clone()); - assert!(q.a == 44.44); - assert!(q.b == ~"Ho"); -} - -fn spawn(f: extern fn(&~fn(A,B)->Pair)) { - let arg: ~fn(A, B) -> Pair = |a, b| make_generic_record(a, b); - task::spawn(|| f(&arg)); -} - -fn test05() { - spawn::(test05_start); -} diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index ecf1830864cd1..91bc8345845d9 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -13,13 +13,13 @@ use std::task; pub fn main() { test05(); } -fn test05_start(f: ~fn(int)) { +fn test05_start(f: proc(int)) { f(22); } fn test05() { let three = ~3; - let fn_to_send: ~fn(int) = |n| { + let fn_to_send: proc(int) = |n| { error!("{}", *three + n); // will copy x into the closure assert_eq!(*three, 3); }; diff --git a/src/test/run-pass/swap-overlapping.rs b/src/test/run-pass/swap-overlapping.rs index 5349d0554b1b7..986a9a8c49c31 100644 --- a/src/test/run-pass/swap-overlapping.rs +++ b/src/test/run-pass/swap-overlapping.rs @@ -34,8 +34,8 @@ pub enum TestName { } pub enum TestFn { - DynTestFn(~fn()), - DynBenchFn(~fn(&mut int)) + DynTestFn(proc()), + DynBenchFn(proc(&mut int)) } pub struct TestDesc { diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 10116e569467c..395d6b0b51ad2 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -44,7 +44,7 @@ fn notify(ch: Chan, v: @mut bool) -> notify { } } -fn joinable(f: ~fn()) -> Port { +fn joinable(f: proc()) -> Port { fn wrapper(c: Chan, f: &fn()) { let b = @mut false; error!("wrapper: task=%? allocated v=%x", diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index e8e3d337838de..a10753451400a 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -40,7 +40,7 @@ fn test_tempdir() { fn test_rm_tempdir() { let (rd, wr) = stream(); - let f: ~fn() = || { + let f: proc() = || { let tmp = TempDir::new("test_rm_tempdir").unwrap(); wr.send(tmp.path().clone()); fail!("fail to unwind past `tmp`"); @@ -52,7 +52,7 @@ fn test_rm_tempdir() { let tmp = TempDir::new("test_rm_tempdir").unwrap(); let path = tmp.path().clone(); let cell = Cell::new(tmp); - let f: ~fn() = || { + let f: proc() = || { let _tmp = cell.take(); fail!("fail to unwind past `tmp`"); }; @@ -61,7 +61,7 @@ fn test_rm_tempdir() { let path; { - let f: ~fn() -> TempDir = || { + let f: proc() -> TempDir = || { TempDir::new("test_rm_tempdir").unwrap() }; let tmp = task::try(f).expect("test_rm_tmdir"); diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index f9a8efe5701d3..ada3607beaef5 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -19,11 +19,11 @@ enum maybe_pointy { struct Pointy { a : maybe_pointy, - d : ~fn() -> uint, + d : proc() -> uint, } -fn make_uniq_closure(a: A) -> ~fn() -> uint { - let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint; +fn make_uniq_closure(a: A) -> proc() -> uint { + let result: proc() -> uint = || ptr::to_unsafe_ptr(&a) as uint; result } diff --git a/src/test/run-pass/uniq-cc.rs b/src/test/run-pass/uniq-cc.rs index e08d3965b17b2..fc58374d46d61 100644 --- a/src/test/run-pass/uniq-cc.rs +++ b/src/test/run-pass/uniq-cc.rs @@ -18,7 +18,7 @@ enum maybe_pointy { struct Pointy { a : maybe_pointy, c : ~int, - d : ~fn()->(), + d : proc()->(), } fn empty_pointy() -> @mut Pointy {