diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-06-30 16:19:07 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-07-01 19:19:32 -0700 |
| commit | d1fc2b5995fdef69fe1dbdbba3703398c0aa547b (patch) | |
| tree | b6d14fd0e920512a29c64a671cc2a5bb90132abb /src/libcore | |
| parent | 13a8f545388929a07af110a950441e6a1b88473a (diff) | |
Convert to new closure syntax
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/arc.rs | 22 | ||||
| -rw-r--r-- | src/libcore/bool.rs | 4 | ||||
| -rw-r--r-- | src/libcore/char.rs | 2 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 46 | ||||
| -rw-r--r-- | src/libcore/dvec.rs | 18 | ||||
| -rw-r--r-- | src/libcore/either.rs | 6 | ||||
| -rw-r--r-- | src/libcore/extfmt.rs | 2 | ||||
| -rw-r--r-- | src/libcore/future.rs | 14 | ||||
| -rw-r--r-- | src/libcore/int-template.rs | 4 | ||||
| -rw-r--r-- | src/libcore/io.rs | 68 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dvec.rs | 2 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 32 | ||||
| -rw-r--r-- | src/libcore/newcomm.rs | 4 | ||||
| -rw-r--r-- | src/libcore/option.rs | 4 | ||||
| -rw-r--r-- | src/libcore/os.rs | 96 | ||||
| -rw-r--r-- | src/libcore/path.rs | 11 | ||||
| -rw-r--r-- | src/libcore/priv.rs | 40 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 16 | ||||
| -rw-r--r-- | src/libcore/rand.rs | 10 | ||||
| -rw-r--r-- | src/libcore/result.rs | 18 | ||||
| -rw-r--r-- | src/libcore/run.rs | 28 | ||||
| -rw-r--r-- | src/libcore/stackwalk.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str.rs | 133 | ||||
| -rw-r--r-- | src/libcore/sys.rs | 6 | ||||
| -rw-r--r-- | src/libcore/task.rs | 106 | ||||
| -rw-r--r-- | src/libcore/to_str.rs | 2 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 6 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 98 |
28 files changed, 399 insertions, 405 deletions
diff --git a/src/libcore/arc.rs b/src/libcore/arc.rs index 7a74410dc61..84f8ca8700e 100644 --- a/src/libcore/arc.rs +++ b/src/libcore/arc.rs @@ -109,9 +109,7 @@ impl methods<T: send> for exclusive<T> { unsafe::reinterpret_cast(self.data); let r = { let rec: &ex_data<T> = &(*ptr).data; - rec.lock.lock_cond({|c| - f(c, &rec.data) - }) + rec.lock.lock_cond(|c| f(c, &rec.data)) }; unsafe::forget(ptr); r @@ -135,7 +133,7 @@ fn shared_arc<T: send const>(-data: T) -> shared_arc<T> { let a = arc::arc(data); let p = port(); let c = chan(p); - do task::spawn() {|move a| + do task::spawn() |move a| { let mut live = true; let terminate = port(); let get = port(); @@ -174,7 +172,7 @@ mod tests { let p = port(); let c = chan(p); - do task::spawn() {|| + do task::spawn() || { let p = port(); c.send(chan(p)); @@ -200,7 +198,7 @@ mod tests { let p = port(); let c = chan(p); - do task::spawn() {|| + do task::spawn() || { let arc_v = get_arc(arc_c); let v = *get(&arc_v); assert v[2] == 3; @@ -221,20 +219,20 @@ mod tests { let total = exclusive(~mut 0u); - for uint::range(0u, num_tasks) {|_i| + for uint::range(0u, num_tasks) |_i| { let total = total.clone(); - futures += ~[future::spawn({|| - for uint::range(0u, count) {|_i| - do total.with {|_cond, count| + futures += ~[future::spawn(|| { + for uint::range(0u, count) |_i| { + do total.with |_cond, count| { **count += 1u; } } })]; }; - for futures.each {|f| f.get() }; + for futures.each |f| { f.get() } - do total.with {|_cond, total| + do total.with |_cond, total| { assert **total == num_tasks * count }; } diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 131b09b2d43..cf7689c57ac 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -65,7 +65,7 @@ pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } } #[test] fn test_bool_from_str() { - do all_values { |v| + do all_values |v| { assert some(v) == from_str(bool::to_str(v)) } } @@ -78,7 +78,7 @@ fn test_bool_to_str() { #[test] fn test_bool_to_bit() { - do all_values { |v| + do all_values |v| { assert to_bit(v) == if is_true(v) { 1u8 } else { 0u8 }; } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index ffead7a523b..8e204d89f3f 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -140,7 +140,7 @@ fn escape_unicode(c: char) -> str { assert str::len(s) <= pad; let mut out = "\\"; out += str::from_char(c); - for uint::range(str::len(s), pad) {|_i| out += "0"; } + for uint::range(str::len(s), pad) |_i| { out += "0"; } out += s; ret out; } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 894256872bf..2d1c4dd978c 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -98,7 +98,7 @@ class port_ptr<T:send> { let po: *rust_port; new(po: *rust_port) { self.po = po; } drop unsafe { - do task::unkillable {|| + do task::unkillable || { // Once the port is detached it's guaranteed not to receive further // messages let yield = 0u; @@ -184,11 +184,11 @@ fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) } #[doc(hidden)] fn recv_chan<T: send>(ch: comm::chan<T>) -> T { - as_raw_port(ch, {|x|recv_(x)}) + as_raw_port(ch, |x|recv_(x)) } fn peek_chan<T: send>(ch: comm::chan<T>) -> bool { - as_raw_port(ch, {|x|peek_(x)}) + as_raw_port(ch, |x|peek_(x)) } #[doc = "Receive on a raw port pointer"] @@ -223,7 +223,7 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>) let mut resport: *rust_port; resport = rusti::init::<*rust_port>(); - do vec::as_buf(ports) {|ports| + do vec::as_buf(ports) |ports| { rustrt::rust_port_select(ptr::addr_of(resport), ports, n_ports, yieldp); } @@ -364,16 +364,16 @@ fn test_select2_rendezvous() { let ch_a = chan(po_a); let ch_b = chan(po_b); - do iter::repeat(10u) {|| - do task::spawn {|| - iter::repeat(10u, {|| task::yield() }); + do iter::repeat(10u) || { + do task::spawn || { + iter::repeat(10u, || task::yield()); send(ch_a, "a"); }; assert select2(po_a, po_b) == either::left("a"); - do task::spawn {|| - iter::repeat(10u, {|| task::yield() }); + do task::spawn || { + iter::repeat(10u, || task::yield()); send(ch_b, "b"); }; @@ -391,14 +391,14 @@ fn test_select2_stress() { let msgs = 100u; let times = 4u; - do iter::repeat(times) {|| - do task::spawn {|| - do iter::repeat(msgs) {|| + do iter::repeat(times) || { + do task::spawn || { + do iter::repeat(msgs) || { send(ch_a, "a") } }; - do task::spawn {|| - do iter::repeat(msgs) {|| + do task::spawn || { + do iter::repeat(msgs) || { send(ch_b, "b") } }; @@ -406,7 +406,7 @@ fn test_select2_stress() { let mut as = 0; let mut bs = 0; - do iter::repeat(msgs * times * 2u) {|| + do iter::repeat(msgs * times * 2u) || { alt check select2(po_a, po_b) { either::left("a") { as += 1 } either::right("b") { bs += 1 } @@ -440,9 +440,9 @@ fn test_recv_chan_wrong_task() { let po = port(); let ch = chan(po); send(ch, "flower"); - assert result::is_err(task::try({|| + assert result::is_err(task::try(|| recv_chan(ch) - })) + )) } #[test] @@ -462,8 +462,8 @@ fn test_chan_peek() { #[test] fn test_listen() { - do listen {|parent| - do task::spawn {|| + do listen |parent| { + do task::spawn || { parent.send("oatmeal-salad"); } assert parent.recv() == "oatmeal-salad"; @@ -473,18 +473,18 @@ fn test_listen() { #[test] #[ignore(cfg(windows))] fn test_port_detach_fail() { - do iter::repeat(100u) {|| + do iter::repeat(100u) || { let builder = task::builder(); task::unsupervise(builder); - do task::run(builder) {|| + do task::run(builder) || { let po = port(); let ch = po.chan(); - do task::spawn {|| + do task::spawn || { fail; } - do task::spawn {|| + do task::spawn || { ch.send(()); } } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 5f1bc5c6ce9..ea67947073e 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -114,12 +114,12 @@ impl extensions<A> for dvec<A> { "] #[inline(always)] fn swap(f: fn(-~[mut A]) -> ~[mut A]) { - self.borrow({ |v| self.return(f(v)) }) + self.borrow(|v| self.return(f(v))) } #[doc = "Returns the number of elements currently in the dvec"] fn len() -> uint { - do self.borrow { |v| + do self.borrow |v| { let l = v.len(); self.return(v); l @@ -134,7 +134,7 @@ impl extensions<A> for dvec<A> { #[doc = "Remove and return the last element"] fn pop() -> A { - do self.borrow { |v| + do self.borrow |v| { let mut v <- v; let result = vec::pop(v); self.return(v); @@ -164,7 +164,7 @@ impl extensions<A> for dvec<A> { #[doc = "Remove and return the first element"] fn shift() -> A { - do self.borrow { |v| + do self.borrow |v| { let mut v = vec::from_mut(v); let result = vec::shift(v); self.return(vec::to_mut(v)); @@ -187,7 +187,7 @@ impl extensions<A:copy> for dvec<A> { Appends elements from `from_idx` to `to_idx` (exclusive) "] fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) { - do self.swap { |v| + do self.swap |v| { let mut v <- v; let new_len = vec::len(v) + to_idx - from_idx; vec::reserve(v, new_len); @@ -207,7 +207,7 @@ impl extensions<A:copy> for dvec<A> { attempts to access this vector. "] fn append_iter<A, I:iter::base_iter<A>>(ts: I) { - do self.swap { |v| + do self.swap |v| { let mut v = alt ts.size_hint() { none { v } some(h) { @@ -218,7 +218,7 @@ impl extensions<A:copy> for dvec<A> { } }; - for ts.each { |t| vec::push(v, t) }; + for ts.each |t| { vec::push(v, t) }; v } } @@ -229,7 +229,7 @@ impl extensions<A:copy> for dvec<A> { See `unwrap()` if you do not wish to copy the contents. "] fn get() -> ~[A] { - do self.borrow { |v| + do self.borrow |v| { let w = vec::from_mut(copy v); self.return(v); w @@ -259,7 +259,7 @@ impl extensions<A:copy> for dvec<A> { growing the vector if necessary. New elements will be initialized with `initval`"] fn grow_set_elt(idx: uint, initval: A, val: A) { - do self.swap { |v| + do self.swap |v| { let mut v <- v; vec::grow_set(v, idx, initval, val); v diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 12f0b869ca2..9dadd848415 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -25,7 +25,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] { #[doc = "Extracts from a vector of either all the left values"]; let mut result: ~[T] = ~[]; - for vec::each(eithers) {|elt| + for vec::each(eithers) |elt| { alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } } } ret result; @@ -35,7 +35,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] { #[doc = "Extracts from a vector of either all the right values"]; let mut result: ~[U] = ~[]; - for vec::each(eithers) {|elt| + for vec::each(eithers) |elt| { alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } } } ret result; @@ -52,7 +52,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>]) let mut lefts: ~[T] = ~[]; let mut rights: ~[U] = ~[]; - for vec::each(eithers) {|elt| + for vec::each(eithers) |elt| { alt elt { left(l) { vec::push(lefts, l); } right(r) { vec::push(rights, r); } diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 312a2057735..e156e595490 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -174,7 +174,7 @@ mod ct { let curr: ~[flag] = ~[f]; ret {flags: vec::append(curr, rest), next: j}; } - let more = {|x|more_(x, s, i, lim)}; + let more = |x| more_(x, s, i, lim); let f = s[i]; ret if f == '-' as u8 { more(flag_left_justify) diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 6c707d56dd7..51aeb3a354c 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -64,7 +64,7 @@ fn from_port<A:send>(-port: comm::port<A>) -> future<A> { waiting for the result to be received on the port. "]; - do from_fn {|| + do from_fn || { comm::recv(port) } } @@ -93,7 +93,7 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> { let mut po = comm::port(); let ch = comm::chan(po); - do task::spawn {|| + do task::spawn || { comm::send(ch, blk()) }; from_port(po) @@ -102,7 +102,7 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> { fn get<A:copy>(future: future<A>) -> A { #[doc = "Get the value of the future"]; - do with(future) {|v| v } + do with(future) |v| { v } } fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B { @@ -150,18 +150,18 @@ fn test_iface_get() { #[test] fn test_with() { let f = from_value("nail"); - assert with(f, {|v| v}) == "nail"; + assert with(f, |v| v) == "nail"; } #[test] fn test_iface_with() { let f = from_value("kale"); - assert f.with({|v| v}) == "kale"; + assert f.with(|v| v) == "kale"; } #[test] fn test_spawn() { - let f = spawn({|| "bale" }); + let f = spawn(|| "bale"); assert get(f) == "bale"; } @@ -169,6 +169,6 @@ fn test_spawn() { #[should_fail] #[ignore(cfg(target_os = "win32"))] fn test_futurefail() { - let f = spawn({|| fail }); + let f = spawn(|| fail); let _x: str = get(f); } diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 91f44e7067b..ac11f2f1102 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -93,8 +93,8 @@ fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) } #[doc = "Convert to a string in a given base"] fn to_str(n: T, radix: uint) -> str { - do to_str_bytes(n, radix) {|slice| - do vec::unpack_slice(slice) {|p, len| + do to_str_bytes(n, radix) |slice| { + do vec::unpack_slice(slice) |p, len| { unsafe { str::unsafe::from_buf_len(p, len) } } } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 316c4d45761..8527f58ca6c 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -195,7 +195,7 @@ impl of reader for *libc::FILE { fn read_bytes(len: uint) -> ~[u8] { let mut buf : ~[mut u8] = ~[mut]; vec::reserve(buf, len); - do vec::as_mut_buf(buf) {|b| + do vec::as_mut_buf(buf) |b| { let read = libc::fread(b as *mut c_void, 1u as size_t, len as size_t, self); unsafe { vec::unsafe::set_len(buf, read as uint) }; @@ -245,10 +245,10 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader { fn stdin() -> reader { rustrt::rust_get_stdin() as reader } fn file_reader(path: str) -> result<reader, str> { - let f = os::as_c_charp(path, {|pathbuf| - os::as_c_charp("r", {|modebuf| + let f = os::as_c_charp(path, |pathbuf| { + os::as_c_charp("r", |modebuf| libc::fopen(pathbuf, modebuf) - }) + ) }); ret if f as uint == 0u { result::err("error opening " + path) } else { @@ -308,7 +308,7 @@ fn str_reader(s: str) -> reader { } fn with_str_reader<T>(s: str, f: fn(reader) -> T) -> T { - do str::as_bytes(s) { |bytes| + do str::as_bytes(s) |bytes| { with_bytes_reader_between(bytes, 0u, str::len(s), f) } } @@ -334,7 +334,7 @@ impl <T: writer, C> of writer for {base: T, cleanup: C} { impl of writer for *libc::FILE { fn write(v: &[const u8]) { - do vec::unpack_const_slice(v) {|vbuf, len| + do vec::unpack_const_slice(v) |vbuf, len| { let nout = libc::fwrite(vbuf as *c_void, len as size_t, 1u as size_t, self); if nout < 1 as size_t { @@ -363,7 +363,7 @@ fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer { impl of writer for fd_t { fn write(v: &[const u8]) { let mut count = 0u; - do vec::unpack_const_slice(v) {|vbuf, len| + do vec::unpack_const_slice(v) |vbuf, len| { while count < len { let vb = ptr::const_offset(vbuf, count) as *c_void; let nout = libc::write(self, vb, len as size_t); @@ -412,7 +412,7 @@ fn mk_file_writer(path: str, flags: ~[fileflag]) fn wb() -> c_int { O_WRONLY as c_int } let mut fflags: c_int = wb(); - for vec::each(flags) {|f| + for vec::each(flags) |f| { alt f { append { fflags |= O_APPEND as c_int; } create { fflags |= O_CREAT as c_int; } @@ -420,7 +420,7 @@ fn mk_file_writer(path: str, flags: ~[fileflag]) no_flag { } } } - let fd = do os::as_c_charp(path) {|pathbuf| + let fd = do os::as_c_charp(path) |pathbuf| { libc::open(pathbuf, fflags, (S_IRUSR | S_IWUSR) as c_int) }; @@ -514,78 +514,78 @@ impl writer_util for writer { self.write_str(str::from_char(ch)); } } - fn write_str(s: str/&) { str::byte_slice(s, {|v| self.write(v); }) } + fn write_str(s: str/&) { str::byte_slice(s, |v| self.write(v)) } fn write_line(s: str/&) { self.write_str(s); self.write_str("\n"/&); } fn write_int(n: int) { - int::to_str_bytes(n, 10u, {|buf| self.write(buf) }) + int::to_str_bytes(n, 10u, |buf| self.write(buf)) } fn write_uint(n: uint) { - uint::to_str_bytes(false, n, 10u, {|buf| self.write(buf) }) + uint::to_str_bytes(false, n, 10u, |buf| self.write(buf)) } fn write_le_uint(n: uint, size: uint) { - u64_to_le_bytes(n as u64, size, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, size, |v| self.write(v)) } fn write_le_int(n: int, size: uint) { - u64_to_le_bytes(n as u64, size, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, size, |v| self.write(v)) } fn write_be_uint(n: uint, size: uint) { - u64_to_be_bytes(n as u64, size, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, size, |v| self.write(v)) } fn write_be_int(n: int, size: uint) { - u64_to_be_bytes(n as u64, size, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, size, |v| self.write(v)) } fn write_be_u64(n: u64) { - u64_to_be_bytes(n, 8u, {|v| self.write(v) }) + u64_to_be_bytes(n, 8u, |v| self.write(v)) } fn write_be_u32(n: u32) { - u64_to_be_bytes(n as u64, 4u, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) } fn write_be_u16(n: u16) { - u64_to_be_bytes(n as u64, 2u, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) } fn write_be_i64(n: i64) { - u64_to_be_bytes(n as u64, 8u, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, 8u, |v| self.write(v)) } fn write_be_i32(n: i32) { - u64_to_be_bytes(n as u64, 4u, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) } fn write_be_i16(n: i16) { - u64_to_be_bytes(n as u64, 2u, {|v| self.write(v) }) + u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) } fn write_le_u64(n: u64) { - u64_to_le_bytes(n, 8u, {|v| self.write(v) }) + u64_to_le_bytes(n, 8u, |v| self.write(v)) } fn write_le_u32(n: u32) { - u64_to_le_bytes(n as u64, 4u, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) } fn write_le_u16(n: u16) { - u64_to_le_bytes(n as u64, 2u, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) } fn write_le_i64(n: i64) { - u64_to_le_bytes(n as u64, 8u, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, 8u, |v| self.write(v)) } fn write_le_i32(n: i32) { - u64_to_le_bytes(n as u64, 4u, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) } fn write_le_i16(n: i16) { - u64_to_le_bytes(n as u64, 2u, {|v| self.write(v) }) + u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) } fn write_u8(n: u8) { self.write(&[n]) } } fn file_writer(path: str, flags: ~[fileflag]) -> result<writer, str> { - result::chain(mk_file_writer(path, flags), { |w| result::ok(w)}) + result::chain(mk_file_writer(path, flags), |w| result::ok(w)) } // FIXME: fileflags // #2004 fn buffered_file_writer(path: str) -> result<writer, str> { - let f = do os::as_c_charp(path) {|pathbuf| - do os::as_c_charp("w") {|modebuf| + let f = do os::as_c_charp(path) |pathbuf| { + do os::as_c_charp("w") |modebuf| { libc::fopen(pathbuf, modebuf) } }; @@ -672,7 +672,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) -> } fn read_whole_file_str(file: str) -> result<str, str> { - result::chain(read_whole_file(file), { |bytes| + result::chain(read_whole_file(file), |bytes| { result::ok(str::from_bytes(bytes)) }) } @@ -680,7 +680,7 @@ fn read_whole_file_str(file: str) -> result<str, str> { // FIXME (#2004): implement this in a low-level way. Going through the // abstractions is pointless. fn read_whole_file(file: str) -> result<~[u8], str> { - result::chain(file_reader(file), { |rdr| + result::chain(file_reader(file), |rdr| { result::ok(rdr.read_whole_stream()) }) } @@ -804,7 +804,7 @@ mod tests { assert(vec::len(res) == len); } assert(vec::slice(ivals, 0u, vec::len(res)) == - vec::map(res, {|x| x as int})); + vec::map(res, |x| x as int)); } let mut i = 0u; while i < 8u { diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs index 5f7058ec975..3f1f4db6a4d 100644 --- a/src/libcore/iter-trait/dvec.rs +++ b/src/libcore/iter-trait/dvec.rs @@ -7,7 +7,7 @@ Attempts to access this dvec during iteration will fail. "] fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) { import dvec::extensions; - self.swap({ |v| vec::each(v, f); v }) + self.swap(|v| { vec::each(v, f); v }) } fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 7466bc11bc3..c5f395d376c 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -5,21 +5,21 @@ iface base_iter<A> { fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) { let mut i = 0u; - for self.each {|a| + for self.each |a| { if !blk(i, a) { break; } i += 1u; } } fn all<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { - for self.each {|a| + for self.each |a| { if !blk(a) { ret false; } } ret true; } fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { - for self.each {|a| + for self.each |a| { if blk(a) { ret true; } } ret false; @@ -28,8 +28,8 @@ fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, prd: fn(A) -> bool) -> ~[A] { let mut result = ~[]; - self.size_hint().iter({|hint| vec::reserve(result, hint); }); - for self.each {|a| + self.size_hint().iter(|hint| vec::reserve(result, hint)); + for self.each |a| { if prd(a) { vec::push(result, a); } } ret result; @@ -37,8 +37,8 @@ fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] { let mut result = ~[]; - self.size_hint().iter({|hint| vec::reserve(result, hint); }); - for self.each {|a| + self.size_hint().iter(|hint| vec::reserve(result, hint)); + for self.each |a| { vec::push(result, op(a)); } ret result; @@ -48,8 +48,8 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>( self: IA, op: fn(A) -> IB) -> ~[B] { let mut result = ~[]; - for self.each {|a| - for op(a).each {|b| + for self.each |a| { + for op(a).each |b| { vec::push(result, b); } } @@ -58,25 +58,25 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>( fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { let mut b <- b0; - for self.each {|a| + for self.each |a| { b = blk(b, a); } ret b; } fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> ~[A] { - foldl::<A,~[A],IA>(self, ~[], {|r, a| vec::append(r, ~[a]) }) + foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(r, ~[a])) } fn contains<A,IA:base_iter<A>>(self: IA, x: A) -> bool { - for self.each {|a| + for self.each |a| { if a == x { ret true; } } ret false; } fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint { - do foldl(self, 0u) {|count, value| + do foldl(self, 0u) |count, value| { if value == x { count + 1u } else { @@ -88,7 +88,7 @@ fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint { fn position<A,IA:base_iter<A>>(self: IA, f: fn(A) -> bool) -> option<uint> { let mut i = 0; - for self.each {|a| + for self.each |a| { if f(a) { ret some(i); } i += 1; } @@ -108,7 +108,7 @@ fn repeat(times: uint, blk: fn()) { } fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { - alt do foldl::<A,option<A>,IA>(self, none) {|a, b| + alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { some(a_) if a_ < b { // FIXME (#2005): Not sure if this is successfully optimized to @@ -124,7 +124,7 @@ fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { } fn max<A:copy,IA:base_iter<A>>(self: IA) -> A { - alt do foldl::<A,option<A>,IA>(self, none) {|a, b| + alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { some(a_) if a_ > b { // FIXME (#2005): Not sure if this is successfully optimized to diff --git a/src/libcore/newcomm.rs b/src/libcore/newcomm.rs index 2c45034feb2..c97420646c9 100644 --- a/src/libcore/newcomm.rs +++ b/src/libcore/newcomm.rs @@ -31,7 +31,7 @@ fn chan<T: send>(p: port<T>) -> chan<T> { fn send<T: send>(c: chan<T>, -x: T) { let mut x <- some(x); - do (*c).with {|cond, data| + do (*c).with |cond, data| { let mut xx = none; xx <-> x; (*data).push(option::unwrap(xx)); @@ -40,7 +40,7 @@ fn send<T: send>(c: chan<T>, -x: T) { } fn recv<T: send>(p: port<T>) -> T { - do (*p).with {|cond, data| + do (*p).with |cond, data| { if (*data).len() == 0u { cond.wait(); } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 39437656c93..3d47c51a73f 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -133,10 +133,10 @@ fn test_unwrap_ptr() { #[test] fn test_unwrap_str() { let x = "test"; - let addr_x = str::as_buf(x, {|buf| ptr::addr_of(buf) }); + let addr_x = str::as_buf(x, |buf| ptr::addr_of(buf)); let opt = some(x); let y = unwrap(opt); - let addr_y = str::as_buf(y, {|buf| ptr::addr_of(buf) }); + let addr_y = str::as_buf(y, |buf| ptr::addr_of(buf)); assert addr_x == addr_y; } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index bd5354a8625..b945a998084 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -53,7 +53,7 @@ native mod rustrt { fn env() -> ~[(str,str)] { let mut pairs = ~[]; - for vec::each(rustrt::rust_env_pairs()) {|p| + for vec::each(rustrt::rust_env_pairs()) |p| { let vs = str::splitn_char(p, '=', 1u); assert vec::len(vs) == 2u; vec::push(pairs, (vs[0], vs[1])); @@ -64,13 +64,13 @@ fn env() -> ~[(str,str)] { const tmpbuf_sz : uint = 1000u; fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T { - str::as_c_str(s, {|b| f(b as *c_char) }) + str::as_c_str(s, |b| f(b as *c_char)) } fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool) -> option<str> { let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char)); - do vec::as_mut_buf(buf) { |b| + do vec::as_mut_buf(buf) |b| { if f(b, tmpbuf_sz as size_t) unsafe { some(str::unsafe::from_buf(b as *u8)) } else { @@ -95,7 +95,7 @@ mod win32 { let mut done = false; while !done { let buf = vec::to_mut(vec::from_elem(n as uint, 0u16)); - do vec::as_mut_buf(buf) {|b| + do vec::as_mut_buf(buf) |b| { let k : dword = f(b, tmpbuf_sz as dword); if k == (0 as dword) { done = true; @@ -160,7 +160,7 @@ mod global_env { fn get_global_env_chan() -> comm::chan<msg> { let global_ptr = rustrt::rust_global_env_chan_ptr(); - let builder_fn = {|| + let builder_fn = || { let builder = task::builder(); task::unsupervise(builder); task::set_opts(builder, { @@ -182,7 +182,7 @@ mod global_env { fn global_env_task(msg_po: comm::port<msg>) { unsafe { - do priv::weaken_task {|weak_po| + do priv::weaken_task |weak_po| { loop { alt comm::select2(msg_po, weak_po) { either::left(msg_getenv(n, resp_ch)) { @@ -220,8 +220,8 @@ mod global_env { import libc::types::os::arch::extra::*; import libc::funcs::extra::kernel32::*; import win32::*; - do as_utf16_p(n) {|u| - do fill_utf16_buf_and_decode() {|buf, sz| + do as_utf16_p(n) |u| { + do fill_utf16_buf_and_decode() |buf, sz| { GetEnvironmentVariableW(u, buf, sz) } } @@ -233,8 +233,8 @@ mod global_env { // FIXME: remove this when export globs work properly. #1238 import libc::funcs::posix01::unistd::setenv; - do str::as_c_str(n) {|nbuf| - do str::as_c_str(v) {|vbuf| + do str::as_c_str(n) |nbuf| { + do str::as_c_str(v) |vbuf| { setenv(nbuf, vbuf, 1i32); } } @@ -246,8 +246,8 @@ mod global_env { // FIXME: remove imports when export globs work properly. #1238 import libc::funcs::extra::kernel32::*; import win32::*; - do as_utf16_p(n) {|nbuf| - do as_utf16_p(v) {|vbuf| + do as_utf16_p(n) |nbuf| { + do as_utf16_p(v) |vbuf| { SetEnvironmentVariableW(nbuf, vbuf); } } @@ -257,7 +257,7 @@ mod global_env { } fn fdopen(fd: c_int) -> *FILE { - ret do as_c_charp("r") {|modebuf| + ret do as_c_charp("r") |modebuf| { libc::fdopen(fd, modebuf) }; } @@ -370,7 +370,7 @@ fn self_exe_path() -> option<path> { unsafe { import libc::funcs::bsd44::*; import libc::consts::os::extra::*; - do fill_charp_buf() {|buf, sz| + do fill_charp_buf() |buf, sz| { let mib = ~[CTL_KERN as c_int, KERN_PROC as c_int, KERN_PROC_PATHNAME as c_int, -1 as c_int]; @@ -384,8 +384,8 @@ fn self_exe_path() -> option<path> { #[cfg(target_os = "linux")] fn load_self() -> option<path> { import libc::funcs::posix01::unistd::readlink; - do fill_charp_buf() {|buf, sz| - do as_c_charp("/proc/self/exe") { |proc_self_buf| + do fill_charp_buf() |buf, sz| { + do as_c_charp("/proc/self/exe") |proc_self_buf| { readlink(proc_self_buf, buf, sz) != (-1 as ssize_t) } } @@ -395,7 +395,7 @@ fn self_exe_path() -> option<path> { fn load_self() -> option<path> { // FIXME: remove imports when export globs work properly. #1238 import libc::funcs::extra::*; - do fill_charp_buf() {|buf, sz| + do fill_charp_buf() |buf, sz| { _NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32)) == (0 as c_int) } @@ -407,12 +407,12 @@ fn self_exe_path() -> option<path> { import libc::types::os::arch::extra::*; import libc::funcs::extra::kernel32::*; import win32::*; - do fill_utf16_buf_and_decode() {|buf, sz| + do fill_utf16_buf_and_decode() |buf, sz| { GetModuleFileNameW(0u as dword, buf, sz) } } - do option::map(load_self()) {|pth| + do option::map(load_self()) |pth| { path::dirname(pth) + path::path_sep() } } @@ -452,7 +452,7 @@ fn homedir() -> option<path> { #[cfg(windows)] fn secondary() -> option<path> { - do option::chain(getenv("USERPROFILE")) {|p| + do option::chain(getenv("USERPROFILE")) |p| { if !str::is_empty(p) { some(p) } else { @@ -469,7 +469,7 @@ fn walk_dir(p: path, f: fn(path) -> bool) { fn walk_dir_(p: path, f: fn(path) -> bool) -> bool { let mut keepgoing = true; - do list_dir(p).each {|q| + do list_dir(p).each |q| { let path = path::connect(p, q); if !f(path) { keepgoing = false; @@ -493,14 +493,14 @@ fn walk_dir(p: path, f: fn(path) -> bool) { #[doc = "Indicates whether a path represents a directory"] fn path_is_dir(p: path) -> bool { - do str::as_c_str(p) {|buf| + do str::as_c_str(p) |buf| { rustrt::rust_path_is_dir(buf) != 0 as c_int } } #[doc = "Indicates whether a path exists"] fn path_exists(p: path) -> bool { - do str::as_c_str(p) {|buf| + do str::as_c_str(p) |buf| { rustrt::rust_path_exists(buf) != 0 as c_int } } @@ -537,7 +537,7 @@ fn make_dir(p: path, mode: c_int) -> bool { import libc::funcs::extra::kernel32::*; import win32::*; // FIXME: turn mode into something useful? #2623 - do as_utf16_p(p) {|buf| + do as_utf16_p(p) |buf| { CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) }) != (0 as BOOL) } @@ -545,7 +545,7 @@ fn make_dir(p: path, mode: c_int) -> bool { #[cfg(unix)] fn mkdir(p: path, mode: c_int) -> bool { - do as_c_charp(p) {|c| + do as_c_charp(p) |c| { libc::mkdir(c, mode as mode_t) == (0 as c_int) } } @@ -568,7 +568,7 @@ fn list_dir(p: path) -> ~[str] { } } - do rustrt::rust_list_files(star(p)).filter {|filename| + do rustrt::rust_list_files(star(p)).filter |filename| { !str::eq(filename, ".") && !str::eq(filename, "..") } } @@ -585,7 +585,7 @@ fn list_dir_path(p: path) -> ~[str] { && p[pl - 1u] as char != path::consts::alt_path_sep) { p += path::path_sep(); } - os::list_dir(p).map({|f| p + f}) + os::list_dir(p).map(|f| p + f) } #[doc = "Removes a directory at the specified path"] @@ -598,14 +598,14 @@ fn remove_dir(p: path) -> bool { import libc::funcs::extra::kernel32::*; import libc::types::os::arch::extra::*; import win32::*; - ret do as_utf16_p(p) {|buf| + ret do as_utf16_p(p) |buf| { RemoveDirectoryW(buf) != (0 as BOOL) }; } #[cfg(unix)] fn rmdir(p: path) -> bool { - ret do as_c_charp(p) {|buf| + ret do as_c_charp(p) |buf| { libc::rmdir(buf) == (0 as c_int) }; } @@ -620,14 +620,14 @@ fn change_dir(p: path) -> bool { import libc::funcs::extra::kernel32::*; import libc::types::os::arch::extra::*; import win32::*; - ret do as_utf16_p(p) {|buf| + ret do as_utf16_p(p) |buf| { SetCurrentDirectoryW(buf) != (0 as BOOL) }; } #[cfg(unix)] fn chdir(p: path) -> bool { - ret do as_c_charp(p) {|buf| + ret do as_c_charp(p) |buf| { libc::chdir(buf) == (0 as c_int) }; } @@ -643,8 +643,8 @@ fn copy_file(from: path, to: path) -> bool { import libc::funcs::extra::kernel32::*; import libc::types::os::arch::extra::*; import win32::*; - ret do as_utf16_p(from) {|fromp| - do as_utf16_p(to) {|top| + ret do as_utf16_p(from) |fromp| { + do as_utf16_p(to) |top| { CopyFileW(fromp, top, (0 as BOOL)) != (0 as BOOL) } } @@ -652,16 +652,16 @@ fn copy_file(from: path, to: path) -> bool { #[cfg(unix)] fn do_copy_file(from: path, to: path) -> bool { - let istream = do as_c_charp(from) {|fromp| - do as_c_charp("rb") {|modebuf| + let istream = do as_c_charp(from) |fromp| { + do as_c_charp("rb") |modebuf| { libc::fopen(fromp, modebuf) } }; if istream as uint == 0u { ret false; } - let ostream = do as_c_charp(to) {|top| - do as_c_charp("w+b") {|modebuf| + let ostream = do as_c_charp(to) |top| { + do as_c_charp("w+b") |modebuf| { libc::fopen(top, modebuf) } }; @@ -675,7 +675,7 @@ fn copy_file(from: path, to: path) -> bool { let mut done = false; let mut ok = true; while !done { - do vec::as_mut_buf(buf) {|b| + do vec::as_mut_buf(buf) |b| { let nread = libc::fread(b as *mut c_void, 1u as size_t, bufsize as size_t, istream); @@ -707,14 +707,14 @@ fn remove_file(p: path) -> bool { import libc::funcs::extra::kernel32::*; import libc::types::os::arch::extra::*; import win32::*; - ret do as_utf16_p(p) {|buf| + ret do as_utf16_p(p) |buf| { DeleteFileW(buf) != (0 as BOOL) }; } #[cfg(unix)] fn unlink(p: path) -> bool { - ret do as_c_charp(p) {|buf| + ret do as_c_charp(p) |buf| { libc::unlink(buf) == (0 as c_int) }; } @@ -850,7 +850,7 @@ mod tests { fn test_env_getenv() { let e = env(); assert vec::len(e) > 0u; - for vec::each(e) {|p| + for vec::each(e) |p| { let (n, v) = p; log(debug, n); let v2 = getenv(n); @@ -894,7 +894,7 @@ mod tests { setenv("HOME", ""); assert os::homedir() == none; - option::iter(oldhome, {|s| setenv("HOME", s)}); + option::iter(oldhome, |s| setenv("HOME", s)); } #[test] @@ -924,9 +924,9 @@ mod tests { setenv("USERPROFILE", "/home/PaloAlto"); assert os::homedir() == some("/home/MountainView"); - option::iter(oldhome, {|s| setenv("HOME", s)}); + option::iter(oldhome, |s| setenv("HOME", s)); option::iter(olduserprofile, - {|s| setenv("USERPROFILE", s)}); + |s| setenv("USERPROFILE", s)); } // Issue #712 @@ -939,7 +939,7 @@ mod tests { // Just assuming that we've got some contents in the current directory assert (vec::len(dirs) > 0u); - for vec::each(dirs) {|dir| log(debug, dir); } + for vec::each(dirs) |dir| { log(debug, dir); } } #[test] @@ -970,15 +970,15 @@ mod tests { let out = tempdir + path::path_sep() + "out.txt"; /* Write the temp input file */ - let ostream = do as_c_charp(in) {|fromp| - do as_c_charp("w+b") {|modebuf| + let ostream = do as_c_charp(in) |fromp| { + do as_c_charp("w+b") |modebuf| { libc::fopen(fromp, modebuf) } }; assert (ostream as uint != 0u); let s = "hello"; let mut buf = vec::to_mut(str::bytes(s) + ~[0 as u8]); - do vec::as_mut_buf(buf) {|b| + do vec::as_mut_buf(buf) |b| { assert (libc::fwrite(b as *c_void, 1u as size_t, (str::len(s) + 1u) as size_t, ostream) == buf.len() as size_t)}; diff --git a/src/libcore/path.rs b/src/libcore/path.rs index fb92138f4a8..1b514b00759 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -61,9 +61,9 @@ fn path_is_absolute(p: str) -> bool { fn path_sep() -> str { ret str::from_char(consts::path_sep); } fn split_dirname_basename (pp: path) -> {dirname: str, basename: str} { - alt str::rfind(pp, {|ch| + alt str::rfind(pp, |ch| ch == consts::path_sep || ch == consts::alt_path_sep - }) { + ) { some(i) { {dirname: str::slice(pp, 0u, i), basename: str::slice(pp, i + 1u, str::len(pp))} @@ -145,7 +145,7 @@ the first element of the returned vector will be the drive letter followed by a colon. "] fn split(p: path) -> ~[path] { - str::split_nonempty(p, {|c| + str::split_nonempty(p, |c| { c == consts::path_sep || c == consts::alt_path_sep }) } @@ -235,13 +235,12 @@ fn normalize(p: path) -> path { ret s; fn strip_dots(s: ~[path]) -> ~[path] { - vec::filter_map(s, { |elem| + vec::filter_map(s, |elem| if elem == "." { option::none } else { option::some(elem) - } - }) + }) } fn rollup_doubledots(s: ~[path]) -> ~[path] { diff --git a/src/libcore/priv.rs b/src/libcore/priv.rs index f8ce85e360f..8d8ce9a9d72 100644 --- a/src/libcore/priv.rs +++ b/src/libcore/priv.rs @@ -41,7 +41,7 @@ unsafe fn chan_from_global_ptr<T: send>( let setup_po = comm::port(); let setup_ch = comm::chan(setup_po); - let setup_ch = do task::run_listener(builder()) {|setup_po| + let setup_ch = do task::run_listener(builder()) |setup_po| { let po = comm::port::<T>(); let ch = comm::chan(po); comm::send(setup_ch, ch); @@ -92,7 +92,7 @@ fn test_from_global_chan1() { // Create the global channel, attached to a new task let ch = unsafe { - do chan_from_global_ptr(globchanp, task::builder) {|po| + do chan_from_global_ptr(globchanp, task::builder) |po| { let ch = comm::recv(po); comm::send(ch, true); let ch = comm::recv(po); @@ -106,7 +106,7 @@ fn test_from_global_chan1() { // This one just reuses the previous channel let ch = unsafe { - do chan_from_global_ptr(globchanp, task::builder) {|po| + do chan_from_global_ptr(globchanp, task::builder) |po| { let ch = comm::recv(po); comm::send(ch, false); } @@ -121,7 +121,7 @@ fn test_from_global_chan1() { #[test] fn test_from_global_chan2() { - do iter::repeat(100u) {|| + do iter::repeat(100u) || { // The global channel let globchan = 0u; let globchanp = ptr::addr_of(globchan); @@ -131,13 +131,13 @@ fn test_from_global_chan2() { // Spawn a bunch of tasks that all want to compete to // create the global channel - for uint::range(0u, 10u) {|i| - do task::spawn {|| + for uint::range(0u, 10u) |i| { + do task::spawn || { let ch = unsafe { do chan_from_global_ptr( - globchanp, task::builder) {|po| + globchanp, task::builder) |po| { - for uint::range(0u, 10u) {|_j| + for uint::range(0u, 10u) |_j| { let ch = comm::recv(po); comm::send(ch, {i}); } @@ -153,7 +153,7 @@ fn test_from_global_chan2() { } // There should be only one winner let mut winners = 0u; - for uint::range(0u, 10u) {|_i| + for uint::range(0u, 10u) |_i| { let res = comm::recv(resultpo); if res { winners += 1u }; } @@ -200,9 +200,9 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) { #[test] fn test_weaken_task_then_unweaken() { - do task::try {|| + do task::try || { unsafe { - do weaken_task {|_po| + do weaken_task |_po| { } } }; @@ -212,9 +212,9 @@ fn test_weaken_task_then_unweaken() { fn test_weaken_task_wait() { let builder = task::builder(); task::unsupervise(builder); - do task::run(builder) {|| + do task::run(builder) || { unsafe { - do weaken_task {|po| + do weaken_task |po| { comm::recv(po); } } @@ -224,18 +224,18 @@ fn test_weaken_task_wait() { #[test] fn test_weaken_task_stress() { // Create a bunch of weak tasks - do iter::repeat(100u) {|| - do task::spawn {|| + do iter::repeat(100u) || { + do task::spawn || { unsafe { - do weaken_task {|_po| + do weaken_task |_po| { } } } let builder = task::builder(); task::unsupervise(builder); - do task::run(builder) {|| + do task::run(builder) || { unsafe { - do weaken_task {|po| + do weaken_task |po| { // Wait for it to tell us to die comm::recv(po); } @@ -247,9 +247,9 @@ fn test_weaken_task_stress() { #[test] #[ignore(cfg(windows))] fn test_weaken_task_fail() { - let res = do task::try {|| + let res = do task::try || { unsafe { - do weaken_task {|_po| + do weaken_task |_po| { fail; } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index add3c87ce34..b3eaa3bd16d 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -70,7 +70,7 @@ fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T { #[doc = "Return the offset of the first null pointer in `buf`."] #[inline(always)] unsafe fn buf_len<T>(buf: **T) -> uint { - do position(buf) {|i| i == null() } + position(buf, |i| i == null()) } #[doc = "Return the first offset `i` such that `f(buf[i]) == true`."] @@ -171,9 +171,9 @@ fn test_position() { let s = "hello"; unsafe { - assert 2u == as_c_str(s, {|p| position(p, {|c| c == 'l' as c_char})}); - assert 4u == as_c_str(s, {|p| position(p, {|c| c == 'o' as c_char})}); - assert 5u == as_c_str(s, {|p| position(p, {|c| c == 0 as c_char })}); + assert 2u == as_c_str(s, |p| position(p, |c| c == 'l' as c_char)); + assert 4u == as_c_str(s, |p| position(p, |c| c == 'o' as c_char)); + assert 5u == as_c_str(s, |p| position(p, |c| c == 0 as c_char)); } } @@ -182,11 +182,11 @@ fn test_buf_len() { let s0 = "hello"; let s1 = "there"; let s2 = "thing"; - do str::as_c_str(s0) {|p0| - do str::as_c_str(s1) {|p1| - do str::as_c_str(s2) {|p2| + do str::as_c_str(s0) |p0| { + do str::as_c_str(s1) |p1| { + do str::as_c_str(s2) |p2| { let v = ~[p0, p1, p2, null()]; - do vec::as_buf(v) {|vp| + do vec::as_buf(v) |vp| { assert unsafe { buf_len(vp) } == 3u; } } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 1eb0983b7e4..4724c00941c 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -152,7 +152,7 @@ impl extensions for rng { #[doc = "Return a random byte string of the specified length"] fn gen_bytes(len: uint) -> ~[u8] { - do vec::from_fn(len) {|_i| + do vec::from_fn(len) |_i| { self.gen_u8() } } @@ -181,7 +181,7 @@ impl extensions for rng { none if the sum of the weights is 0"] fn choose_weighted_option<T:copy>(v: ~[weighted<T>]) -> option<T> { let mut total = 0u; - for v.each {|item| + for v.each |item| { total += item.weight; } if total == 0u { @@ -189,7 +189,7 @@ impl extensions for rng { } let chosen = self.gen_uint_range(0u, total); let mut so_far = 0u; - for v.each {|item| + for v.each |item| { so_far += item.weight; if so_far > chosen { ret some(item.item); @@ -202,8 +202,8 @@ impl extensions for rng { the weight of the item determines how many copies there are"] fn weighted_vec<T:copy>(v: ~[weighted<T>]) -> ~[T] { let mut r = ~[]; - for v.each {|item| - for uint::range(0u, item.weight) {|_i| + for v.each |item| { + for uint::range(0u, item.weight) |_i| { vec::push(r, item.item); } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 899ad6040c1..64d5ff9c73c 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -254,7 +254,7 @@ fn map_vec<T,U:copy,V:copy>( let mut vs: ~[V] = ~[]; vec::reserve(vs, vec::len(ts)); - for vec::each(ts) {|t| + for vec::each(ts) |t| { alt op(t) { ok(v) { vec::push(vs, v); } err(u) { ret err(u); } @@ -362,33 +362,33 @@ mod tests { #[test] fn test_impl_iter() { let mut valid = false; - ok::<str, str>("a").iter({ |_x| valid = true; }); + ok::<str, str>("a").iter(|_x| valid = true); assert valid; - err::<str, str>("b").iter({ |_x| valid = false; }); + err::<str, str>("b").iter(|_x| valid = false); assert valid; } #[test] fn test_impl_iter_err() { let mut valid = true; - ok::<str, str>("a").iter_err({ |_x| valid = false; }); + ok::<str, str>("a").iter_err(|_x| valid = false); assert valid; valid = false; - err::<str, str>("b").iter_err({ |_x| valid = true; }); + err::<str, str>("b").iter_err(|_x| valid = true); assert valid; } #[test] fn test_impl_map() { - assert ok::<str, str>("a").map({ |_x| "b" }) == ok("b"); - assert err::<str, str>("a").map({ |_x| "b" }) == err("a"); + assert ok::<str, str>("a").map(|_x| "b") == ok("b"); + assert err::<str, str>("a").map(|_x| "b") == err("a"); } #[test] fn test_impl_map_err() { - assert ok::<str, str>("a").map_err({ |_x| "b" }) == ok("a"); - assert err::<str, str>("a").map_err({ |_x| "b" }) == err("b"); + assert ok::<str, str>("a").map_err(|_x| "b") == ok("a"); + assert err::<str, str>("a").map_err(|_x| "b") == err("b"); } } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 83033bdf9d2..7bb3b56fa1b 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -67,9 +67,9 @@ fn spawn_process(prog: str, args: ~[str], dir: option<str>, in_fd: c_int, out_fd: c_int, err_fd: c_int) -> pid_t { - do with_argv(prog, args) {|argv| - do with_envp(env) { |envp| - do with_dirp(dir) { |dirp| + do with_argv(prog, args) |argv| { + do with_envp(env) |envp| { + do with_dirp(dir) |dirp| { rustrt::rust_run_program(argv, envp, dirp, in_fd, out_fd, err_fd) } @@ -79,12 +79,12 @@ fn spawn_process(prog: str, args: ~[str], fn with_argv<T>(prog: str, args: ~[str], cb: fn(**libc::c_char) -> T) -> T { - let mut argptrs = str::as_c_str(prog, {|b| ~[b] }); + let mut argptrs = str::as_c_str(prog, |b| ~[b]); let mut tmps = ~[]; - for vec::each(args) {|arg| + for vec::each(args) |arg| { let t = @arg; vec::push(tmps, t); - vec::push_all(argptrs, str::as_c_str(*t, {|b| ~[b] })); + vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b])); } vec::push(argptrs, ptr::null()); vec::as_buf(argptrs, cb) @@ -100,16 +100,16 @@ fn with_envp<T>(env: option<~[(str,str)]>, let mut tmps = ~[]; let mut ptrs = ~[]; - for vec::each(es) {|e| + for vec::each(es) |e| { let (k,v) = e; let t = @(#fmt("%s=%s", k, v)); vec::push(tmps, t); - vec::push_all(ptrs, str::as_c_str(*t, {|b| ~[b]})); + vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b])); } vec::push(ptrs, ptr::null()); - vec::as_buf(ptrs, { |p| + vec::as_buf(ptrs, |p| unsafe { cb(::unsafe::reinterpret_cast(p)) } - }) + ) } _ { cb(ptr::null()) @@ -127,7 +127,7 @@ fn with_envp<T>(env: option<~[(str,str)]>, alt env { some(es) if !vec::is_empty(es) { let mut blk : ~[u8] = ~[]; - for vec::each(es) {|e| + for vec::each(es) |e| { let (k,v) = e; let t = #fmt("%s=%s", k, v); let mut v : ~[u8] = ::unsafe::reinterpret_cast(t); @@ -135,7 +135,7 @@ fn with_envp<T>(env: option<~[(str,str)]>, ::unsafe::forget(v); } blk += ~[0_u8]; - vec::as_buf(blk, {|p| cb(::unsafe::reinterpret_cast(p)) }) + vec::as_buf(blk, |p| cb(::unsafe::reinterpret_cast(p))) } _ { cb(ptr::null()) @@ -298,11 +298,11 @@ fn program_output(prog: str, args: ~[str]) -> // clever way to do this. let p = comm::port(); let ch = comm::chan(p); - do task::spawn_sched(task::single_threaded) {|| + do task::spawn_sched(task::single_threaded) || { let errput = readclose(pipe_err.in); comm::send(ch, (2, errput)); }; - do task::spawn_sched(task::single_threaded) {|| + do task::spawn_sched(task::single_threaded) || { let output = readclose(pipe_out.in); comm::send(ch, (1, output)); }; diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index d6c78a4c575..4af007b14dd 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -18,7 +18,7 @@ fn walk_stack(visit: fn(frame) -> bool) { #debug("beginning stack walk"); - do frame_address { |frame_pointer| + do frame_address |frame_pointer| { let mut frame_address: *word = unsafe { reinterpret_cast(frame_pointer) }; @@ -44,7 +44,7 @@ fn walk_stack(visit: fn(frame) -> bool) { #[test] fn test_simple() { - for walk_stack { |_frame| + for walk_stack |_frame| { } } @@ -53,7 +53,7 @@ fn test_simple_deep() { fn run(i: int) { if i == 0 { ret } - for walk_stack { |_frame| + for walk_stack |_frame| { unsafe { breakpoint(); } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 01b463fce24..e0c257f9c0a 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -154,7 +154,7 @@ fn push_char(&s: str, ch: char) { let new_len = len + nb; reserve_at_least(s, new_len); let off = len; - do as_buf(s) {|buf| + do as_buf(s) |buf| { let buf: *mut u8 = ::unsafe::reinterpret_cast(buf); if nb == 1u { *ptr::mut_offset(buf, off) = @@ -208,7 +208,7 @@ fn push_char(&s: str, ch: char) { *ptr::mut_offset(buf, off + nb) = 0u8; } - do as_bytes(s) {|bytes| + do as_bytes(s) |bytes| { let mut mut_bytes: ~[u8] = ::unsafe::reinterpret_cast(bytes); vec::unsafe::set_len(mut_bytes, new_len + 1u); ::unsafe::forget(mut_bytes); @@ -228,7 +228,7 @@ pure fn from_chars(chs: &[const char]) -> str { let mut buf = ""; unchecked { reserve(buf, chs.len()); - for vec::each(chs) {|ch| push_char(buf, ch); } + for vec::each(chs) |ch| { push_char(buf, ch); } } ret buf; } @@ -236,7 +236,7 @@ pure fn from_chars(chs: &[const char]) -> str { #[doc = "Concatenate a vector of strings"] pure fn concat(v: &[const str]) -> str { let mut s: str = ""; - for vec::each(v) {|ss| s += ss; } + for vec::each(v) |ss| { s += ss; } ret s; } @@ -245,7 +245,7 @@ Concatenate a vector of strings, placing a given separator between each "] pure fn connect(v: &[const str], sep: str) -> str { let mut s = "", first = true; - for vec::each(v) {|ss| + for vec::each(v) |ss| { if first { first = false; } else { s += sep; } s += ss; } @@ -289,7 +289,7 @@ fn unshift_char(&s: str, ch: char) { s = from_char(ch) + s; } #[doc = "Returns a string with leading whitespace removed"] pure fn trim_left(+s: str) -> str { - alt find(s, {|c| !char::is_whitespace(c)}) { + alt find(s, |c| !char::is_whitespace(c)) { none { "" } some(first) { if first == 0u { s } @@ -300,7 +300,7 @@ pure fn trim_left(+s: str) -> str { #[doc = "Returns a string with trailing whitespace removed"] pure fn trim_right(+s: str) -> str { - alt rfind(s, {|c| !char::is_whitespace(c)}) { + alt rfind(s, |c| !char::is_whitespace(c)) { none { "" } some(last) { let {next, _} = char_range_at(s, last); @@ -336,7 +336,7 @@ Work with the string as a byte slice, not including trailing null. "] #[inline(always)] pure fn byte_slice<T>(s: str/&, f: fn(v: &[u8]) -> T) -> T { - do unpack_slice(s) {|p,n| + do unpack_slice(s) |p,n| { unsafe { vec::unsafe::form_slice(p, n-1u, f) } } } @@ -421,7 +421,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) } result } else { - splitn(s, {|cur| cur == sep}, count) + splitn(s, |cur| cur == sep, count) } } @@ -495,7 +495,7 @@ pure fn iter_matches(s: str/&a, sep: str/&b, f: fn(uint, uint)) { pure fn iter_between_matches(s: str/&a, sep: str/&b, f: fn(uint, uint)) { let mut last_end = 0u; - do iter_matches(s, sep) {|from, to| + do iter_matches(s, sep) |from, to| { f(last_end, from); last_end = to; } @@ -513,7 +513,7 @@ assert [\"\", \"XXX\", \"YYY\", \"\"] == split_str(\".XXX.YYY.\", \".\") "] pure fn split_str(s: str/&a, sep: str/&b) -> ~[str] { let mut result = ~[]; - do iter_between_matches(s, sep) {|from, to| + do iter_between_matches(s, sep) |from, to| { unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); } } result @@ -521,7 +521,7 @@ pure fn split_str(s: str/&a, sep: str/&b) -> ~[str] { pure fn split_str_nonempty(s: str/&a, sep: str/&b) -> ~[str] { let mut result = ~[]; - do iter_between_matches(s, sep) {|from, to| + do iter_between_matches(s, sep) |from, to| { if to > from { unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); } } @@ -539,7 +539,7 @@ Splits a string into a vector of the substrings separated by LF ('\\n') and/or CR LF ('\\r\\n') "] pure fn lines_any(s: str/&) -> ~[str] { - vec::map(lines(s), {|s| + vec::map(lines(s), |s| { let l = len(s); let mut cp = s; if l > 0u && s[l - 1u] == '\r' as u8 { @@ -553,21 +553,21 @@ pure fn lines_any(s: str/&) -> ~[str] { Splits a string into a vector of the substrings separated by whitespace "] pure fn words(s: str/&) -> ~[str] { - split_nonempty(s, {|c| char::is_whitespace(c)}) + split_nonempty(s, |c| char::is_whitespace(c)) } #[doc = "Convert a string to lowercase. ASCII only"] pure fn to_lower(s: str/&) -> str { - map(s, {|c| - unchecked{(libc::tolower(c as libc::c_char)) as char} - }) + map(s, + |c| unchecked{(libc::tolower(c as libc::c_char)) as char} + ) } #[doc = "Convert a string to uppercase. ASCII only"] pure fn to_upper(s: str/&) -> str { - map(s, {|c| - unchecked{(libc::toupper(c as libc::c_char)) as char} - }) + map(s, + |c| unchecked{(libc::toupper(c as libc::c_char)) as char} + ) } #[doc = " @@ -585,7 +585,7 @@ The original string with all occurances of `from` replaced with `to` "] pure fn replace(s: str, from: str, to: str) -> str { let mut result = "", first = true; - do iter_between_matches(s, from) {|start, end| + do iter_between_matches(s, from) |start, end| { if first { first = false; } else { result += to; } unsafe { result += unsafe::slice_bytes(s, start, end); } } @@ -622,7 +622,7 @@ pure fn hash(&&s: str) -> uint { // djb hash. // FIXME: replace with murmur. (see #859 and #1616) let mut u: uint = 5381u; - for each(s) {|c| u *= 33u; u += c as uint; } + for each(s) |c| { u *= 33u; u += c as uint; } ret u; } @@ -643,7 +643,7 @@ Return true if a predicate matches any character (and false if it matches none or there are no characters) "] pure fn any(ss: str/&, pred: fn(char) -> bool) -> bool { - !all(ss, {|cc| !pred(cc)}) + !all(ss, |cc| !pred(cc)) } #[doc = "Apply a function to each character"] @@ -651,7 +651,7 @@ pure fn map(ss: str/&, ff: fn(char) -> char) -> str { let mut result = ""; unchecked { reserve(result, len(ss)); - do chars_iter(ss) {|cc| + do chars_iter(ss) |cc| { str::push_char(result, ff(cc)); } } @@ -807,7 +807,7 @@ pure fn find_char_between(s: str/&, c: char, start: uint, end: uint) } ret none; } else { - find_between(s, start, end, {|x| x == c}) + find_between(s, start, end, |x| x == c) } } @@ -886,7 +886,7 @@ pure fn rfind_char_between(s: str/&, c: char, start: uint, end: uint) } ret none; } else { - rfind_between(s, start, end, {|x| x == c}) + rfind_between(s, start, end, |x| x == c) } } @@ -1051,7 +1051,7 @@ pure fn rfind_between(s: str/&, start: uint, end: uint, f: fn(char) -> bool) // Utility used by various searching functions pure fn match_at(haystack: str/&a, needle: str/&b, at: uint) -> bool { let mut i = at; - for each(needle) {|c| if haystack[i] != c { ret false; } i += 1u; } + for each(needle) |c| { if haystack[i] != c { ret false; } i += 1u; } ret true; } @@ -1215,7 +1215,7 @@ fn is_alphanumeric(s: str/&) -> bool { Returns the string length/size in bytes not counting the null terminator "] pure fn len(s: str/&) -> uint { - do unpack_slice(s) { |_p, n| n - 1u } + do unpack_slice(s) |_p, n| { n - 1u } } #[doc = "Returns the number of characters that a string holds"] @@ -1267,7 +1267,7 @@ pure fn is_utf16(v: &[const u16]) -> bool { #[doc = "Converts to a vector of `u16` encoded as UTF-16"] pure fn to_utf16(s: str/&) -> ~[u16] { let mut u = ~[]; - do chars_iter(s) {|cch| + do chars_iter(s) |cch| { // Arithmetic with u32 literals is easier on the eyes than chars. let mut ch = cch as u32; @@ -1316,7 +1316,7 @@ pure fn from_utf16(v: &[const u16]) -> str { let mut buf = ""; unchecked { reserve(buf, vec::len(v)); - do utf16_chars(v) {|ch| push_char(buf, ch); } + utf16_chars(v, |ch| push_char(buf, ch)); } ret buf; } @@ -1539,7 +1539,7 @@ Loop through a substring, char by char "] pure fn any_between(s: str/&, start: uint, end: uint, it: fn(char) -> bool) -> bool { - !all_between(s, start, end, {|c| !it(c)}) + !all_between(s, start, end, |c| !it(c)) } // UTF-8 tags and ranges @@ -1583,7 +1583,7 @@ Allows for unsafe manipulation of strings, which is useful for native interop. "] pure fn as_buf<T>(s: str, f: fn(*u8) -> T) -> T { - as_bytes(s, { |v| unsafe { vec::as_buf(v, f) } }) + as_bytes(s, |v| unsafe { vec::as_buf(v, f) }) } #[doc = " @@ -1599,7 +1599,7 @@ let s = str::as_buf(\"PATH\", { |path_buf| libc::getenv(path_buf) }); ~~~ "] pure fn as_c_str<T>(s: str, f: fn(*libc::c_char) -> T) -> T { - as_buf(s, {|buf| f(buf as *libc::c_char) }) + as_buf(s, |buf| f(buf as *libc::c_char)) } @@ -1671,7 +1671,7 @@ Returns the number of single-byte characters the string can hold without reallocating "] pure fn capacity(&&s: str) -> uint { - do as_bytes(s) {|buf| + do as_bytes(s) |buf| { let vcap = vec::capacity(buf); assert vcap > 0u; vcap - 1u @@ -1683,7 +1683,7 @@ pure fn escape_default(s: str/&) -> str { let mut out: str = ""; unchecked { reserve_at_least(out, str::len(s)); - do chars_iter(s) {|c| out += char::escape_default(c); } + chars_iter(s, |c| out += char::escape_default(c)); } ret out; } @@ -1693,7 +1693,7 @@ pure fn escape_unicode(s: str/&) -> str { let mut out: str = ""; unchecked { reserve_at_least(out, str::len(s)); - do chars_iter(s) {|c| out += char::escape_unicode(c); } + chars_iter(s, |c| out += char::escape_unicode(c)); } ret out; } @@ -1726,7 +1726,7 @@ mod unsafe { unsafe fn from_buf_len(buf: *u8, len: uint) -> str { let mut v: ~[u8] = ~[]; vec::reserve(v, len + 1u); - do vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); } + vec::as_buf(v, |b| ptr::memcpy(b, buf, len)); vec::unsafe::set_len(v, len); vec::push(v, 0u8); @@ -1777,14 +1777,14 @@ mod unsafe { If end is greater than the length of the string. "] unsafe fn slice_bytes(s: str/&, begin: uint, end: uint) -> str { - do unpack_slice(s) { |sbuf, n| + do unpack_slice(s) |sbuf, n| { assert (begin <= end); assert (end <= n); let mut v = ~[]; vec::reserve(v, end - begin + 1u); unsafe { - do vec::as_buf(v) { |vbuf| + do vec::as_buf(v) |vbuf| { let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } @@ -1802,7 +1802,7 @@ mod unsafe { #[doc = "Appends a vector of bytes to a string. (Not UTF-8 safe)."] unsafe fn push_bytes(&s: str, bytes: ~[u8]) { - for vec::each(bytes) {|byte| rustrt::rust_str_push(s, byte); } + for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); } } #[doc = " @@ -2037,7 +2037,7 @@ mod tests { log(debug, "split_byte: " + s); let v = split_char(s, c); #debug("split_byte to: %?", v); - assert vec::all2(v, u, { |a,b| a == b }); + assert vec::all2(v, u, |a,b| a == b); } t("abc.hello.there", '.', ~["abc", "hello", "there"]); t(".hello.there", '.', ~["", "hello", "there"]); @@ -2067,7 +2067,7 @@ mod tests { let v = splitn_char(s, c, n); #debug("split_byte to: %?", v); #debug("comparing vs. %?", u); - assert vec::all2(v, u, { |a,b| a == b }); + assert vec::all2(v, u, |a,b| a == b); } t("abc.hello.there", '.', 0u, ~["abc.hello.there"]); t("abc.hello.there", '.', 1u, ~["abc", "hello.there"]); @@ -2149,7 +2149,7 @@ mod tests { fn test_split() { let data = "ประเทศไทย中华Việt Nam"; assert ~["ประเทศไทย中", "Việt Nam"] - == split (data, {|cc| cc == '华'}); + == split (data, |cc| cc == '华'); assert ~["", "", "XXX", "YYY", ""] == split("zzXXXzYYYz", char::is_lowercase); @@ -2157,9 +2157,9 @@ mod tests { assert ~["zz", "", "", "z", "", "", "z"] == split("zzXXXzYYYz", char::is_uppercase); - assert ~["",""] == split("z", {|cc| cc == 'z'}); - assert ~[""] == split("", {|cc| cc == 'z'}); - assert ~["ok"] == split("ok", {|cc| cc == 'z'}); + assert ~["",""] == split("z", |cc| cc == 'z'); + assert ~[""] == split("", |cc| cc == 'z'); + assert ~["ok"] == split("ok", |cc| cc == 'z'); } #[test] @@ -2284,9 +2284,9 @@ mod tests { #[test] fn test_to_lower() { - assert "" == map("", {|c| libc::tolower(c as c_char) as char}); + assert "" == map("", |c| libc::tolower(c as c_char) as char); assert "ymca" == map("YMCA", - {|c| libc::tolower(c as c_char) as char}); + |c| libc::tolower(c as c_char) as char); } #[test] @@ -2574,13 +2574,13 @@ mod tests { #[should_fail] fn test_as_bytes_fail() { // Don't double free - do as_bytes("") {|_bytes| fail } + as_bytes::<()>("", |_bytes| fail ); } #[test] fn test_as_buf() { let a = "Abcdefg"; - let b = as_buf(a, {|buf| + let b = as_buf(a, |buf| { assert unsafe { *buf } == 65u8; 100 }); @@ -2590,7 +2590,7 @@ mod tests { #[test] fn test_as_buf_small() { let a = "A"; - let b = as_buf(a, {|buf| + let b = as_buf(a, |buf| { assert unsafe { *buf } == 65u8; 100 }); @@ -2601,7 +2601,7 @@ mod tests { fn test_as_buf2() { unsafe { let s = "hello"; - let sb = as_buf(s, {|b| b }); + let sb = as_buf(s, |b| b); let s_cstr = unsafe::from_buf(sb); assert (eq(s_cstr, s)); } @@ -2647,7 +2647,7 @@ mod tests { #[test] fn test_chars_iter() { let mut i = 0; - do chars_iter("x\u03c0y") {|ch| + do chars_iter("x\u03c0y") |ch| { alt check i { 0 { assert ch == 'x'; } 1 { assert ch == '\u03c0'; } @@ -2656,14 +2656,14 @@ mod tests { i += 1; } - do chars_iter("") {|_ch| fail; } // should not fail + chars_iter("", |_ch| fail ); // should not fail } #[test] fn test_bytes_iter() { let mut i = 0; - do bytes_iter("xyz") {|bb| + do bytes_iter("xyz") |bb| { alt check i { 0 { assert bb == 'x' as u8; } 1 { assert bb == 'y' as u8; } @@ -2672,7 +2672,7 @@ mod tests { i += 1; } - do bytes_iter("") {|bb| assert bb == 0u8; } + bytes_iter("", |bb| assert bb == 0u8); } #[test] @@ -2681,7 +2681,7 @@ mod tests { let mut ii = 0; - do split_char_iter(data, ' ') {|xx| + do split_char_iter(data, ' ') |xx| { alt ii { 0 { assert "\nMary" == xx; } 1 { assert "had" == xx; } @@ -2699,7 +2699,7 @@ mod tests { let mut ii = 0; - do splitn_char_iter(data, ' ', 2u) {|xx| + do splitn_char_iter(data, ' ', 2u) |xx| { alt ii { 0 { assert "\nMary" == xx; } 1 { assert "had" == xx; } @@ -2716,7 +2716,7 @@ mod tests { let mut ii = 0; - do words_iter(data) {|ww| + do words_iter(data) |ww| { alt ii { 0 { assert "Mary" == ww; } 1 { assert "had" == ww; } @@ -2727,7 +2727,7 @@ mod tests { ii += 1; } - do words_iter("") {|_x| fail; } // should not fail + words_iter("", |_x| fail); // should not fail } #[test] @@ -2736,7 +2736,7 @@ mod tests { let mut ii = 0; - do lines_iter(lf) {|x| + do lines_iter(lf) |x| { alt ii { 0 { assert "" == x; } 1 { assert "Mary had a little lamb" == x; } @@ -2750,9 +2750,8 @@ mod tests { #[test] fn test_map() { - assert "" == map("", {|c| libc::toupper(c as c_char) as char}); - assert "YMCA" == map("ymca", {|c| libc::toupper(c as c_char) - as char}); + assert "" == map("", |c| libc::toupper(c as c_char) as char); + assert "YMCA" == map("ymca", |c| libc::toupper(c as c_char) as char); } #[test] @@ -2819,7 +2818,7 @@ mod tests { 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16, 0x000a_u16 ]) ]; - for vec::each(pairs) {|p| + for vec::each(pairs) |p| { let (s, u) = p; assert to_utf16(s) == u; assert from_utf16(u) == s; @@ -2832,7 +2831,7 @@ mod tests { fn test_each_char() { let s = "abc"; let mut found_b = false; - for each_char(s) {|ch| + for each_char(s) |ch| { if ch == 'b' { found_b = true; break; @@ -2844,7 +2843,7 @@ mod tests { #[test] fn test_unpack_slice() { let a = "hello"; - do unpack_slice(a) {|buf, len| + do unpack_slice(a) |buf, len| { unsafe { assert a[0] == 'h' as u8; assert *buf == 'h' as u8; diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 25fa1fb525e..28ef48240ee 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -183,16 +183,16 @@ mod tests { let lock = arc::arc(create_lock()); let lock2 = arc::clone(&lock); - do task::spawn {|move lock2| + do task::spawn |move lock2| { let lock = arc::get(&lock2); - do (*lock).lock_cond {|c| + do (*lock).lock_cond |c| { c.wait(); } } let mut signaled = false; while !signaled { - do (*arc::get(&lock)).lock_cond {|c| + do (*arc::get(&lock)).lock_cond |c| { signaled = c.signal() } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index c3d215b2de7..2d4c2b44226 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -295,7 +295,7 @@ fn future_result(builder: builder) -> future::future<task_result> { with get_opts(builder) }); - do future::from_fn {|| + do future::from_fn || { alt comm::recv(po) { exit(_, result) { result } } @@ -307,7 +307,7 @@ fn future_task(builder: builder) -> future::future<task> { let mut po = comm::port(); let ch = comm::chan(po); - do add_wrapper(builder) {|body| + do add_wrapper(builder) |body| { fn~() { comm::send(ch, get_task()); body(); @@ -342,7 +342,7 @@ fn run_listener<A:send>(-builder: builder, let setup_po = comm::port(); let setup_ch = comm::chan(setup_po); - do run(builder) {|| + do run(builder) || { let po = comm::port(); let mut ch = comm::chan(po); comm::send(setup_ch, ch); @@ -439,7 +439,7 @@ fn try<T:send>(+f: fn~() -> T) -> result<T,()> { let mut builder = builder(); unsupervise(builder); let result = future_result(builder); - do run(builder) {|| + do run(builder) || { comm::send(ch, f()); } alt future::get(result) { @@ -540,7 +540,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) { }; assert !new_task.is_null(); - do option::iter(opts.notify_chan) {|c| + do option::iter(opts.notify_chan) |c| { // FIXME (#1087): Would like to do notification in Rust rustrt::rust_task_config_notify(new_task, c); } @@ -615,7 +615,7 @@ crust fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. let map: task_local_map = unsafe::reinterpret_cast(map_ptr); - for (*map).each {|entry| + for (*map).each |entry| { alt entry { // Finaliser drops data. We drop the finaliser implicitly here. some((_key, data, finalise_fn)) { finalise_fn(data); } @@ -657,10 +657,10 @@ unsafe fn key_to_key_value<T>(key: local_data_key<T>) -> *libc::c_void { unsafe fn local_data_lookup<T>(map: task_local_map, key: local_data_key<T>) -> option<(uint, *libc::c_void, fn@(+*libc::c_void))> { let key_value = key_to_key_value(key); - let map_pos = (*map).position({|entry| + let map_pos = (*map).position(|entry| alt entry { some((k,_,_)) { k == key_value } none { false } } - }); - do map_pos.map {|index| + ); + do map_pos.map |index| { // .get() is guaranteed because of "none { false }" above. let (_, data_ptr, finaliser) = (*map)[index].get(); (index, data_ptr, finaliser) @@ -671,7 +671,7 @@ unsafe fn local_get_helper<T>(task: *rust_task, key: local_data_key<T>, do_pop: bool) -> option<@T> { let map = get_task_local_map(task); // Interpret our findings from the map - do local_data_lookup(map, key).map {|result| + do local_data_lookup(map, key).map |result| { // A reference count magically appears on 'data' out of thin air. // 'data' has the reference we originally stored it with. We either // need to erase it from the map or artificially bump the count. @@ -718,7 +718,7 @@ unsafe fn local_set<T>(task: *rust_task, key: local_data_key<T>, -data: @T) { } none { // Find an empty slot. If not, grow the vector. - alt (*map).position({|x| x == none}) { + alt (*map).position(|x| x == none) { some(empty_index) { (*map).set_elt(empty_index, new_entry); } @@ -799,7 +799,7 @@ native mod rustrt { fn test_spawn_raw_simple() { let po = comm::port(); let ch = comm::chan(po); - do spawn_raw(default_task_opts()) {|| + do spawn_raw(default_task_opts()) || { comm::send(ch, ()); } comm::recv(po); @@ -812,7 +812,7 @@ fn test_spawn_raw_unsupervise() { supervise: false with default_task_opts() }; - do spawn_raw(opts) {|| + do spawn_raw(opts) || { fail; } } @@ -829,7 +829,7 @@ fn test_spawn_raw_notify() { notify_chan: some(notify_ch) with default_task_opts() }; - do spawn_raw(opts) {|| + do spawn_raw(opts) || { comm::send(task_ch, get_task()); } let task_ = comm::recv(task_po); @@ -840,7 +840,7 @@ fn test_spawn_raw_notify() { notify_chan: some(notify_ch) with default_task_opts() }; - do spawn_raw(opts) {|| + do spawn_raw(opts) || { comm::send(task_ch, get_task()); fail; } @@ -853,7 +853,7 @@ fn test_run_basic() { let po = comm::port(); let ch = comm::chan(po); let buildr = builder(); - do run(buildr) {|| + do run(buildr) || { comm::send(ch, ()); } comm::recv(po); @@ -864,13 +864,13 @@ fn test_add_wrapper() { let po = comm::port(); let ch = comm::chan(po); let buildr = builder(); - do add_wrapper(buildr) {|body| + do add_wrapper(buildr) |body| { fn~() { body(); comm::send(ch, ()); } } - do run(buildr) {||} + do run(buildr) || { } comm::recv(po); } @@ -879,13 +879,13 @@ fn test_add_wrapper() { fn test_future_result() { let buildr = builder(); let result = future_result(buildr); - do run(buildr) {||} + do run(buildr) || { } assert future::get(result) == success; let buildr = builder(); let result = future_result(buildr); unsupervise(buildr); - do run(buildr) {|| fail } + do run(buildr) || { fail } assert future::get(result) == failure; } @@ -895,7 +895,7 @@ fn test_future_task() { let ch = comm::chan(po); let buildr = builder(); let task1 = future_task(buildr); - do run(buildr) {|| comm::send(ch, get_task()) } + do run(buildr) || { comm::send(ch, get_task()) } assert future::get(task1) == comm::recv(po); } @@ -903,7 +903,7 @@ fn test_future_task() { fn test_spawn_listiner_bidi() { let po = comm::port(); let ch = comm::chan(po); - let ch = do spawn_listener {|po| + let ch = do spawn_listener |po| { // Now the child has a port called 'po' to read from and // an environment-captured channel called 'ch'. let res = comm::recv(po); @@ -918,7 +918,7 @@ fn test_spawn_listiner_bidi() { #[test] fn test_try_success() { - alt do try {|| + alt do try || { "Success!" } { result::ok("Success!") { } @@ -929,7 +929,7 @@ fn test_try_success() { #[test] #[ignore(cfg(windows))] fn test_try_fail() { - alt do try {|| + alt do try || { fail } { result::err(()) { } @@ -941,7 +941,7 @@ fn test_try_fail() { #[should_fail] #[ignore(cfg(windows))] fn test_spawn_sched_no_threads() { - do spawn_sched(manual_threads(0u)) {|| }; + do spawn_sched(manual_threads(0u)) || { } } #[test] @@ -952,7 +952,7 @@ fn test_spawn_sched() { fn f(i: int, ch: comm::chan<()>) { let parent_sched_id = rustrt::rust_get_sched_id(); - do spawn_sched(single_threaded) {|| + do spawn_sched(single_threaded) || { let child_sched_id = rustrt::rust_get_sched_id(); assert parent_sched_id != child_sched_id; @@ -973,9 +973,9 @@ fn test_spawn_sched_childs_on_same_sched() { let po = comm::port(); let ch = comm::chan(po); - do spawn_sched(single_threaded) {|| + do spawn_sched(single_threaded) || { let parent_sched_id = rustrt::rust_get_sched_id(); - do spawn {|| + do spawn || { let child_sched_id = rustrt::rust_get_sched_id(); // This should be on the same scheduler assert parent_sched_id == child_sched_id; @@ -1002,7 +1002,7 @@ fn test_spawn_sched_blocking() { // Testing that a task in one scheduler can block in foreign code // without affecting other schedulers - do iter::repeat(20u) {|| + do iter::repeat(20u) || { let start_po = comm::port(); let start_ch = comm::chan(start_po); @@ -1011,7 +1011,7 @@ fn test_spawn_sched_blocking() { let lock = testrt::rust_dbg_lock_create(); - do spawn_sched(single_threaded) {|| + do spawn_sched(single_threaded) || { testrt::rust_dbg_lock_lock(lock); comm::send(start_ch, ()); @@ -1038,7 +1038,7 @@ fn test_spawn_sched_blocking() { let setup_ch = comm::chan(setup_po); let parent_po = comm::port(); let parent_ch = comm::chan(parent_po); - do spawn {|| + do spawn || { let child_po = comm::port(); comm::send(setup_ch, comm::chan(child_po)); pingpong(child_po, parent_ch); @@ -1063,7 +1063,7 @@ fn avoid_copying_the_body(spawnfn: fn(+fn~())) { let x = ~1; let x_in_parent = ptr::addr_of(*x) as uint; - do spawnfn {|| + do spawnfn || { let x_in_child = ptr::addr_of(*x) as uint; comm::send(ch, x_in_child); } @@ -1079,7 +1079,7 @@ fn test_avoid_copying_the_body_spawn() { #[test] fn test_avoid_copying_the_body_spawn_listener() { - do avoid_copying_the_body {|f| + do avoid_copying_the_body |f| { spawn_listener(fn~(move f, _po: comm::port<int>) { f(); }); @@ -1088,9 +1088,9 @@ fn test_avoid_copying_the_body_spawn_listener() { #[test] fn test_avoid_copying_the_body_run() { - do avoid_copying_the_body {|f| + do avoid_copying_the_body |f| { let buildr = builder(); - do run(buildr) {|| + do run(buildr) || { f(); } } @@ -1098,7 +1098,7 @@ fn test_avoid_copying_the_body_run() { #[test] fn test_avoid_copying_the_body_run_listener() { - do avoid_copying_the_body {|f| + do avoid_copying_the_body |f| { let buildr = builder(); run_listener(buildr, fn~(move f, _po: comm::port<int>) { f(); @@ -1108,8 +1108,8 @@ fn test_avoid_copying_the_body_run_listener() { #[test] fn test_avoid_copying_the_body_try() { - do avoid_copying_the_body {|f| - do try {|| + do avoid_copying_the_body |f| { + do try || { f() }; } @@ -1117,10 +1117,10 @@ fn test_avoid_copying_the_body_try() { #[test] fn test_avoid_copying_the_body_future_task() { - do avoid_copying_the_body {|f| + do avoid_copying_the_body |f| { let buildr = builder(); future_task(buildr); - do run(buildr) {|| + do run(buildr) || { f(); } } @@ -1128,10 +1128,10 @@ fn test_avoid_copying_the_body_future_task() { #[test] fn test_avoid_copying_the_body_unsupervise() { - do avoid_copying_the_body {|f| + do avoid_copying_the_body |f| { let buildr = builder(); unsupervise(buildr); - do run(buildr) {|| + do run(buildr) || { f(); } } @@ -1151,7 +1151,7 @@ fn test_osmain() { let po = comm::port(); let ch = comm::chan(po); - do run(buildr) {|| + do run(buildr) || { comm::send(ch, ()); } comm::recv(po); @@ -1166,12 +1166,12 @@ fn test_unkillable() { let ch = po.chan(); // We want to do this after failing - do spawn {|| + do spawn || { iter::repeat(10u, yield); ch.send(()); } - do spawn {|| + do spawn || { yield(); // We want to fail after the unkillable task // blocks on recv @@ -1179,7 +1179,7 @@ fn test_unkillable() { } unsafe { - do unkillable {|| + do unkillable || { let p = ~0; let pp: *uint = unsafe::transmute(p); @@ -1198,7 +1198,7 @@ fn test_unkillable() { fn test_tls_multitask() unsafe { fn my_key(+_x: @str) { } local_data_set(my_key, @"parent data"); - do task::spawn {|| + do task::spawn || { assert local_data_get(my_key) == none; // TLS shouldn't carry over. local_data_set(my_key, @"child data"); assert *(local_data_get(my_key).get()) == "child data"; @@ -1230,13 +1230,13 @@ fn test_tls_pop() unsafe { #[test] fn test_tls_modify() unsafe { fn my_key(+_x: @str) { } - local_data_modify(my_key, {|data| + local_data_modify(my_key, |data| { alt data { some(@val) { fail "unwelcome value: " + val } none { some(@"first data") } } }); - local_data_modify(my_key, {|data| + local_data_modify(my_key, |data| { alt data { some(@"first data") { some(@"next data") } some(@val) { fail "wrong value: " + val } @@ -1254,7 +1254,7 @@ fn test_tls_crust_automorestack_memorial_bug() unsafe { // something within a rust stack segment. Then a subsequent upcall (esp. // for logging, think vsnprintf) would run on a stack smaller than 1 MB. fn my_key(+_x: @str) { } - do task::spawn {|| + do task::spawn || { unsafe { local_data_set(my_key, @"hax"); } } } @@ -1264,7 +1264,7 @@ fn test_tls_multiple_types() unsafe { fn str_key(+_x: @str) { } fn box_key(+_x: @@()) { } fn int_key(+_x: @int) { } - do task::spawn{|| + do task::spawn || { local_data_set(str_key, @"string data"); local_data_set(box_key, @@()); local_data_set(int_key, @42); @@ -1276,7 +1276,7 @@ fn test_tls_overwrite_multiple_types() unsafe { fn str_key(+_x: @str) { } fn box_key(+_x: @@()) { } fn int_key(+_x: @int) { } - do task::spawn{|| + do task::spawn || { local_data_set(str_key, @"string data"); local_data_set(int_key, @42); // This could cause a segfault if overwriting-destruction is done with @@ -1294,7 +1294,7 @@ fn test_tls_cleanup_on_failure() unsafe { fn int_key(+_x: @int) { } local_data_set(str_key, @"parent data"); local_data_set(box_key, @@()); - do task::spawn{|| // spawn_linked + do task::spawn || { // spawn_linked local_data_set(str_key, @"string data"); local_data_set(box_key, @@()); local_data_set(int_key, @42); diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 3420e468a34..359f5ea4a9c 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -59,7 +59,7 @@ impl <A: to_str copy, B: to_str copy, C: to_str copy> of to_str for (A, B, C){ impl <A: to_str> of to_str for ~[A] { fn to_str() -> str { let mut acc = "[", first = true; - for vec::each(self) {|elt| + for vec::each(self) |elt| { if first { first = false; } else { acc += ", "; } acc += elt.to_str(); diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 8e63bc61a7d..7f4ffe97c01 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -131,8 +131,8 @@ Convert to a string in a given base Fails if `radix` < 2 or `radix` > 16 "] fn to_str(num: T, radix: uint) -> str { - do to_str_bytes(false, num, radix) {|slice| - do vec::unpack_slice(slice) {|p, len| + do to_str_bytes(false, num, radix) |slice| { + do vec::unpack_slice(slice) |p, len| { unsafe { str::unsafe::from_buf_len(p, len) } } } @@ -177,7 +177,7 @@ fn to_str_bytes<U>(neg: bool, num: T, radix: uint, // in-bounds, no extra cost. unsafe { - do vec::unpack_slice(buf) {|p, len| + do vec::unpack_slice(buf) |p, len| { let mp = p as *mut u8; let mut i = len; let mut n = num; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index cd895d5b436..e95598a08c8 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -103,12 +103,12 @@ type init_op<T> = fn(uint) -> T; #[doc = "Returns true if a vector contains no elements"] pure fn is_empty<T>(v: &[const T]) -> bool { - unpack_const_slice(v, {|_p, len| len == 0u}) + unpack_const_slice(v, |_p, len| len == 0u) } #[doc = "Returns true if a vector contains some elements"] pure fn is_not_empty<T>(v: &[const T]) -> bool { - unpack_const_slice(v, {|_p, len| len > 0u}) + unpack_const_slice(v, |_p, len| len > 0u) } #[doc = "Returns true if two vectors have the same length"] @@ -169,7 +169,7 @@ pure fn capacity<T>(&&v: ~[const T]) -> uint { #[doc = "Returns the length of a vector"] #[inline(always)] pure fn len<T>(&&v: &[const T]) -> uint { - unpack_const_slice(v, { |_p, len| len}) + unpack_const_slice(v, |_p, len| len) } #[doc = " @@ -266,7 +266,7 @@ pure fn slice<T: copy>(v: &[const T], start: uint, end: uint) -> ~[T] { pure fn view<T: copy>(v: &[const T], start: uint, end: uint) -> &a.[T] { assert (start <= end); assert (end <= len(v)); - do unpack_slice(v) {|p, _len| + do unpack_slice(v) |p, _len| { unsafe { ::unsafe::reinterpret_cast( (ptr::offset(p, start), (end - start) * sys::size_of::<T>())) @@ -387,7 +387,7 @@ fn shift<T>(&v: ~[T]) -> T { let vv = unsafe::to_ptr(vv); rr <- *vv; - for uint::range(1u, ln) {|i| + for uint::range(1u, ln) |i| { let r <- *ptr::offset(vv, i); push(v, r); } @@ -455,16 +455,14 @@ fn push_slow<T>(&v: ~[const T], +initval: T) { // Unchecked vector indexing #[inline(always)] unsafe fn ref<T: copy>(v: &[const T], i: uint) -> T { - unpack_slice(v, {|p, _len| - *ptr::offset(p, i) - }) + unpack_slice(v, |p, _len| *ptr::offset(p, i)) } #[inline(always)] fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) { reserve(v, v.len() + rhs.len()); - for uint::range(0u, rhs.len()) {|i| + for uint::range(0u, rhs.len()) |i| { push(v, unsafe { ref(rhs, i) }) } } @@ -473,8 +471,8 @@ fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) { fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) { reserve(v, v.len() + rhs.len()); unsafe { - do unpack_slice(rhs) {|p, len| - for uint::range(0, len) {|i| + do unpack_slice(rhs) |p, len| { + for uint::range(0, len) |i| { let x <- *ptr::offset(p, i); push(v, x); } @@ -578,7 +576,7 @@ Apply a function to each element of a vector and return the results pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> ~[U] { let mut result = ~[]; unchecked{reserve(result, len(v));} - for each(v) {|elem| unsafe { push(result, f(elem)); } } + for each(v) |elem| { unsafe { push(result, f(elem)); } } ret result; } @@ -588,7 +586,7 @@ Apply a function to each element of a vector and return the results pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] { let mut result = ~[]; unchecked{reserve(result, len(v));} - for eachi(v) {|i, elem| unsafe { push(result, f(i, elem)); } } + for eachi(v) |i, elem| { unsafe { push(result, f(i, elem)); } } ret result; } @@ -598,7 +596,7 @@ of each result vector "] pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) {|elem| unchecked{ push_all_move(result, f(elem)); } } + for each(v) |elem| { unchecked{ push_all_move(result, f(elem)); } } ret result; } @@ -627,7 +625,7 @@ the resulting vector. pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>) -> ~[U] { let mut result = ~[]; - for each(v) {|elem| + for each(v) |elem| { alt f(elem) { none {/* no-op */ } some(result_elem) { unsafe { push(result, result_elem); } } @@ -645,7 +643,7 @@ only those elements for which `f` returned true. "] pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] { let mut result = ~[]; - for each(v) {|elem| + for each(v) |elem| { if f(elem) { unsafe { push(result, elem); } } } ret result; @@ -658,7 +656,7 @@ Flattens a vector of vectors of T into a single vector of T. "] pure fn concat<T: copy>(v: &[[T]/~]) -> ~[T] { let mut r = ~[]; - for each(v) {|inner| unsafe { push_all(r, inner); } } + for each(v) |inner| { unsafe { push_all(r, inner); } } ret r; } @@ -668,7 +666,7 @@ Concatenate a vector of vectors, placing a given separator between each pure fn connect<T: copy>(v: &[[T]/~], sep: T) -> ~[T] { let mut r: ~[T] = ~[]; let mut first = true; - for each(v) {|inner| + for each(v) |inner| { if first { first = false; } else { unsafe { push(r, sep); } } unchecked { push_all(r, inner) }; } @@ -678,7 +676,7 @@ pure fn connect<T: copy>(v: &[[T]/~], sep: T) -> ~[T] { #[doc = "Reduce a vector from left to right"] pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T { let mut accum = z; - do iter(v) { |elt| + do iter(v) |elt| { accum = p(accum, elt); } ret accum; @@ -687,7 +685,7 @@ pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T { #[doc = "Reduce a vector from right to left"] pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U { let mut accum = z; - do riter(v) { |elt| + do riter(v) |elt| { accum = p(elt, accum); } ret accum; @@ -699,7 +697,7 @@ Return true if a predicate matches any elements If the vector contains no elements then false is returned. "] pure fn any<T>(v: &[T], f: fn(T) -> bool) -> bool { - for each(v) {|elem| if f(elem) { ret true; } } + for each(v) |elem| { if f(elem) { ret true; } } ret false; } @@ -726,7 +724,7 @@ Return true if a predicate matches all elements If the vector contains no elements then true is returned. "] pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool { - for each(v) {|elem| if !f(elem) { ret false; } } + for each(v) |elem| { if !f(elem) { ret false; } } ret true; } @@ -736,7 +734,7 @@ Return true if a predicate matches all elements If the vector contains no elements then true is returned. "] pure fn alli<T>(v: &[T], f: fn(uint, T) -> bool) -> bool { - for eachi(v) {|i, elem| if !f(i, elem) { ret false; } } + for eachi(v) |i, elem| { if !f(i, elem) { ret false; } } ret true; } @@ -756,14 +754,14 @@ pure fn all2<T, U>(v0: &[T], v1: &[U], #[doc = "Return true if a vector contains an element with the given value"] pure fn contains<T>(v: &[T], x: T) -> bool { - for each(v) {|elt| if x == elt { ret true; } } + for each(v) |elt| { if x == elt { ret true; } } ret false; } #[doc = "Returns the number of elements that are equal to a given value"] pure fn count<T>(v: &[T], x: T) -> uint { let mut cnt = 0u; - for each(v) {|elt| if x == elt { cnt += 1u; } } + for each(v) |elt| { if x == elt { cnt += 1u; } } ret cnt; } @@ -787,7 +785,7 @@ is returned. If `f` matches no elements then none is returned. "] pure fn find_between<T: copy>(v: &[T], start: uint, end: uint, f: fn(T) -> bool) -> option<T> { - option::map(position_between(v, start, end, f), { |i| v[i] }) + option::map(position_between(v, start, end, f), |i| v[i]) } #[doc = " @@ -810,12 +808,12 @@ the element is returned. If `f` matches no elements then none is returned. "] pure fn rfind_between<T: copy>(v: &[T], start: uint, end: uint, f: fn(T) -> bool) -> option<T> { - option::map(rposition_between(v, start, end, f), { |i| v[i] }) + option::map(rposition_between(v, start, end, f), |i| v[i]) } #[doc = "Find the first index containing a matching value"] pure fn position_elem<T>(v: &[T], x: T) -> option<uint> { - position(v, { |y| x == y }) + position(v, |y| x == y) } #[doc = " @@ -847,7 +845,7 @@ pure fn position_between<T>(v: &[T], start: uint, end: uint, #[doc = "Find the last index containing a matching value"] pure fn rposition_elem<T>(v: &[T], x: T) -> option<uint> { - rposition(v, { |y| x == y }) + rposition(v, |y| x == y) } #[doc = " @@ -894,7 +892,7 @@ of the i-th tuple of the input vector. "] pure fn unzip<T: copy, U: copy>(v: &[(T, U)]) -> (~[T], ~[U]) { let mut as = ~[], bs = ~[]; - for each(v) {|p| + for each(v) |p| { let (a, b) = p; unchecked { vec::push(as, a); @@ -974,7 +972,7 @@ element's value. */ #[inline(always)] pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) { - do unpack_slice(v) { |base_ptr, len| + do unpack_slice(v) |base_ptr, len| { assert start <= end; assert end <= len; unsafe { @@ -996,7 +994,7 @@ Return true to continue, false to break. "] #[inline(always)] pure fn each<T>(v: &[const T], f: fn(T) -> bool) { - do vec::unpack_slice(v) {|p, n| + do vec::unpack_slice(v) |p, n| { let mut n = n; let mut p = p; while n > 0u { @@ -1016,7 +1014,7 @@ Return true to continue, false to break. "] #[inline(always)] pure fn eachi<T>(v: &[const T], f: fn(uint, T) -> bool) { - do vec::unpack_slice(v) {|p, n| + do vec::unpack_slice(v) |p, n| { let mut i = 0u; let mut p = p; while i < n { @@ -1039,7 +1037,7 @@ Both vectors must have the same length #[inline] fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(U, T)) { assert len(v1) == len(v2); - for uint::range(0u, len(v1)) {|i| + for uint::range(0u, len(v1)) |i| { f(v1[i], v2[i]) } } @@ -1064,7 +1062,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the element's value. "] pure fn riter<T>(v: &[T], f: fn(T)) { - riteri(v, { |_i, v| f(v) }) + riteri(v, |_i, v| f(v)) } #[doc =" @@ -1102,7 +1100,7 @@ pure fn permute<T: copy>(v: &[T], put: fn(~[T])) { let mut rest = slice(v, 0u, i); unchecked { push_all(rest, view(v, i+1u, ln)); - permute(rest, {|permutation| + permute(rest, |permutation| { put(append(~[elt], permutation)) }) } @@ -1114,7 +1112,7 @@ pure fn permute<T: copy>(v: &[T], put: fn(~[T])) { pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] { let mut ww = ~[]; assert 1u <= nn; - vec::iteri (xx, {|ii, _x| + vec::iteri (xx, |ii, _x| { let len = vec::len(xx); if ii+nn <= len unchecked { vec::push(ww, vec::slice(xx, ii, ii+nn)); @@ -1130,11 +1128,11 @@ Allows for unsafe manipulation of vector contents, which is useful for native interop. "] fn as_buf<E,T>(v: &[E], f: fn(*E) -> T) -> T { - unpack_slice(v, { |buf, _len| f(buf) }) + unpack_slice(v, |buf, _len| f(buf)) } fn as_mut_buf<E,T>(v: &[mut E], f: fn(*mut E) -> T) -> T { - unpack_mut_slice(v, { |buf, _len| f(buf) }) + unpack_mut_slice(v, |buf, _len| f(buf)) } #[doc = " @@ -1474,7 +1472,7 @@ mod u8 { it out. -- tjc */ let mut u: uint = 5381u; - vec::iter(s, { |c| u *= 33u; u += c as uint; }); + vec::iter(s, |c| {u *= 33u; u += c as uint;}); ret u; } } @@ -1841,21 +1839,21 @@ mod tests { #[test] fn test_iter_empty() { let mut i = 0; - iter::<int>(~[], { |_v| i += 1 }); + iter::<int>(~[], |_v| i += 1); assert i == 0; } #[test] fn test_iter_nonempty() { let mut i = 0; - iter(~[1, 2, 3], { |v| i += v }); + iter(~[1, 2, 3], |v| i += v); assert i == 6; } #[test] fn test_iteri() { let mut i = 0; - iteri(~[1, 2, 3], { |j, v| + iteri(~[1, 2, 3], |j, v| { if i == 0 { assert v == 1; } assert j + 1u == v as uint; i += v; @@ -1866,14 +1864,14 @@ mod tests { #[test] fn test_riter_empty() { let mut i = 0; - riter::<int>(~[], { |_v| i += 1 }); + riter::<int>(~[], |_v| i += 1); assert i == 0; } #[test] fn test_riter_nonempty() { let mut i = 0; - riter(~[1, 2, 3], { |v| + riter(~[1, 2, 3], |v| { if i == 0 { assert v == 3; } i += v }); @@ -1883,7 +1881,7 @@ mod tests { #[test] fn test_riteri() { let mut i = 0; - riteri(~[0, 1, 2], { |j, v| + riteri(~[0, 1, 2], |j, v| { if i == 0 { assert v == 2; } assert j == v as uint; i += v; @@ -1896,19 +1894,19 @@ mod tests { let mut results: ~[~[int]]; results = ~[]; - permute(~[], {|v| vec::push(results, v); }); + permute(~[], |v| vec::push(results, v)); assert results == ~[~[]]; results = ~[]; - permute(~[7], {|v| results += ~[v]; }); + permute(~[7], |v| results += ~[v]); assert results == ~[~[7]]; results = ~[]; - permute(~[1,1], {|v| results += ~[v]; }); + permute(~[1,1], |v| results += ~[v]); assert results == ~[~[1,1],~[1,1]]; results = ~[]; - permute(~[5,2,0], {|v| results += ~[v]; }); + permute(~[5,2,0], |v| results += ~[v]); assert results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]; } |
