From 406813957b65a1627e9b26f73019868a7da1ae79 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Nov 2013 16:34:19 -0800 Subject: [PATCH 01/12] test: Remove most uses of `&fn()` from the tests. --- src/test/auxiliary/cci_impl_lib.rs | 4 +-- src/test/auxiliary/cci_iter_lib.rs | 2 +- src/test/auxiliary/cci_no_inline_lib.rs | 2 +- src/test/bench/core-map.rs | 2 +- src/test/bench/core-set.rs | 25 +++++++------ src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 3 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- .../compile-fail/access-mode-in-closures.rs | 2 +- src/test/compile-fail/block-coerce-no-2.rs | 2 +- src/test/compile-fail/block-coerce-no.rs | 6 ++-- .../compile-fail/borrowck-assign-comp-idx.rs | 2 +- .../compile-fail/borrowck-autoref-3261.rs | 2 +- .../borrowck-insert-during-each.rs | 2 +- .../compile-fail/borrowck-lend-flow-if.rs | 2 +- .../compile-fail/borrowck-lend-flow-loop.rs | 4 +-- src/test/compile-fail/borrowck-lend-flow.rs | 2 +- .../borrowck-loan-blocks-move-cc.rs | 2 +- .../borrowck-loan-blocks-mut-uniq.rs | 2 +- src/test/compile-fail/borrowck-loan-rcvr.rs | 4 +-- .../compile-fail/borrowck-loan-vec-content.rs | 2 +- .../borrowck-move-in-irrefut-pat.rs | 2 +- .../closure-bounds-not-builtin.rs | 2 +- ...ure-bounds-static-cant-capture-borrowed.rs | 2 +- .../compile-fail/closure-bounds-subtype.rs | 8 ++--- src/test/compile-fail/closure-that-fails.rs | 2 +- src/test/compile-fail/do2.rs | 2 +- .../compile-fail/extern-wrong-value-type.rs | 2 +- src/test/compile-fail/fn-variance-1.rs | 2 +- .../compile-fail/immut-function-arguments.rs | 2 +- src/test/compile-fail/issue-2074.rs | 4 +-- src/test/compile-fail/issue-2149.rs | 4 +-- src/test/compile-fail/issue-5216.rs | 4 +-- src/test/compile-fail/issue-5239-1.rs | 2 +- src/test/compile-fail/issue-6762.rs | 11 +++--- src/test/compile-fail/issue-7573.rs | 2 +- src/test/compile-fail/kindck-freeze.rs | 2 +- .../compile-fail/lint-unused-mut-variables.rs | 2 +- src/test/compile-fail/lint-unused-unsafe.rs | 2 +- src/test/compile-fail/liveness-block-unint.rs | 2 +- .../liveness-closure-require-ret.rs | 2 +- .../liveness-init-in-called-fn-expr.rs | 2 +- .../compile-fail/liveness-init-in-fn-expr.rs | 2 +- src/test/compile-fail/missing-do.rs | 2 +- .../moves-based-on-type-block-bad.rs | 2 +- ...ased-on-type-no-recursive-stack-closure.rs | 2 +- .../compile-fail/omitted-arg-wrong-types.rs | 2 +- ...once-cant-move-out-of-non-once-on-stack.rs | 2 +- src/test/compile-fail/once-fn-subtyping.rs | 4 +-- src/test/compile-fail/qquote-1.rs | 2 +- src/test/compile-fail/qquote-2.rs | 2 +- .../regionck-closure-lifetimes.rs | 4 +-- .../compile-fail/regions-creating-enums.rs | 2 +- .../compile-fail/regions-escape-bound-fn-2.rs | 2 +- .../compile-fail/regions-escape-bound-fn.rs | 2 +- .../regions-escape-via-trait-or-not.rs | 2 +- src/test/compile-fail/regions-fn-bound.rs | 16 ++++----- src/test/compile-fail/regions-fn-subtyping.rs | 36 +++++++++---------- src/test/compile-fail/regions-fns.rs | 2 +- .../regions-free-region-ordering-callee.rs | 2 +- .../regions-free-region-ordering-caller.rs | 2 +- .../regions-infer-borrow-scope-within-loop.rs | 2 +- src/test/compile-fail/regions-infer-call-3.rs | 2 +- .../compile-fail/regions-name-undeclared.rs | 12 +++---- src/test/compile-fail/regions-nested-fns-2.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 4 +-- .../compile-fail/regions-ref-in-fn-arg.rs | 2 +- .../compile-fail/regions-ret-borrowed-1.rs | 2 +- src/test/compile-fail/regions-ret-borrowed.rs | 2 +- .../compile-fail/type-arg-out-of-scope.rs | 2 +- .../lexical-scope-in-stack-closure.rs | 2 +- src/test/run-fail/unwind-iter.rs | 2 +- src/test/run-fail/unwind-iter2.rs | 2 +- src/test/run-fail/unwind-lambda.rs | 4 +-- src/test/run-pass-fulldeps/qquote.rs | 2 +- src/test/run-pass/argument-passing.rs | 2 +- src/test/run-pass/assignability-trait.rs | 6 ++-- src/test/run-pass/autobind.rs | 4 +-- src/test/run-pass/block-arg-call-as.rs | 4 +-- .../block-arg-can-be-followed-by-block-arg.rs | 2 +- src/test/run-pass/block-arg-used-as-any.rs | 2 +- src/test/run-pass/block-explicit-types.rs | 2 +- src/test/run-pass/block-fn-coerce.rs | 2 +- src/test/run-pass/block-iter-1.rs | 2 +- src/test/run-pass/block-iter-2.rs | 2 +- .../borrowck-borrow-from-expr-block.rs | 2 +- src/test/run-pass/borrowck-mut-uniq.rs | 2 +- .../borrowck-preserve-box-in-field.rs | 2 +- .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 +- src/test/run-pass/borrowck-preserve-box.rs | 2 +- .../run-pass/borrowck-preserve-expl-deref.rs | 2 +- src/test/run-pass/closure-inference.rs | 2 +- src/test/run-pass/do-empty-args.rs | 2 +- src/test/run-pass/do-no-args.rs | 4 +-- src/test/run-pass/do-pure.rs | 2 +- src/test/run-pass/do-stack.rs | 2 +- src/test/run-pass/do1.rs | 2 +- src/test/run-pass/do2.rs | 2 +- src/test/run-pass/do3.rs | 2 +- src/test/run-pass/fn-bare-coerce-to-block.rs | 2 +- src/test/run-pass/fn-pattern-expected-type.rs | 2 +- src/test/run-pass/fn-type-infer.rs | 2 +- src/test/run-pass/foreach-nested.rs | 2 +- src/test/run-pass/foreach-put-structured.rs | 2 +- .../run-pass/foreach-simple-outer-slot.rs | 2 +- src/test/run-pass/fun-call-variants.rs | 2 +- src/test/run-pass/generic-static-methods.rs | 4 +-- src/test/run-pass/issue-1458.rs | 4 +-- src/test/run-pass/issue-2185.rs | 30 ++++++++-------- src/test/run-pass/issue-2190-2.rs | 6 ++-- src/test/run-pass/issue-2487-a.rs | 2 +- src/test/run-pass/issue-3429.rs | 2 +- src/test/run-pass/issue-3796.rs | 2 +- src/test/run-pass/issue-3874.rs | 2 +- src/test/run-pass/issue-3904.rs | 2 +- src/test/run-pass/issue-5239-2.rs | 2 +- src/test/run-pass/issue-6153.rs | 2 +- src/test/run-pass/issue-868.rs | 2 +- src/test/run-pass/iter-range.rs | 2 +- src/test/run-pass/lambda-infer-unresolved.rs | 4 +-- src/test/run-pass/last-use-in-block.rs | 6 ++-- src/test/run-pass/last-use-is-capture.rs | 2 +- src/test/run-pass/match-phi.rs | 2 +- src/test/run-pass/monad.rs | 8 ++--- src/test/run-pass/move-nullary-fn.rs | 4 +-- src/test/run-pass/mut-function-arguments.rs | 2 +- src/test/run-pass/newlambdas.rs | 4 +-- src/test/run-pass/non-legacy-modes.rs | 2 +- src/test/run-pass/purity-infer.rs | 2 +- src/test/run-pass/reflect-visit-data.rs | 6 ++-- src/test/run-pass/regions-fn-subtyping-2.rs | 4 +-- src/test/run-pass/regions-fn-subtyping.rs | 8 ++--- src/test/run-pass/regions-infer-call-2.rs | 2 +- src/test/run-pass/regions-params.rs | 2 +- src/test/run-pass/sendfn-is-a-block.rs | 2 +- src/test/run-pass/static-impl.rs | 12 +++---- src/test/run-pass/task-killjoin-rsrc.rs | 2 +- src/test/run-pass/tempfile.rs | 2 +- src/test/run-pass/trait-bounds-in-arc.rs | 8 ++--- src/test/run-pass/trait-generic.rs | 4 +-- src/test/run-pass/type-params-in-for-each.rs | 2 +- src/test/run-pass/unnamed_argument_mode.rs | 2 +- src/test/run-pass/unused-move-capture.rs | 2 +- src/test/run-pass/variadic-ffi.rs | 2 +- src/test/run-pass/vec-matching-fold.rs | 4 +-- 145 files changed, 249 insertions(+), 256 deletions(-) diff --git a/src/test/auxiliary/cci_impl_lib.rs b/src/test/auxiliary/cci_impl_lib.rs index aebe9382f64a7..f038acf67a82e 100644 --- a/src/test/auxiliary/cci_impl_lib.rs +++ b/src/test/auxiliary/cci_impl_lib.rs @@ -11,12 +11,12 @@ #[link(name="cci_impl_lib", vers="0.0")]; trait uint_helpers { - fn to(&self, v: uint, f: &fn(uint)); + fn to(&self, v: uint, f: |uint|); } impl uint_helpers for uint { #[inline] - fn to(&self, v: uint, f: &fn(uint)) { + fn to(&self, v: uint, f: |uint|) { let mut i = *self; while i < v { f(i); diff --git a/src/test/auxiliary/cci_iter_lib.rs b/src/test/auxiliary/cci_iter_lib.rs index a264c7d238f52..e08a2f7fcbbec 100644 --- a/src/test/auxiliary/cci_iter_lib.rs +++ b/src/test/auxiliary/cci_iter_lib.rs @@ -11,7 +11,7 @@ #[link(name="cci_iter_lib", vers="0.0")]; #[inline] -pub fn iter(v: &[T], f: &fn(&T)) { +pub fn iter(v: &[T], f: |&T|) { let mut i = 0u; let n = v.len(); while i < n { diff --git a/src/test/auxiliary/cci_no_inline_lib.rs b/src/test/auxiliary/cci_no_inline_lib.rs index fbdb7806b5e67..99d13e91752ab 100644 --- a/src/test/auxiliary/cci_no_inline_lib.rs +++ b/src/test/auxiliary/cci_no_inline_lib.rs @@ -11,7 +11,7 @@ #[link(name="cci_no_inline_lib", vers="0.0")]; // same as cci_iter_lib, more-or-less, but not marked inline -pub fn iter(v: ~[uint], f: &fn(uint)) { +pub fn iter(v: ~[uint], f: |uint|) { let mut i = 0u; let n = v.len(); while i < n { diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 37efa5768af7c..3cfe615b9c019 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -19,7 +19,7 @@ use std::trie::TrieMap; use std::uint; use std::vec; -fn timed(label: &str, f: &fn()) { +fn timed(label: &str, f: ||) { let start = time::precise_time_s(); f(); let end = time::precise_time_s(); diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 9f65dc1e5555b..f9a3618d2abb6 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -27,7 +27,7 @@ struct Results { delete_strings: f64 } -fn timed(result: &mut f64, op: &fn()) { +fn timed(result: &mut f64, op: ||) { let start = extra::time::precise_time_s(); op(); let end = extra::time::precise_time_s(); @@ -36,13 +36,12 @@ fn timed(result: &mut f64, op: &fn()) { impl Results { pub fn bench_int, - R: rand::Rng>( - &mut self, - rng: &mut R, - num_keys: uint, - rand_cap: uint, - f: &fn() -> T) { - { + R: rand::Rng>( + &mut self, + rng: &mut R, + num_keys: uint, + rand_cap: uint, + f: || -> T) { { let mut set = f(); do timed(&mut self.sequential_ints) { for i in range(0u, num_keys) { @@ -79,11 +78,11 @@ impl Results { } pub fn bench_str, - R:rand::Rng>( - &mut self, - rng: &mut R, - num_keys: uint, - f: &fn() -> T) { + R:rand::Rng>( + &mut self, + rng: &mut R, + num_keys: uint, + f: || -> T) { { let mut set = f(); do timed(&mut self.sequential_strings) { diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 4f1e267257538..c7036f8d9db31 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -40,7 +40,7 @@ fn main() { bench!(argv, is_utf8_multibyte); } -fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) { +fn maybe_run_test(argv: &[~str], name: ~str, test: ||) { let mut run_test = false; if os::getenv("RUST_BENCH").is_some() { diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 7becdee43a4ab..853b4eaba9d68 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -104,8 +104,7 @@ fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) { // given a ~[u8], for each window call a function // i.e., for "hello" and windows of size four, // run it("hell") and it("ello"), then return "llo" -fn windows_with_carry(bb: &[u8], nn: uint, - it: &fn(window: &[u8])) -> ~[u8] { +fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] { let mut ii = 0u; let len = bb.len(); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index f2ba0d40ebc69..f8ac5154e7b0d 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -154,7 +154,7 @@ impl Table { } } - fn each(&self, f: &fn(entry: &Entry) -> bool) { + fn each(&self, f: |entry: &Entry| -> bool) { for self.items.each |item| { match *item { None => {} diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index 61fb754f7619f..ef853f57ef5e1 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -11,7 +11,7 @@ struct sty(~[int]); -fn unpack(_unpack: &fn(v: &sty) -> ~[int]) {} +fn unpack(_unpack: |v: &sty| -> ~[int]) {} fn main() { let _foo = unpack(|s| { diff --git a/src/test/compile-fail/block-coerce-no-2.rs b/src/test/compile-fail/block-coerce-no-2.rs index 3e38ce9ab358b..52359bed59c90 100644 --- a/src/test/compile-fail/block-coerce-no-2.rs +++ b/src/test/compile-fail/block-coerce-no-2.rs @@ -15,7 +15,7 @@ fn main() { fn f(f: extern fn(extern fn(extern fn()))) { } - fn g(f: extern fn(&fn())) { + fn g(f: extern fn(||)) { } f(g); diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index 71afba18bb1ff..d07c3feb19423 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -11,9 +11,9 @@ // Make sure that fn-to-block coercion isn't incorrectly lifted over // other tycons. -fn coerce(b: &fn()) -> extern fn() { - fn lol(f: extern fn(v: &fn()) -> extern fn(), - g: &fn()) -> extern fn() { return f(g); } +fn coerce(b: ||) -> extern fn() { + fn lol(f: extern fn(v: ||) -> extern fn(), + g: ||) -> extern fn() { return f(g); } fn fn_id(f: extern fn()) -> extern fn() { return f } return lol(fn_id, b); //~^ ERROR mismatched types diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 81e16b6b615ed..55ef70ad8520f 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -24,7 +24,7 @@ fn a() { info!("{}", *q); } -fn borrow(_x: &[int], _f: &fn()) {} +fn borrow(_x: &[int], _f: ||) {} fn b() { // here we alias the mutable vector into an imm slice and try to diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 4bbd1b0decf57..f834642eb3cc5 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -11,7 +11,7 @@ struct X(Either<(uint,uint),extern fn()>); impl X { - pub fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) { + pub fn with(&self, blk: |x: &Either<(uint,uint),extern fn()>|) { blk(&**self) } } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index e507f0e9e5b92..358305aee08fb 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -15,7 +15,7 @@ struct Foo { } impl Foo { - pub fn foo(&mut self, fun: &fn(&int)) { + pub fn foo(&mut self, fun: |&int|) { for f in self.n.iter() { fun(f); } diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index 563f63b98be05..80b8770397fb2 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -17,7 +17,7 @@ fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { fail!() } -fn for_func(_f: &fn() -> bool) { fail!() } +fn for_func(_f: || -> bool) { fail!() } fn produce() -> T { fail!(); } fn inc(v: &mut ~int) { diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 9286340f6c9f5..14994c0245da9 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -111,7 +111,7 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) { } } -fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) { +fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) { // Here we check that when you break out of an inner loop, the // borrows that go out of scope as you exit the inner loop are // removed from the bitset. @@ -127,7 +127,7 @@ fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) } } -fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) { +fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) { // Similar to `loop_break_pops_scopes` but for the `loop` keyword while cond() { diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index ea840a28b4e6a..5e4e5bb1e73f1 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -17,7 +17,7 @@ fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { fail!() } -fn for_func(_f: &fn() -> bool) { fail!() } +fn for_func(_f: || -> bool) { fail!() } fn produce() -> T { fail!(); } fn inc(v: &mut ~int) { diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 0284f234d9a5a..7a226b8b67c0b 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -10,7 +10,7 @@ use std::task; -fn borrow(v: &int, f: &fn(x: &int)) { +fn borrow(v: &int, f: |x: &int|) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index ae8779eafcc70..417330b6864a7 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn borrow(v: &int, f: &fn(x: &int)) { +fn borrow(v: &int, f: |x: &int|) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index 27a66557434b0..e04eaa4d7af6a 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -12,14 +12,14 @@ struct point { x: int, y: int } trait methods { fn impurem(&self); - fn blockm(&self, f: &fn()); + fn blockm(&self, f: ||); } impl methods for point { fn impurem(&self) { } - fn blockm(&self, f: &fn()) { f() } + fn blockm(&self, f: ||) { f() } } fn a() { diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 8a4a2cdedb230..0617d19919114 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -12,7 +12,7 @@ // (locally rooted) mutable, unique vector, and that we then prevent // modifications to the contents. -fn takes_imm_elt(_v: &int, f: &fn()) { +fn takes_imm_elt(_v: &int, f: ||) { f(); } diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index 628ccd1a5d782..7615036300f6f 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -1,4 +1,4 @@ -fn with(f: &fn(&~str)) {} +fn with(f: |&~str|) {} fn arg_item(&_x: &~str) {} //~^ ERROR cannot move out of dereference of & pointer diff --git a/src/test/compile-fail/closure-bounds-not-builtin.rs b/src/test/compile-fail/closure-bounds-not-builtin.rs index fbf1acb60665b..4afab8db5468b 100644 --- a/src/test/compile-fail/closure-bounds-not-builtin.rs +++ b/src/test/compile-fail/closure-bounds-not-builtin.rs @@ -1,7 +1,7 @@ trait Foo {} -fn take(f: &fn:Foo()) { +fn take(f: ||:Foo) { //~^ ERROR only the builtin traits can be used as closure or object bounds } diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index cac1244a56092..8fb64ee6dacec 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn bar(blk: &fn:'static()) { +fn bar(blk: ||:'static) { } fn foo(x: &()) { diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index f04da0575b954..77281b26554b1 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -1,15 +1,15 @@ -fn take_any(_: &fn:()) { +fn take_any(_: ||:) { } -fn take_const_owned(_: &fn:Freeze+Send()) { +fn take_const_owned(_: ||:Freeze+Send) { } -fn give_any(f: &fn:()) { +fn give_any(f: ||:) { take_any(f); } -fn give_owned(f: &fn:Send()) { +fn give_owned(f: ||:Send) { take_any(f); take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send` } diff --git a/src/test/compile-fail/closure-that-fails.rs b/src/test/compile-fail/closure-that-fails.rs index aad0e8bcbb6dd..fc8e2d4d853f1 100644 --- a/src/test/compile-fail/closure-that-fails.rs +++ b/src/test/compile-fail/closure-that-fails.rs @@ -1,4 +1,4 @@ -fn foo(f: &fn() -> !) {} +fn foo(f: || -> !) {} fn main() { // Type inference didn't use to be able to handle this: diff --git a/src/test/compile-fail/do2.rs b/src/test/compile-fail/do2.rs index 1bffdaa682cdc..ffb779da354f8 100644 --- a/src/test/compile-fail/do2.rs +++ b/src/test/compile-fail/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: &fn(int) -> bool) -> bool { f(10i) } +fn f(f: |int| -> bool) -> bool { f(10i) } fn main() { assert!(do f() |i| { i == 10i } == 10i); diff --git a/src/test/compile-fail/extern-wrong-value-type.rs b/src/test/compile-fail/extern-wrong-value-type.rs index 069c5a77c6c33..6b01b83db21fd 100644 --- a/src/test/compile-fail/extern-wrong-value-type.rs +++ b/src/test/compile-fail/extern-wrong-value-type.rs @@ -14,5 +14,5 @@ extern fn f() { fn main() { // extern functions are extern "C" fn let _x: extern "C" fn() = f; // OK - let _x: &fn() = f; //~ ERROR mismatched types + let _x: || = f; //~ ERROR mismatched types } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index dd14d89a380c1..a4ebfef1774c6 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -13,7 +13,7 @@ fn takes_mut(x: @mut int) { } fn takes_imm(x: @int) { } -fn apply(t: T, f: &fn(T)) { +fn apply(t: T, f: |T|) { f(t) } diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 66b5bd172cace..663a50e9e553e 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -13,7 +13,7 @@ fn f(y: ~int) { } fn g() { - let _frob: &fn(~int) = |q| { *q = 2; }; //~ ERROR cannot assign + let _frob: |~int| = |q| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/issue-2074.rs b/src/test/compile-fail/issue-2074.rs index 7815fca16c69b..3b8c552db2bd2 100644 --- a/src/test/compile-fail/issue-2074.rs +++ b/src/test/compile-fail/issue-2074.rs @@ -10,11 +10,11 @@ // xfail-test fn main() { - let one: &fn() -> uint = || { + let one: || -> uint = || { enum r { a }; a as uint }; - let two = &fn() -> uint = || { + let two = || -> uint = || { enum r { a }; a as uint }; diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 3da01c6fb0139..8d2bdd2d2eb36 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -9,11 +9,11 @@ // except according to those terms. trait vec_monad { - fn bind(&self, f: &fn(A) -> ~[B]); + fn bind(&self, f: |A| -> ~[B]); } impl vec_monad for ~[A] { - fn bind(&self, f: &fn(A) -> ~[B]) { + fn bind(&self, f: |A| -> ~[B]) { let mut r = fail!(); for elt in self.iter() { r = r + f(*elt); } //~^ ERROR the type of this value must be known diff --git a/src/test/compile-fail/issue-5216.rs b/src/test/compile-fail/issue-5216.rs index 8205a6dae6470..ec9ec9565c406 100644 --- a/src/test/compile-fail/issue-5216.rs +++ b/src/test/compile-fail/issue-5216.rs @@ -9,12 +9,12 @@ // except according to those terms. fn f() { } -struct S(&fn()); //~ ERROR missing lifetime specifier +struct S(||); //~ ERROR missing lifetime specifier pub static C: S = S(f); fn g() { } -type T = &fn(); //~ ERROR missing lifetime specifier +type T = ||; //~ ERROR missing lifetime specifier pub static D: T = g; fn main() {} diff --git a/src/test/compile-fail/issue-5239-1.rs b/src/test/compile-fail/issue-5239-1.rs index 97317ec762ad1..a316e3df042e0 100644 --- a/src/test/compile-fail/issue-5239-1.rs +++ b/src/test/compile-fail/issue-5239-1.rs @@ -11,5 +11,5 @@ // Regression test for issue #5239 fn main() { - let x: &fn(int) -> int = |ref x| { x += 1; }; //~ ERROR binary operation + cannot be applied to type `&int` + let x: |int| -> int = |ref x| { x += 1; }; //~ ERROR binary operation + cannot be applied to type `&int` } diff --git a/src/test/compile-fail/issue-6762.rs b/src/test/compile-fail/issue-6762.rs index 14dcc4ea8a3a8..22bb660a08066 100644 --- a/src/test/compile-fail/issue-6762.rs +++ b/src/test/compile-fail/issue-6762.rs @@ -4,20 +4,17 @@ // transferring ownership of the owned box before invoking the stack // closure results in a crash. -fn twice(x: ~uint) -> uint -{ +fn twice(x: ~uint) -> uint { *x * 2 } -fn invoke(f : &fn() -> uint) -{ +fn invoke(f: || -> uint) { f(); } -fn main() -{ +fn main() { let x : ~uint = ~9; - let sq : &fn() -> uint = || { *x * *x }; + let sq : || -> uint = || { *x * *x }; twice(x); invoke(sq); diff --git a/src/test/compile-fail/issue-7573.rs b/src/test/compile-fail/issue-7573.rs index 9dc29e59f904a..4ab0ac6386e4c 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -35,7 +35,7 @@ pub fn remove_package_from_database() { } -pub fn list_database(f: &fn(&PkgId)) { +pub fn list_database(f: |&PkgId|) { let stuff = ["foo", "bar"]; for l in stuff.iter() { diff --git a/src/test/compile-fail/kindck-freeze.rs b/src/test/compile-fail/kindck-freeze.rs index c83892e2a3b31..474c1b1d3cfa4 100644 --- a/src/test/compile-fail/kindck-freeze.rs +++ b/src/test/compile-fail/kindck-freeze.rs @@ -45,7 +45,7 @@ fn test<'a,T,U:Freeze>(_: &'a int) { assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze` // closures are like an `&mut` object - assert_freeze::<&fn()>(); //~ ERROR does not fulfill `Freeze` + assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze` // unsafe ptrs are ok unless they point at unfreezeable things assert_freeze::<*int>(); diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 3abacdba18340..d73f0e6ab1e68 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -55,7 +55,7 @@ fn main() { let mut _allowed = 1; } -fn callback(f: &fn()) {} +fn callback(f: ||) {} // make sure the lint attribute can be turned off #[allow(unused_mut)] diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index 50cc9ceb94e91..253459be85a82 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -18,7 +18,7 @@ mod foo { } } -fn callback(_f: &fn() -> T) -> T { fail!() } +fn callback(_f: || -> T) -> T { fail!() } unsafe fn unsf() {} fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block diff --git a/src/test/compile-fail/liveness-block-unint.rs b/src/test/compile-fail/liveness-block-unint.rs index 98b6cabb6ffac..c46b9013a068d 100644 --- a/src/test/compile-fail/liveness-block-unint.rs +++ b/src/test/compile-fail/liveness-block-unint.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: &fn()) { f(); } +fn force(f: ||) { f(); } fn main() { let x: int; force(|| { diff --git a/src/test/compile-fail/liveness-closure-require-ret.rs b/src/test/compile-fail/liveness-closure-require-ret.rs index 8f9941e668895..9d46202d64e21 100644 --- a/src/test/compile-fail/liveness-closure-require-ret.rs +++ b/src/test/compile-fail/liveness-closure-require-ret.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: &fn() -> int) -> int { f() } +fn force(f: || -> int) -> int { f() } fn main() { info!("{:?}", force(|| {})); } //~ ERROR mismatched types diff --git a/src/test/compile-fail/liveness-init-in-called-fn-expr.rs b/src/test/compile-fail/liveness-init-in-called-fn-expr.rs index 7054cb0d901ce..d759a5738bd22 100644 --- a/src/test/compile-fail/liveness-init-in-called-fn-expr.rs +++ b/src/test/compile-fail/liveness-init-in-called-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let j: &fn() -> int = || { + let j: || -> int = || { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; diff --git a/src/test/compile-fail/liveness-init-in-fn-expr.rs b/src/test/compile-fail/liveness-init-in-fn-expr.rs index 1381631388449..f6bb2f5428370 100644 --- a/src/test/compile-fail/liveness-init-in-fn-expr.rs +++ b/src/test/compile-fail/liveness-init-in-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let f: &fn() -> int = || { + let f: || -> int = || { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; diff --git a/src/test/compile-fail/missing-do.rs b/src/test/compile-fail/missing-do.rs index e6a7698d0f075..5448766c30a72 100644 --- a/src/test/compile-fail/missing-do.rs +++ b/src/test/compile-fail/missing-do.rs @@ -10,7 +10,7 @@ // Regression test for issue #2783 -fn foo(f: &fn()) { f() } +fn foo(f: ||) { f() } fn main() { ~"" || 42; //~ ERROR binary operation || cannot be applied to type diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index 11c4d078208ee..355305b6c630c 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -8,7 +8,7 @@ enum E { Baz } -fn f(s: &S, g: &fn(&S)) { +fn f(s: &S, g: |&S|) { g(s) } diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index 2762140be3793..db8effb1de3df 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -36,7 +36,7 @@ fn innocent_looking_victim() { } } -fn conspirator(f: &fn(&R, bool)) { +fn conspirator(f: |&R, bool|) { let r = R {c: f}; f(&r, false) //~ ERROR use of moved value } diff --git a/src/test/compile-fail/omitted-arg-wrong-types.rs b/src/test/compile-fail/omitted-arg-wrong-types.rs index a44c113269b98..f43ff0421a9a7 100644 --- a/src/test/compile-fail/omitted-arg-wrong-types.rs +++ b/src/test/compile-fail/omitted-arg-wrong-types.rs @@ -9,7 +9,7 @@ // except according to those terms. // xfail-test - #2093 -fn let_in(x: T, f: &fn(T)) {} +fn let_in(x: T, f: |T|) {} fn main() { let_in(3u, |i| { assert!(i == 3); }); diff --git a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs index aedeb92df787c..4927acde48d87 100644 --- a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs +++ b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs @@ -15,7 +15,7 @@ extern mod extra; use extra::arc; use std::util; -fn foo(blk: &fn()) { +fn foo(blk: ||) { blk(); blk(); } diff --git a/src/test/compile-fail/once-fn-subtyping.rs b/src/test/compile-fail/once-fn-subtyping.rs index 5f7393fdf8b8c..503b4d3e77b97 100644 --- a/src/test/compile-fail/once-fn-subtyping.rs +++ b/src/test/compile-fail/once-fn-subtyping.rs @@ -11,7 +11,7 @@ #[feature(once_fns)]; fn main() { let f: &once fn() = ||(); - let g: &fn() = f; //~ ERROR mismatched types - let h: &fn() = ||(); + let g: || = f; //~ ERROR mismatched types + let h: || = ||(); let i: &once fn() = h; // ok } diff --git a/src/test/compile-fail/qquote-1.rs b/src/test/compile-fail/qquote-1.rs index 0112c0adea298..f55fcfc204b2f 100644 --- a/src/test/compile-fail/qquote-1.rs +++ b/src/test/compile-fail/qquote-1.rs @@ -62,6 +62,6 @@ fn main() { check_pp(expr3, pprust::print_expr, "2 - 23 + 7"); } -fn check_pp(expr: T, f: &fn(pprust::ps, T), expect: str) { +fn check_pp(expr: T, f: |pprust::ps, T|, expect: str) { fail!(); } diff --git a/src/test/compile-fail/qquote-2.rs b/src/test/compile-fail/qquote-2.rs index 57355885e2f46..262abc045a411 100644 --- a/src/test/compile-fail/qquote-2.rs +++ b/src/test/compile-fail/qquote-2.rs @@ -57,6 +57,6 @@ fn main() { check_pp(*stmt, pprust::print_stmt, ""); } -fn check_pp(expr: T, f: &fn(pprust::ps, T), expect: str) { +fn check_pp(expr: T, f: |pprust::ps, T|, expect: str) { fail!(); } diff --git a/src/test/compile-fail/regionck-closure-lifetimes.rs b/src/test/compile-fail/regionck-closure-lifetimes.rs index c9a3e044d9c47..f66b17d68c76f 100644 --- a/src/test/compile-fail/regionck-closure-lifetimes.rs +++ b/src/test/compile-fail/regionck-closure-lifetimes.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn env<'a>(_: &'a uint, blk: &fn(p: &'a fn())) { +fn env<'a>(_: &'a uint, blk: |p: 'a |||) { // Test that the closure here cannot be assigned // the lifetime `'a`, which outlives the current // block. @@ -21,7 +21,7 @@ fn env<'a>(_: &'a uint, blk: &fn(p: &'a fn())) { blk(|| *statep = 1); //~ ERROR cannot infer an appropriate lifetime } -fn no_env_no_for<'a>(_: &'a uint, blk: &fn(p: &'a fn())) { +fn no_env_no_for<'a>(_: &'a uint, blk: |p: 'a |||) { // Test that a closure with no free variables CAN // outlive the block in which it is created. // diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index c2d8427d5eb39..0a370425c4165 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -27,7 +27,7 @@ fn compute(x: &ast) -> uint { } } -fn map_nums(x: &ast, f: &fn(uint) -> uint) -> &ast { +fn map_nums(x: &ast, f: |uint| -> uint) -> &ast { match *x { num(x) => { return &num(f(x)); //~ ERROR borrowed value does not live long enough diff --git a/src/test/compile-fail/regions-escape-bound-fn-2.rs b/src/test/compile-fail/regions-escape-bound-fn-2.rs index 305aa68528493..d2551ec4fedb4 100644 --- a/src/test/compile-fail/regions-escape-bound-fn-2.rs +++ b/src/test/compile-fail/regions-escape-bound-fn-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: &fn(x: &int)) { +fn with_int(f: |x: &int|) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-bound-fn.rs b/src/test/compile-fail/regions-escape-bound-fn.rs index 5ac5e334be23d..eb72b4b0c5321 100644 --- a/src/test/compile-fail/regions-escape-bound-fn.rs +++ b/src/test/compile-fail/regions-escape-bound-fn.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: &fn(x: &int)) { +fn with_int(f: |x: &int|) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index 5b6dc1b2f4fb4..32ec59d97413b 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -18,7 +18,7 @@ impl<'self> deref for &'self int { } } -fn with(f: &fn(x: &int) -> R) -> int { +fn with(f: |x: &int| -> R) -> int { f(&3).get() } diff --git a/src/test/compile-fail/regions-fn-bound.rs b/src/test/compile-fail/regions-fn-bound.rs index add53d3d9b0b9..09801d37ee92c 100644 --- a/src/test/compile-fail/regions-fn-bound.rs +++ b/src/test/compile-fail/regions-fn-bound.rs @@ -11,8 +11,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn of() -> &fn(T) { fail!(); } -fn subtype(x: &fn(T)) { fail!(); } +fn of() -> |T| { fail!(); } +fn subtype(x: |T|) { fail!(); } fn test_fn(_x: &'x T, _y: &'y T, _z: &'z T) { // Here, x, y, and z are free. Other letters @@ -21,14 +21,14 @@ fn test_fn(_x: &'x T, _y: &'y T, _z: &'z T) { // iff T1 <: T2. // should be the default: - subtype::<&'static fn()>(of::<&fn()>()); - subtype::<&fn()>(of::<&'static fn()>()); + subtype::<'static ||>(of::<||>()); + subtype::<||>(of::<'static ||>()); // - subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types - subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types + subtype::<'x ||>(of::<||>()); //~ ERROR mismatched types + subtype::<'x ||>(of::<'y ||>()); //~ ERROR mismatched types - subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types - subtype::<&'static fn()>(of::<&'x fn()>()); + subtype::<'x ||>(of::<'static ||>()); //~ ERROR mismatched types + subtype::<'static ||>(of::<'x ||>()); } diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index cad73daa46b15..0cbd37a3b9a5e 100644 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ b/src/test/compile-fail/regions-fn-subtyping.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn of() -> &fn(T) { fail!(); } -fn subtype(x: &fn(T)) { fail!(); } +fn of() -> |T| { fail!(); } +fn subtype(x: |T|) { fail!(); } fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) { // Here, x, y, and z are free. Other letters @@ -17,29 +17,29 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) { // subtype::(of::()) will typecheck // iff T1 <: T2. - subtype::<&fn<'a>(&'a T)>( - of::<&fn<'a>(&'a T)>()); + subtype::< <'a>|&'a T|>( + of::< <'a>|&'a T|>()); - subtype::<&fn<'a>(&'a T)>( - of::<&fn<'b>(&'b T)>()); + subtype::< <'a>|&'a T|>( + of::< <'b>|&'b T|>()); - subtype::<&fn<'b>(&'b T)>( - of::<&fn(&'x T)>()); + subtype::< <'b>|&'b T|>( + of::<|&'x T|>()); - subtype::<&fn(&'x T)>( - of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types + subtype::<|&'x T|>( + of::< <'b>|&'b T|>()); //~ ERROR mismatched types - subtype::<&fn<'a,'b>(&'a T, &'b T)>( - of::<&fn<'a>(&'a T, &'a T)>()); + subtype::< <'a,'b>|&'a T, &'b T|>( + of::< <'a>|&'a T, &'a T|>()); - subtype::<&fn<'a>(&'a T, &'a T)>( - of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types + subtype::< <'a>|&'a T, &'a T|>( + of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types - subtype::<&fn<'a,'b>(&'a T, &'b T)>( - of::<&fn(&'x T, &'y T)>()); + subtype::< <'a,'b>|&'a T, &'b T|>( + of::<|&'x T, &'y T|>()); - subtype::<&fn(&'x T, &'y T)>( - of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types + subtype::<|&'x T, &'y T|>( + of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types } fn main() {} diff --git a/src/test/compile-fail/regions-fns.rs b/src/test/compile-fail/regions-fns.rs index 715261d816a4e..854584ec535e6 100644 --- a/src/test/compile-fail/regions-fns.rs +++ b/src/test/compile-fail/regions-fns.rs @@ -12,7 +12,7 @@ // we reported errors in this case: fn not_ok<'b>(a: &uint, b: &'b uint) { - let mut g: &fn(x: &uint) = |x: &'b uint| {}; + let mut g: |x: &uint| = |x: &'b uint| {}; //~^ ERROR mismatched types g(a); } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index fb31e477ba279..94c617b218266 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -30,7 +30,7 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint { fail!(); } -fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: &fn(&'a &'b uint)) { +fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: |&'a &'b uint|) { let z: Option<&'a &'b uint> = None; } diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index 58fa437a6a365..808e850907f28 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -26,7 +26,7 @@ fn call3<'a, 'b>(a: &'a uint, b: &'b uint) { } fn call4<'a, 'b>(a: &'a uint, b: &'b uint) { - let z: Option<&fn(&'a &'b uint)> = None; + let z: Option<|&'a &'b uint|> = None; //~^ ERROR pointer has a longer lifetime than the data it references } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index e0764d3929133..26b0f2b66c387 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -12,7 +12,7 @@ fn borrow<'r, T>(x: &'r T) -> &'r T {x} -fn foo(cond: &fn() -> bool, box: &fn() -> @int) { +fn foo(cond: || -> bool, box: || -> @int) { let mut y: ∫ loop { let x = box(); diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index 585b56d5a420b..8002f8bcc50d2 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -10,7 +10,7 @@ fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x } -fn with(f: &fn(x: &int) -> T) -> T { +fn with(f: |x: &int| -> T) -> T { f(&20) } diff --git a/src/test/compile-fail/regions-name-undeclared.rs b/src/test/compile-fail/regions-name-undeclared.rs index abff33e051491..ba3d7bd29f4ac 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -43,16 +43,16 @@ fn bar<'a>(x: &'a int) { // &'a CAN be declared on functions and used then: fn g<'a>(a: &'a int) { } // OK - fn h(a: &fn<'a>(&'a int)) { } // OK + fn h(a: <'a>|&'a int|) { } // OK } // Test nesting of lifetimes in fn type declarations fn fn_types(a: &'a int, //~ ERROR undeclared lifetime - b: &fn<'a>(a: &'a int, - b: &'b int, //~ ERROR undeclared lifetime - c: &fn<'b>(a: &'a int, - b: &'b int), - d: &'b int), //~ ERROR undeclared lifetime + b: <'a>|a: &'a int, + b: &'b int, //~ ERROR undeclared lifetime + c: <'b>|a: &'a int, + b: &'b int|, + d: &'b int|, //~ ERROR undeclared lifetime c: &'a int) //~ ERROR undeclared lifetime { } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index fe995052c52e4..8e9a7546541d0 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ignore(_f: &fn<'z>(&'z int) -> &'z int) {} +fn ignore(_f: <'z>|&'z int| -> &'z int) {} fn nested() { let y = 3; diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index 244e9cc06a1ac..11610f422a0c8 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) { let y = 3; let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime - ignore::<&fn<'z>(&'z int)>(|z| { + ignore::< <'z>|&'z int|>(|z| { ay = x; ay = &y; ay = z; }); - ignore::<&fn<'z>(&'z int) -> &'z int>(|z| { + ignore::< <'z>|&'z int| -> &'z int>(|z| { if false { return x; } //~ ERROR mismatched types //~^ ERROR cannot infer an appropriate lifetime if false { return ay; } diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index 4848262750720..9574f05fa5852 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -2,7 +2,7 @@ fn arg_item(~ref x: ~int) -> &'static int { x //~^ ERROR borrowed value does not live long enough } -fn with(f: &fn(~int) -> R) -> R { f(~3) } +fn with(f: |~int| -> R) -> R { f(~3) } fn arg_closure() -> &'static int { with(|~ref x| x) //~ ERROR borrowed value does not live long enough diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index ee6ed3b0d76f6..7eb5fa3c60be6 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,7 +12,7 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with(f: &fn<'a>(x: &'a int) -> R) -> R { +fn with(f: <'a>|x: &'a int| -> R) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index c2e48053260cf..2f6f2f44cda58 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -15,7 +15,7 @@ // used to successfully compile because we failed to account for the // fact that fn(x: &int) rebound the region &. -fn with(f: &fn(x: &int) -> R) -> R { +fn with(f: |x: &int| -> R) -> R { f(&3) } diff --git a/src/test/compile-fail/type-arg-out-of-scope.rs b/src/test/compile-fail/type-arg-out-of-scope.rs index 07dc677c04763..240b1aa06d472 100644 --- a/src/test/compile-fail/type-arg-out-of-scope.rs +++ b/src/test/compile-fail/type-arg-out-of-scope.rs @@ -10,6 +10,6 @@ // error-pattern:attempt to use a type argument out of scope fn foo(x: T) { - fn bar(f: &fn(T) -> T) { } + fn bar(f: |T| -> T) { } } fn main() { foo(1); } diff --git a/src/test/debug-info/lexical-scope-in-stack-closure.rs b/src/test/debug-info/lexical-scope-in-stack-closure.rs index 238ad3c519d13..f052448c146a6 100644 --- a/src/test/debug-info/lexical-scope-in-stack-closure.rs +++ b/src/test/debug-info/lexical-scope-in-stack-closure.rs @@ -51,7 +51,7 @@ fn main() { zzz(); sentinel(); - let stack_closure: &fn(int) = |x| { + let stack_closure: |int| = |x| { zzz(); sentinel(); diff --git a/src/test/run-fail/unwind-iter.rs b/src/test/run-fail/unwind-iter.rs index 51c6cb3adf318..1f5e455564e34 100644 --- a/src/test/run-fail/unwind-iter.rs +++ b/src/test/run-fail/unwind-iter.rs @@ -13,7 +13,7 @@ #[allow(unreachable_code)]; #[allow(unused_variable)]; -fn x(it: &fn(int)) { +fn x(it: |int|) { fail!(); it(0); } diff --git a/src/test/run-fail/unwind-iter2.rs b/src/test/run-fail/unwind-iter2.rs index 17936df6959f2..d0726d2544ca6 100644 --- a/src/test/run-fail/unwind-iter2.rs +++ b/src/test/run-fail/unwind-iter2.rs @@ -10,7 +10,7 @@ // error-pattern:fail -fn x(it: &fn(int)) { +fn x(it: |int|) { let _a = @0; it(1); } diff --git a/src/test/run-fail/unwind-lambda.rs b/src/test/run-fail/unwind-lambda.rs index 4b95afc0ee28b..bd415e9eac3e7 100644 --- a/src/test/run-fail/unwind-lambda.rs +++ b/src/test/run-fail/unwind-lambda.rs @@ -16,13 +16,13 @@ fn main() { let cheese = ~"roquefort"; let carrots = @~"crunchy"; - let result: &'static fn(@~str, &fn(~str)) = (|tasties, macerate| { + let result: &'static fn(@~str, |~str|) = (|tasties, macerate| { macerate((*tasties).clone()); }); result(carrots, |food| { let mush = food + cheese; let cheese = cheese.clone(); - let f: &fn() = || { + let f: || = || { let _chew = mush + cheese; fail!("so yummy") }; diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs index c7c8e3a19a6cd..0fcd49790e072 100644 --- a/src/test/run-pass-fulldeps/qquote.rs +++ b/src/test/run-pass-fulldeps/qquote.rs @@ -74,7 +74,7 @@ fn main() { } fn check_pp(cx: fake_ext_ctxt, - expr: T, f: &fn(pprust::ps, T), expect: ~str) { + expr: T, f: |pprust::ps, T|, expect: ~str) { let s = do io::with_str_writer |wr| { let pp = pprust::rust_printer(wr, cx.parse_sess().interner); f(pp, expr); diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index 6d6ae3da62fef..7f43642463e1e 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -21,7 +21,7 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int { return r; } -fn f2(a: int, f: &fn(int)) -> int { f(1); return a; } +fn f2(a: int, f: |int|) -> int { f(1); return a; } pub fn main() { let mut a = X {x: 1}; diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 5269f7dab5aad..1da5023dce023 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -13,17 +13,17 @@ // it. trait iterable { - fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool; + fn iterate(&self, blk: |x: &A| -> bool) -> bool; } impl<'self,A> iterable for &'self [A] { - fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { + fn iterate(&self, f: |x: &A| -> bool) -> bool { self.iter().advance(f) } } impl iterable for ~[A] { - fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { + fn iterate(&self, f: |x: &A| -> bool) -> bool { self.iter().advance(f) } } diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs index 440ad723a12ce..c0ceb50a2c4be 100644 --- a/src/test/run-pass/autobind.rs +++ b/src/test/run-pass/autobind.rs @@ -10,10 +10,10 @@ fn f(x: ~[T]) -> T { return x[0]; } -fn g(act: &fn(~[int]) -> int) -> int { return act(~[1, 2, 3]); } +fn g(act: |~[int]| -> int) -> int { return act(~[1, 2, 3]); } pub fn main() { assert_eq!(g(f), 1); - let f1: &fn(~[~str]) -> ~str = f; + let f1: |~[~str]| -> ~str = f; assert_eq!(f1(~[~"x", ~"y", ~"z"]), ~"x"); } diff --git a/src/test/run-pass/block-arg-call-as.rs b/src/test/run-pass/block-arg-call-as.rs index 5aa28258792e6..70307e1ff0465 100644 --- a/src/test/run-pass/block-arg-call-as.rs +++ b/src/test/run-pass/block-arg-call-as.rs @@ -10,11 +10,11 @@ extern mod extra; -fn asSendfn( f : proc()->uint ) -> uint { +fn asSendfn(f: proc() -> uint) -> uint { return f(); } -fn asBlock( f : &fn()->uint ) -> uint { +fn asBlock(f: || -> uint) -> uint { return f(); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs index ed8641eaf85f9..0d82e294caf22 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - fn f(i: &fn() -> uint) -> uint { i() } + fn f(i: || -> uint) -> uint { i() } let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0]; let z = do do v.iter().fold(f) |x, _y| { x } { 22u }; assert_eq!(z, 22u); diff --git a/src/test/run-pass/block-arg-used-as-any.rs b/src/test/run-pass/block-arg-used-as-any.rs index 7ee9d9e5b5489..f05eb8e30b17c 100644 --- a/src/test/run-pass/block-arg-used-as-any.rs +++ b/src/test/run-pass/block-arg-used-as-any.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn call_any(f: &fn() -> uint) -> uint { +fn call_any(f: || -> uint) -> uint { return f(); } diff --git a/src/test/run-pass/block-explicit-types.rs b/src/test/run-pass/block-explicit-types.rs index 379fced1d334b..82e563ae41ced 100644 --- a/src/test/run-pass/block-explicit-types.rs +++ b/src/test/run-pass/block-explicit-types.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - fn as_buf(s: ~str, f: &fn(~str) -> T) -> T { f(s) } + fn as_buf(s: ~str, f: |~str| -> T) -> T { f(s) } as_buf(~"foo", |foo: ~str| -> () error!("{}", foo) ); } diff --git a/src/test/run-pass/block-fn-coerce.rs b/src/test/run-pass/block-fn-coerce.rs index 19e1fd4099b74..bbb30e9578e9e 100644 --- a/src/test/run-pass/block-fn-coerce.rs +++ b/src/test/run-pass/block-fn-coerce.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: &fn() -> int) -> int { return f(); } +fn force(f: || -> int) -> int { return f(); } pub fn main() { fn f() -> int { return 7; } assert_eq!(force(f), 7); diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index a977eb40992bb..821f4b17a79b1 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -10,7 +10,7 @@ // xfail-fast -fn iter_vec(v: ~[T], f: &fn(&T)) { for x in v.iter() { f(x); } } +fn iter_vec(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } } pub fn main() { let v = ~[1, 2, 3, 4, 5, 6, 7]; diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index e5ea54c2a3eb3..ddaf7f233cf01 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -10,7 +10,7 @@ // xfail-fast -fn iter_vec(v: ~[T], f: &fn(&T)) { for x in v.iter() { f(x); } } +fn iter_vec(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } } pub fn main() { let v = ~[1, 2, 3, 4, 5]; diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index bc3078f88eabb..dae10ed6d3917 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -13,7 +13,7 @@ use std::borrow; use std::ptr; -fn borrow(x: &int, f: &fn(x: &int)) { +fn borrow(x: &int, f: |x: &int|) { f(x) } diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index 9057ebf7983f1..7b4c4247a353b 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -20,7 +20,7 @@ fn add_int(x: &mut Ints, v: int) { util::swap(&mut values, &mut x.values); } -fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool { +fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool { let l = x.values.len(); range(0u, l).advance(|i| f(&x.values[i])) } diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs index 214753c009cda..bc8eeb5cd4178 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -12,7 +12,7 @@ use std::ptr; -fn borrow(x: &int, f: &fn(x: &int)) { +fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); let after = *x; diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 239dd4c6dc43c..3ff30192efed8 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -12,7 +12,7 @@ use std::ptr; -fn borrow(x: &int, f: &fn(x: &int)) { +fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); let after = *x; diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs index 8a97e8f1b5caf..e83621d6bb280 100644 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -12,7 +12,7 @@ use std::ptr; -fn borrow(x: &int, f: &fn(x: &int)) { +fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); let after = *x; diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs index a0010d3619091..6041fa977f5c3 100644 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -12,7 +12,7 @@ use std::ptr; -fn borrow(x: &int, f: &fn(x: &int)) { +fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); let after = *x; diff --git a/src/test/run-pass/closure-inference.rs b/src/test/run-pass/closure-inference.rs index 167fbdf3fc052..b6943b4570018 100644 --- a/src/test/run-pass/closure-inference.rs +++ b/src/test/run-pass/closure-inference.rs @@ -12,7 +12,7 @@ fn foo(i: int) -> int { i + 1 } -fn apply(f: &fn(A) -> A, v: A) -> A { f(v) } +fn apply(f: |A| -> A, v: A) -> A { f(v) } pub fn main() { let f = {|i| foo(i)}; diff --git a/src/test/run-pass/do-empty-args.rs b/src/test/run-pass/do-empty-args.rs index 485d59da7d4b2..0078294eb89d5 100644 --- a/src/test/run-pass/do-empty-args.rs +++ b/src/test/run-pass/do-empty-args.rs @@ -11,7 +11,7 @@ // no-reformat // Testing various forms of `do` with empty arg lists -fn f(_f: &fn() -> bool) -> bool { +fn f(_f: || -> bool) -> bool { true } diff --git a/src/test/run-pass/do-no-args.rs b/src/test/run-pass/do-no-args.rs index 1f725ffb3576a..eb6a4a3db5421 100644 --- a/src/test/run-pass/do-no-args.rs +++ b/src/test/run-pass/do-no-args.rs @@ -10,9 +10,9 @@ // Testing that we can drop the || in do exprs -fn f(_f: &fn() -> bool) -> bool { true } +fn f(_f: || -> bool) -> bool { true } -fn d(_f: &fn()) { } +fn d(_f: ||) { } pub fn main() { do d { } diff --git a/src/test/run-pass/do-pure.rs b/src/test/run-pass/do-pure.rs index 8a0509c177432..85bb84c6061ac 100644 --- a/src/test/run-pass/do-pure.rs +++ b/src/test/run-pass/do-pure.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(_f: &fn()) { +fn f(_f: ||) { } fn g() { diff --git a/src/test/run-pass/do-stack.rs b/src/test/run-pass/do-stack.rs index 0444b269cb34f..fddf3b15c78da 100644 --- a/src/test/run-pass/do-stack.rs +++ b/src/test/run-pass/do-stack.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: &fn(int)) { f(10) } +fn f(f: |int|) { f(10) } pub fn main() { do f() |i| { assert!(i == 10) } diff --git a/src/test/run-pass/do1.rs b/src/test/run-pass/do1.rs index 0444b269cb34f..fddf3b15c78da 100644 --- a/src/test/run-pass/do1.rs +++ b/src/test/run-pass/do1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: &fn(int)) { f(10) } +fn f(f: |int|) { f(10) } pub fn main() { do f() |i| { assert!(i == 10) } diff --git a/src/test/run-pass/do2.rs b/src/test/run-pass/do2.rs index 9feededc9800b..1bfb10a9f7568 100644 --- a/src/test/run-pass/do2.rs +++ b/src/test/run-pass/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: &fn(int) -> int) -> int { f(10) } +fn f(f: |int| -> int) -> int { f(10) } pub fn main() { assert_eq!(do f() |i| { i }, 10); diff --git a/src/test/run-pass/do3.rs b/src/test/run-pass/do3.rs index eeb983b455792..c08842a45ce77 100644 --- a/src/test/run-pass/do3.rs +++ b/src/test/run-pass/do3.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: &fn(int) -> int) -> int { f(10) } +fn f(f: |int| -> int) -> int { f(10) } pub fn main() { assert_eq!(do f |i| { i }, 10); diff --git a/src/test/run-pass/fn-bare-coerce-to-block.rs b/src/test/run-pass/fn-bare-coerce-to-block.rs index db7604d11484d..1231a49dcd31b 100644 --- a/src/test/run-pass/fn-bare-coerce-to-block.rs +++ b/src/test/run-pass/fn-bare-coerce-to-block.rs @@ -10,7 +10,7 @@ fn bare() {} -fn likes_block(f: &fn()) { f() } +fn likes_block(f: ||) { f() } pub fn main() { likes_block(bare); diff --git a/src/test/run-pass/fn-pattern-expected-type.rs b/src/test/run-pass/fn-pattern-expected-type.rs index 450e2a70aab9b..fb75abc6ea093 100644 --- a/src/test/run-pass/fn-pattern-expected-type.rs +++ b/src/test/run-pass/fn-pattern-expected-type.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let f: &fn((int,int)) = |(x, y)| { + let f: |(int,int)| = |(x, y)| { assert_eq!(x, 1); assert_eq!(y, 2); }; diff --git a/src/test/run-pass/fn-type-infer.rs b/src/test/run-pass/fn-type-infer.rs index 09e7ababa6cb6..cf783ca141c0a 100644 --- a/src/test/run-pass/fn-type-infer.rs +++ b/src/test/run-pass/fn-type-infer.rs @@ -11,7 +11,7 @@ #[allow(unused_variable)]; pub fn main() { - // We should be able to type infer inside of &fns. + // We should be able to type infer inside of ||s. let _f = || { let i = 10; }; diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index 36c086093cff0..1f63bd68d34f7 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -11,7 +11,7 @@ -fn two(it: &fn(int)) { it(0); it(1); } +fn two(it: |int|) { it(0); it(1); } pub fn main() { let mut a: ~[int] = ~[-1, -1, -1, -1]; diff --git a/src/test/run-pass/foreach-put-structured.rs b/src/test/run-pass/foreach-put-structured.rs index 2b57cc033f9f6..91468841e0923 100644 --- a/src/test/run-pass/foreach-put-structured.rs +++ b/src/test/run-pass/foreach-put-structured.rs @@ -10,7 +10,7 @@ -fn pairs(it: &fn((int, int))) { +fn pairs(it: |(int, int)|) { let mut i: int = 0; let mut j: int = 0; while i < 10 { it((i, j)); i += 1; j += i; } diff --git a/src/test/run-pass/foreach-simple-outer-slot.rs b/src/test/run-pass/foreach-simple-outer-slot.rs index f38ac1ed38b4a..34b131893269a 100644 --- a/src/test/run-pass/foreach-simple-outer-slot.rs +++ b/src/test/run-pass/foreach-simple-outer-slot.rs @@ -19,7 +19,7 @@ pub fn main() { assert_eq!(sum, 45); } -fn first_ten(it: &fn(int)) { +fn first_ten(it: |int|) { let mut i: int = 0; while i < 10 { info!("first_ten"); it(i); i = i + 1; } } diff --git a/src/test/run-pass/fun-call-variants.rs b/src/test/run-pass/fun-call-variants.rs index 0edfe174680e6..479f4f8387fb4 100644 --- a/src/test/run-pass/fun-call-variants.rs +++ b/src/test/run-pass/fun-call-variants.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ho(f: &fn(int) -> int) -> int { let n: int = f(3); return n; } +fn ho(f: |int| -> int) -> int { let n: int = f(3); return n; } fn direct(x: int) -> int { return x + 1; } diff --git a/src/test/run-pass/generic-static-methods.rs b/src/test/run-pass/generic-static-methods.rs index 2e281812d138f..5832c565d7f4c 100644 --- a/src/test/run-pass/generic-static-methods.rs +++ b/src/test/run-pass/generic-static-methods.rs @@ -9,11 +9,11 @@ // except according to those terms. trait vec_utils { - fn map_(x: &Self, f: &fn(&T) -> U) -> ~[U]; + fn map_(x: &Self, f: |&T| -> U) -> ~[U]; } impl vec_utils for ~[T] { - fn map_(x: &~[T], f: &fn(&T) -> U) -> ~[U] { + fn map_(x: &~[T], f: |&T| -> U) -> ~[U] { let mut r = ~[]; for elt in x.iter() { r.push(f(elt)); diff --git a/src/test/run-pass/issue-1458.rs b/src/test/run-pass/issue-1458.rs index e22f38287ad5d..ce5c932f8da2e 100644 --- a/src/test/run-pass/issue-1458.rs +++ b/src/test/run-pass/issue-1458.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn plus_one(f: &fn() -> int) -> int { +fn plus_one(f: || -> int) -> int { return f() + 1; } -fn ret_plus_one() -> extern fn(&fn() -> int) -> int { +fn ret_plus_one() -> extern fn(|| -> int) -> int { return plus_one; } diff --git a/src/test/run-pass/issue-2185.rs b/src/test/run-pass/issue-2185.rs index fdf88f414ecfc..afe7656b7a343 100644 --- a/src/test/run-pass/issue-2185.rs +++ b/src/test/run-pass/issue-2185.rs @@ -18,12 +18,12 @@ // // Running /usr/local/bin/rustc: // issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait -// issue-2185.rs:24 impl iterable for &'static fn(&fn(uint)) { -// issue-2185.rs:25 fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) } +// issue-2185.rs:24 impl iterable for &'static fn(|uint|) { +// issue-2185.rs:25 fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) } // issue-2185.rs:26 } // issue-2185.rs:20:0: 22:1 note: note conflicting implementation here -// issue-2185.rs:20 impl iterable for &'static fn(&fn(A)) { -// issue-2185.rs:21 fn iter(&self, blk: &fn(A)) { self(blk); } +// issue-2185.rs:20 impl iterable for 'static ||A|| { +// issue-2185.rs:21 fn iter(&self, blk: |A|) { self(blk); } // issue-2185.rs:22 } // // … so it looks like it's just not possible to implement both the generic iterable and iterable for the type iterable. Is it okay if I just remove this test? @@ -39,26 +39,24 @@ // warrant still having a test, so I inlined the old definitions. trait iterable { - fn iter(&self, blk: &fn(A)); + fn iter(&self, blk: |A|); } -impl iterable for &'static fn(&fn(A)) { - fn iter(&self, blk: &fn(A)) { self(blk); } +impl iterable for 'static ||A|| { + fn iter(&self, blk: |A|) { self(blk); } } -impl iterable for &'static fn(&fn(uint)) { - fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) } +impl iterable for 'static ||uint|| { + fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) } } -fn filter>(self: IA, - prd: &'static fn(A) -> bool, - blk: &fn(A)) { +fn filter>(self: IA, prd: 'static |A| -> bool, blk: |A|) { do self.iter |a| { if prd(a) { blk(a) } } } -fn foldl>(self: IA, b0: B, blk: &fn(B, A) -> B) -> B { +fn foldl>(self: IA, b0: B, blk: |B, A| -> B) -> B { let mut b = b0; do self.iter |a| { b = blk(b, a); @@ -66,7 +64,7 @@ fn foldl>(self: IA, b0: B, blk: &fn(B, A) -> B) -> B { b } -fn range(lo: uint, hi: uint, it: &fn(uint)) { +fn range(lo: uint, hi: uint, it: |uint|) { let mut i = lo; while i < hi { it(i); @@ -75,8 +73,8 @@ fn range(lo: uint, hi: uint, it: &fn(uint)) { } pub fn main() { - let range: &'static fn(&fn(uint)) = |a| range(0u, 1000u, a); - let filt: &'static fn(&fn(v: uint)) = |a| filter( + let range: 'static ||uint|| = |a| range(0u, 1000u, a); + let filt: 'static ||v: uint|| = |a| filter( range, |&&n: uint| n % 3u != 0u && n % 5u != 0u, a); diff --git a/src/test/run-pass/issue-2190-2.rs b/src/test/run-pass/issue-2190-2.rs index d5ee712d412bc..571944e5300b8 100644 --- a/src/test/run-pass/issue-2190-2.rs +++ b/src/test/run-pass/issue-2190-2.rs @@ -10,19 +10,19 @@ // xfail-test FIXME #2190 mod a { - fn foo(f: &fn()) { f() } + fn foo(f: ||) { f() } fn bar() {} pub fn main() { foo(||bar()); } } mod b { - fn foo(f: Option<&fn()>) { f.iter(|x|x()) } + fn foo(f: Option<||>) { f.iter(|x|x()) } fn bar() {} pub fn main() { foo(Some(bar)); } } mod c { - fn foo(f: Option<&fn()>) { f.iter(|x|x()) } + fn foo(f: Option<||>) { f.iter(|x|x()) } fn bar() {} pub fn main() { foo(Some(||bar())); } } diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index c12325e6ff52e..110bceced82a1 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -31,7 +31,7 @@ fn socket() -> socket { } } -fn closure(f: &fn()) { f() } +fn closure(f: ||) { f() } fn setsockopt_bytes(_sock: int) { } diff --git a/src/test/run-pass/issue-3429.rs b/src/test/run-pass/issue-3429.rs index fc493485b794e..cce90f8a2cd29 100644 --- a/src/test/run-pass/issue-3429.rs +++ b/src/test/run-pass/issue-3429.rs @@ -10,6 +10,6 @@ pub fn main() { let x = 1; - let y: &fn() -> int = || x; + let y: || -> int = || x; let _z = y(); } diff --git a/src/test/run-pass/issue-3796.rs b/src/test/run-pass/issue-3796.rs index 5f4409391396a..a7c6f86b45357 100644 --- a/src/test/run-pass/issue-3796.rs +++ b/src/test/run-pass/issue-3796.rs @@ -12,7 +12,7 @@ #[deny(dead_assignment)]; fn main() { let mut x = 1; - let f: &fn() -> int = || { x + 20 }; + let f: || -> int = || { x + 20 }; assert_eq!(f(), 21); x += 1; assert_eq!(f(), 22); diff --git a/src/test/run-pass/issue-3874.rs b/src/test/run-pass/issue-3874.rs index ea1242ae21613..40725311f313c 100644 --- a/src/test/run-pass/issue-3874.rs +++ b/src/test/run-pass/issue-3874.rs @@ -10,7 +10,7 @@ enum PureCounter { PureCounter(uint) } -fn each(thing: PureCounter, blk: &fn(v: &uint)) { +fn each(thing: PureCounter, blk: |v: &uint|) { let PureCounter(ref x) = thing; blk(x); } diff --git a/src/test/run-pass/issue-3904.rs b/src/test/run-pass/issue-3904.rs index 6b678ffdb1c4a..4a9b58067b056 100644 --- a/src/test/run-pass/issue-3904.rs +++ b/src/test/run-pass/issue-3904.rs @@ -9,7 +9,7 @@ // except according to those terms. // xfail-test -type ErrPrinter = &fn(&str, &str); +type ErrPrinter = |&str, &str|; fn example_err(prog: &str, arg: &str) { println!("{}: {}", prog, arg) diff --git a/src/test/run-pass/issue-5239-2.rs b/src/test/run-pass/issue-5239-2.rs index ba70fac0e4e8f..eabc1cfeb595f 100644 --- a/src/test/run-pass/issue-5239-2.rs +++ b/src/test/run-pass/issue-5239-2.rs @@ -11,7 +11,7 @@ // Regression test for issue #5239 pub fn main() { - let _f: &fn(int) -> int = |ref x: int| { *x }; + let _f: |int| -> int = |ref x: int| { *x }; let foo = 10; assert!(_f(foo) == 10); } diff --git a/src/test/run-pass/issue-6153.rs b/src/test/run-pass/issue-6153.rs index 668d6f3ae45e3..f7d0316880a4d 100644 --- a/src/test/run-pass/issue-6153.rs +++ b/src/test/run-pass/issue-6153.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn swap(f: &fn(~[int]) -> ~[int]) -> ~[int] { +fn swap(f: |~[int]| -> ~[int]) -> ~[int] { let x = ~[1, 2, 3]; f(x) } diff --git a/src/test/run-pass/issue-868.rs b/src/test/run-pass/issue-868.rs index 2a82f559d547c..12dcc4ecd2c3a 100644 --- a/src/test/run-pass/issue-868.rs +++ b/src/test/run-pass/issue-868.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(g: &fn() -> T) -> T { g() } +fn f(g: || -> T) -> T { g() } pub fn main() { let _x = f( | | { 10 }); diff --git a/src/test/run-pass/iter-range.rs b/src/test/run-pass/iter-range.rs index 5ada4aa8c7583..c44b7389666f9 100644 --- a/src/test/run-pass/iter-range.rs +++ b/src/test/run-pass/iter-range.rs @@ -10,7 +10,7 @@ -fn range_(a: int, b: int, it: &fn(int)) { +fn range_(a: int, b: int, it: |int|) { assert!((a < b)); let mut i: int = a; while i < b { it(i); i += 1; } diff --git a/src/test/run-pass/lambda-infer-unresolved.rs b/src/test/run-pass/lambda-infer-unresolved.rs index e615cfae6add0..b6ee2d10fb33f 100644 --- a/src/test/run-pass/lambda-infer-unresolved.rs +++ b/src/test/run-pass/lambda-infer-unresolved.rs @@ -9,13 +9,13 @@ // except according to those terms. // This should typecheck even though the type of e is not fully -// resolved when we finish typechecking the &fn. +// resolved when we finish typechecking the ||. struct Refs { refs: ~[int], n: int } pub fn main() { let e = @mut Refs{refs: ~[], n: 0}; - let _f: &fn() = || error!("{}", e.n); + let _f: || = || error!("{}", e.n); e.refs.push(1); } diff --git a/src/test/run-pass/last-use-in-block.rs b/src/test/run-pass/last-use-in-block.rs index e2dbf7d29db19..8117c5657e989 100644 --- a/src/test/run-pass/last-use-in-block.rs +++ b/src/test/run-pass/last-use-in-block.rs @@ -10,7 +10,7 @@ // Issue #1818 -fn lp(s: ~str, f: &fn(~str) -> T) -> T { +fn lp(s: ~str, f: |~str| -> T) -> T { while false { let r = f(s); return (r); @@ -18,8 +18,8 @@ fn lp(s: ~str, f: &fn(~str) -> T) -> T { fail!(); } -fn apply(s: ~str, f: &fn(~str) -> T) -> T { - fn g(s: ~str, f: &fn(~str) -> T) -> T {f(s)} +fn apply(s: ~str, f: |~str| -> T) -> T { + fn g(s: ~str, f: |~str| -> T) -> T {f(s)} g(s, |v| { let r = f(v); r }) } diff --git a/src/test/run-pass/last-use-is-capture.rs b/src/test/run-pass/last-use-is-capture.rs index 5c349a095513e..c34e65b2b4213 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -13,7 +13,7 @@ struct A { a: ~int } pub fn main() { - fn invoke(f: &fn()) { f(); } + fn invoke(f: ||) { f(); } let k = ~22; let _u = A {a: k.clone()}; invoke(|| error!("{:?}", k.clone()) ) diff --git a/src/test/run-pass/match-phi.rs b/src/test/run-pass/match-phi.rs index c25f573e73bce..fc851e444e86b 100644 --- a/src/test/run-pass/match-phi.rs +++ b/src/test/run-pass/match-phi.rs @@ -13,7 +13,7 @@ enum thing { a, b, c, } -fn foo(it: &fn(int)) { it(10); } +fn foo(it: |int|) { it(10); } pub fn main() { let mut x = true; diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 8baf15c8493be..891ee4812c1b8 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -11,11 +11,11 @@ // xfail-fast trait vec_monad { - fn bind(&self, f: &fn(&A) -> ~[B]) -> ~[B]; + fn bind(&self, f: |&A| -> ~[B]) -> ~[B]; } impl vec_monad for ~[A] { - fn bind(&self, f: &fn(&A) -> ~[B]) -> ~[B] { + fn bind(&self, f: |&A| -> ~[B]) -> ~[B] { let mut r = ~[]; for elt in self.iter() { r.push_all_move(f(elt)); @@ -25,11 +25,11 @@ impl vec_monad for ~[A] { } trait option_monad { - fn bind(&self, f: &fn(&A) -> Option) -> Option; + fn bind(&self, f: |&A| -> Option) -> Option; } impl option_monad for Option { - fn bind(&self, f: &fn(&A) -> Option) -> Option { + fn bind(&self, f: |&A| -> Option) -> Option { match *self { Some(ref a) => { f(a) } None => { None } diff --git a/src/test/run-pass/move-nullary-fn.rs b/src/test/run-pass/move-nullary-fn.rs index 87281c2fd2253..4b613e9beaab2 100644 --- a/src/test/run-pass/move-nullary-fn.rs +++ b/src/test/run-pass/move-nullary-fn.rs @@ -9,9 +9,9 @@ // except according to those terms. // Issue #922 -fn f2(_thing: &fn()) { } +fn f2(_thing: ||) { } -fn f(thing: &fn()) { +fn f(thing: ||) { f2(thing); } diff --git a/src/test/run-pass/mut-function-arguments.rs b/src/test/run-pass/mut-function-arguments.rs index 0fa89ba0f049d..5801ccebb0fcd 100644 --- a/src/test/run-pass/mut-function-arguments.rs +++ b/src/test/run-pass/mut-function-arguments.rs @@ -14,7 +14,7 @@ fn f(mut y: ~int) { } fn g() { - let frob: &fn(~int) = |mut q| { *q = 2; assert!(*q == 2); }; + let frob: |~int| = |mut q| { *q = 2; assert!(*q == 2); }; let w = ~37; frob(w); diff --git a/src/test/run-pass/newlambdas.rs b/src/test/run-pass/newlambdas.rs index d9d0daa7138cd..1835514c0d1fe 100644 --- a/src/test/run-pass/newlambdas.rs +++ b/src/test/run-pass/newlambdas.rs @@ -10,9 +10,9 @@ // Tests for the new |args| expr lambda syntax -fn f(i: int, f: &fn(int) -> int) -> int { f(i) } +fn f(i: int, f: |int| -> int) -> int { f(i) } -fn g(_g: &fn()) { } +fn g(_g: ||) { } pub fn main() { assert_eq!(f(10, |a| a), 10); diff --git a/src/test/run-pass/non-legacy-modes.rs b/src/test/run-pass/non-legacy-modes.rs index 642686e06e5dd..8262432db607f 100644 --- a/src/test/run-pass/non-legacy-modes.rs +++ b/src/test/run-pass/non-legacy-modes.rs @@ -12,7 +12,7 @@ struct X { repr: int } -fn apply(x: T, f: &fn(T)) { +fn apply(x: T, f: |T|) { f(x); } diff --git a/src/test/run-pass/purity-infer.rs b/src/test/run-pass/purity-infer.rs index debde77b21128..bbb312842ce14 100644 --- a/src/test/run-pass/purity-infer.rs +++ b/src/test/run-pass/purity-infer.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn something(f: &fn()) { f(); } +fn something(f: ||) { f(); } pub fn main() { something(|| error!("hi!") ); } diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 42614f7653928..96081d30275fb 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -22,7 +22,7 @@ use std::unstable::raw::Vec; /// Trait for visitor that wishes to reflect on data. trait movable_ptr { - fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void); + fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void); } /// Helper function for alignment calculation. @@ -471,7 +471,7 @@ struct Stuff { } impl my_visitor { - pub fn get(&mut self, f: &fn(T)) { + pub fn get(&mut self, f: |T|) { unsafe { f((*(self.ptr1 as *T)).clone()); } @@ -490,7 +490,7 @@ impl my_visitor { struct Inner { inner: V } impl movable_ptr for my_visitor { - fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void) { + fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void) { self.ptr1 = adjustment(self.ptr1); self.ptr2 = adjustment(self.ptr2); } diff --git a/src/test/run-pass/regions-fn-subtyping-2.rs b/src/test/run-pass/regions-fn-subtyping-2.rs index ef8d9970c2b47..9d2a959eae1c7 100644 --- a/src/test/run-pass/regions-fn-subtyping-2.rs +++ b/src/test/run-pass/regions-fn-subtyping-2.rs @@ -13,13 +13,13 @@ // Here, `f` is a function that takes a pointer `x` and a function // `g`, where `g` requires its argument `y` to be in the same region // that `x` is in. -fn has_same_region(f: &fn<'a>(x: &'a int, g: &fn(y: &'a int))) { +fn has_same_region(f: <'a>|x: &'a int, g: |y: &'a int||) { // `f` should be the type that `wants_same_region` wants, but // right now the compiler complains that it isn't. wants_same_region(f); } -fn wants_same_region(_f: &fn<'b>(x: &'b int, g: &fn(y: &'b int))) { +fn wants_same_region(_f: <'b>|x: &'b int, g: |y: &'b int||) { } pub fn main() { diff --git a/src/test/run-pass/regions-fn-subtyping.rs b/src/test/run-pass/regions-fn-subtyping.rs index 06c8aca474164..14e56bd618117 100644 --- a/src/test/run-pass/regions-fn-subtyping.rs +++ b/src/test/run-pass/regions-fn-subtyping.rs @@ -14,21 +14,21 @@ #[allow(unused_variable)]; // Should pass region checking. -fn ok(f: &fn(x: &uint)) { +fn ok(f: |x: &uint|) { // Here, g is a function that can accept a uint pointer with // lifetime r, and f is a function that can accept a uint pointer // with any lifetime. The assignment g = f should be OK (i.e., // f's type should be a subtype of g's type), because f can be // used in any context that expects g's type. But this currently // fails. - let mut g: &fn<'r>(y: &'r uint) = |x| { }; + let mut g: <'r>|y: &'r uint| = |x| { }; g = f; } // This version is the same as above, except that here, g's type is // inferred. -fn ok_inferred(f: &fn(x: &uint)) { - let mut g: &fn<'r>(x: &'r uint) = |_| {}; +fn ok_inferred(f: |x: &uint|) { + let mut g: <'r>|x: &'r uint| = |_| {}; g = f; } diff --git a/src/test/run-pass/regions-infer-call-2.rs b/src/test/run-pass/regions-infer-call-2.rs index 42be3b5b97553..061f27972871f 100644 --- a/src/test/run-pass/regions-infer-call-2.rs +++ b/src/test/run-pass/regions-infer-call-2.rs @@ -10,7 +10,7 @@ fn takes_two(x: &int, y: &int) -> int { *x + *y } -fn with(f: &fn(x: &int) -> T) -> T { +fn with(f: |x: &int| -> T) -> T { f(&20) } diff --git a/src/test/run-pass/regions-params.rs b/src/test/run-pass/regions-params.rs index ea32cf866a0cd..5fe92f527d05b 100644 --- a/src/test/run-pass/regions-params.rs +++ b/src/test/run-pass/regions-params.rs @@ -12,7 +12,7 @@ fn region_identity<'r>(x: &'r uint) -> &'r uint { x } -fn apply(t: T, f: &fn(T) -> T) -> T { f(t) } +fn apply(t: T, f: |T| -> T) -> T { f(t) } fn parameterized(x: &uint) -> uint { let z = apply(x, ({|y| diff --git a/src/test/run-pass/sendfn-is-a-block.rs b/src/test/run-pass/sendfn-is-a-block.rs index f7808f7f8ac8b..1b80d7648a6df 100644 --- a/src/test/run-pass/sendfn-is-a-block.rs +++ b/src/test/run-pass/sendfn-is-a-block.rs @@ -10,7 +10,7 @@ // xfail-fast -fn test(f: &fn(uint) -> uint) -> uint { +fn test(f: |uint| -> uint) -> uint { return f(22u); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 651b3342d5833..28aab18cf6cfc 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -26,12 +26,12 @@ mod b { trait uint_utils { fn str(&self) -> ~str; - fn multi(&self, f: &fn(uint)); + fn multi(&self, f: |uint|); } impl uint_utils for uint { fn str(&self) -> ~str { self.to_str() } - fn multi(&self, f: &fn(uint)) { + fn multi(&self, f: |uint|) { let mut c = 0u; while c < *self { f(c); c += 1u; } } @@ -39,14 +39,14 @@ impl uint_utils for uint { trait vec_utils { fn length_(&self, ) -> uint; - fn iter_(&self, f: &fn(&T)); - fn map_(&self, f: &fn(&T) -> U) -> ~[U]; + fn iter_(&self, f: |&T|); + fn map_(&self, f: |&T| -> U) -> ~[U]; } impl vec_utils for ~[T] { fn length_(&self) -> uint { self.len() } - fn iter_(&self, f: &fn(&T)) { for x in self.iter() { f(x); } } - fn map_(&self, f: &fn(&T) -> U) -> ~[U] { + fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } } + fn map_(&self, f: |&T| -> U) -> ~[U] { let mut r = ~[]; for elt in self.iter() { r.push(f(elt)); diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 395d6b0b51ad2..94e402bfa9021 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -45,7 +45,7 @@ fn notify(ch: Chan, v: @mut bool) -> notify { } fn joinable(f: proc()) -> Port { - fn wrapper(c: Chan, f: &fn()) { + fn wrapper(c: Chan, f: ||) { let b = @mut false; error!("wrapper: task=%? allocated v=%x", 0, diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index a10753451400a..cee2079251a28 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -136,7 +136,7 @@ pub fn test_rmdir_recursive_ok() { assert!(!root.join("bar").join("blat").exists()); } -fn in_tmpdir(f: &fn()) { +fn in_tmpdir(f: ||) { let tmpdir = TempDir::new("test").expect("can't make tmpdir"); assert!(os::change_dir(tmpdir.path())); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index a4510ef70e1b2..7b331c4356807 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -22,7 +22,7 @@ use std::task; use std::cell; trait Pet { - fn name(&self, blk: &fn(&str)); + fn name(&self, blk: |&str|); fn num_legs(&self) -> uint; fn of_good_pedigree(&self) -> bool; } @@ -44,19 +44,19 @@ struct Goldfyshe { } impl Pet for Catte { - fn name(&self, blk: &fn(&str)) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 } } impl Pet for Dogge { - fn name(&self, blk: &fn(&str)) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.bark_decibels < 70 || self.tricks_known > 20 } } impl Pet for Goldfyshe { - fn name(&self, blk: &fn(&str)) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name) } fn num_legs(&self) -> uint { 0 } fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 } } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index f448bcb4ab5d2..90f87d832ff89 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -24,10 +24,10 @@ impl to_str for () { } trait map { - fn map(&self, f: &fn(&T) -> U) -> ~[U]; + fn map(&self, f: |&T| -> U) -> ~[U]; } impl map for ~[T] { - fn map(&self, f: &fn(&T) -> U) -> ~[U] { + fn map(&self, f: |&T| -> U) -> ~[U] { let mut r = ~[]; // FIXME: #7355 generates bad code with VecIterator for i in range(0u, self.len()) { diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs index a5a9075af7b24..042b5e96bbc08 100644 --- a/src/test/run-pass/type-params-in-for-each.rs +++ b/src/test/run-pass/type-params-in-for-each.rs @@ -13,7 +13,7 @@ struct S { b: uint, } -fn range_(lo: uint, hi: uint, it: &fn(uint)) { +fn range_(lo: uint, hi: uint, it: |uint|) { let mut lo_ = lo; while lo_ < hi { it(lo_); lo_ += 1u; } } diff --git a/src/test/run-pass/unnamed_argument_mode.rs b/src/test/run-pass/unnamed_argument_mode.rs index c52658542f05b..948824834df84 100644 --- a/src/test/run-pass/unnamed_argument_mode.rs +++ b/src/test/run-pass/unnamed_argument_mode.rs @@ -3,7 +3,7 @@ fn good(_a: &int) { // unnamed argument &int is now parse x: &int -fn called(_f: &fn(&int)) { +fn called(_f: |&int|) { } pub fn main() { diff --git a/src/test/run-pass/unused-move-capture.rs b/src/test/run-pass/unused-move-capture.rs index 662121a09931f..ceb91d557f6ae 100644 --- a/src/test/run-pass/unused-move-capture.rs +++ b/src/test/run-pass/unused-move-capture.rs @@ -10,6 +10,6 @@ pub fn main() { let _x = ~1; - let lam_move: &fn() = || {}; + let lam_move: || = || {}; lam_move(); } diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index d82e2890ae8d3..06026d58f6005 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -15,7 +15,7 @@ extern { fn sprintf(s: *mut c_char, format: *c_char, ...) -> c_int; } -unsafe fn check(expected: &str, f: &fn(*mut c_char) -> T) { +unsafe fn check(expected: &str, f: |*mut c_char| -> T) { let mut x = [0i8, ..50]; f(&mut x[0] as *mut c_char); let res = CString::new(&x[0], false); diff --git a/src/test/run-pass/vec-matching-fold.rs b/src/test/run-pass/vec-matching-fold.rs index 22f1ccb8bbb05..75c48da8d812d 100644 --- a/src/test/run-pass/vec-matching-fold.rs +++ b/src/test/run-pass/vec-matching-fold.rs @@ -1,6 +1,6 @@ fn foldl(values: &[T], initial: U, - function: &fn(partial: U, element: &T) -> U) + function: |partial: U, element: &T| -> U) -> U { match values { [ref head, ..tail] => @@ -11,7 +11,7 @@ fn foldl(values: &[T], fn foldr(values: &[T], initial: U, - function: &fn(element: &T, partial: U) -> U) + function: |element: &T, partial: U| -> U) -> U { match values { [..head, ref tail] => From 9e610573ba285619c9a59d8c1468624b6428492c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Nov 2013 17:36:32 -0800 Subject: [PATCH 02/12] librustc: Remove remaining uses of `&fn()` in favor of `||`. --- doc/po/ja/rust.md.po | 2 +- doc/po/rust.md.pot | 2 +- doc/rust.md | 2 +- src/libextra/sort.rs | 2 +- src/librustc/front/config.rs | 2 +- src/librustc/metadata/decoder.rs | 14 +++---- src/librustc/metadata/encoder.rs | 8 ++-- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/tydecode.rs | 2 +- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/trans/base.rs | 3 +- src/librustc/middle/trans/glue.rs | 3 +- src/librustc/middle/trans/tvec.rs | 3 +- src/librustc/middle/ty_fold.rs | 13 +++---- .../middle/typeck/check/regionmanip.rs | 2 +- src/librustc/middle/typeck/infer/lattice.rs | 4 +- src/librustc/util/common.rs | 4 +- src/librustdoc/html/format.rs | 4 +- src/librustdoc/html/render.rs | 6 +-- src/librustpkg/installed_packages.rs | 2 +- src/librustpkg/package_source.rs | 2 +- src/librustpkg/path_util.rs | 2 +- src/librustpkg/sha1.rs | 8 ++-- src/librustpkg/util.rs | 4 +- src/librustpkg/workspace.rs | 5 ++- src/libstd/cleanup.rs | 2 +- src/libstd/condition.rs | 4 +- src/libstd/iter.rs | 38 +++++++++---------- src/libstd/rand/distributions/mod.rs | 14 ++++--- src/libstd/str.rs | 2 +- src/libstd/to_bytes.rs | 2 +- src/libstd/unstable/finally.rs | 4 +- src/libstd/vec.rs | 20 +++++----- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/ext/deriving/generic.rs | 11 +++--- src/libsyntax/ext/deriving/mod.rs | 22 +++++------ src/test/auxiliary/iss.rs | 2 +- src/test/bench/shootout-meteor.rs | 4 +- src/test/compile-fail/issue-4335.rs | 4 +- src/test/compile-fail/issue-4523.rs | 2 +- ...ased-on-type-no-recursive-stack-closure.rs | 2 +- src/test/compile-fail/regions-freevar.rs | 2 +- .../regions-infer-at-fn-not-param.rs | 6 +-- ...ns-infer-invariance-due-to-mutability-3.rs | 2 +- ...ns-infer-invariance-due-to-mutability-4.rs | 2 +- .../compile-fail/regions-infer-not-param.rs | 4 +- .../compile-fail/regions-steal-closure.rs | 4 +- src/test/run-fail/unwind-lambda.rs | 2 +- src/test/run-pass/const-fn-val.rs | 2 +- src/test/run-pass/const-vec-of-fns.rs | 2 +- src/test/run-pass/expr-block-fn.rs | 2 +- src/test/run-pass/expr-block-generic-box1.rs | 2 +- src/test/run-pass/expr-block-generic-box2.rs | 2 +- .../run-pass/expr-block-generic-unique1.rs | 2 +- .../run-pass/expr-block-generic-unique2.rs | 2 +- src/test/run-pass/expr-block-generic.rs | 2 +- src/test/run-pass/expr-if-generic-box1.rs | 2 +- src/test/run-pass/expr-if-generic-box2.rs | 2 +- src/test/run-pass/expr-if-generic.rs | 2 +- src/test/run-pass/expr-match-generic-box1.rs | 2 +- src/test/run-pass/expr-match-generic-box2.rs | 2 +- .../run-pass/expr-match-generic-unique1.rs | 2 +- .../run-pass/expr-match-generic-unique2.rs | 2 +- src/test/run-pass/fn-coerce-field.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/issue-1516.rs | 2 +- src/test/run-pass/issue-2185.rs | 2 +- src/test/run-pass/issue-3052.rs | 2 +- src/test/run-pass/last-use-in-cap-clause.rs | 4 +- src/test/run-pass/regions-copy-closure.rs | 4 +- src/test/run-pass/regions-dependent-autofn.rs | 4 +- src/test/run-pass/regions-static-closure.rs | 4 +- 72 files changed, 163 insertions(+), 153 deletions(-) diff --git a/doc/po/ja/rust.md.po b/doc/po/ja/rust.md.po index 24f07337df9ff..99392964e7aad 100644 --- a/doc/po/ja/rust.md.po +++ b/doc/po/ja/rust.md.po @@ -5383,7 +5383,7 @@ msgstr "" #. type: Plain text #: doc/rust.md:2849 msgid "" -"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = " +"type Binop<'self> = 'self |int,int| -> int; let bo: Binop = add; x = " "bo(5,7); ~~~~~~~~" msgstr "" diff --git a/doc/po/rust.md.pot b/doc/po/rust.md.pot index 80116dad4d33c..1914526cb921f 100644 --- a/doc/po/rust.md.pot +++ b/doc/po/rust.md.pot @@ -5370,7 +5370,7 @@ msgstr "" #. type: Plain text #: doc/rust.md:2849 msgid "" -"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = " +"type Binop<'self> = 'self |int,int| -> int; let bo: Binop = add; x = " "bo(5,7); ~~~~~~~~" msgstr "" diff --git a/doc/rust.md b/doc/rust.md index fe8d0a834e3e4..bfc18a8473bc3 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -3194,7 +3194,7 @@ fn add(x: int, y: int) -> int { let mut x = add(5,7); -type Binop<'self> = &'self fn(int,int) -> int; +type Binop<'self> = 'self |int,int| -> int; let bo: Binop = add; x = bo(5,7); ~~~~ diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index 60c4a75104b60..175eaa2a8db81 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -15,7 +15,7 @@ use std::cmp::{Eq, Ord}; use std::util::swap; use std::vec; -type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool; +type Le<'self, T> = 'self |v1: &T, v2: &T| -> bool; /** * Merge sort. Returns a new vector containing the sorted list. diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index 296e8578cbe7c..460f1ff1262ff 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -13,7 +13,7 @@ use syntax::fold::ast_fold; use syntax::{ast, fold, attr}; struct Context<'self> { - in_cfg: &'self fn(attrs: &[ast::Attribute]) -> bool, + in_cfg: 'self |attrs: &[ast::Attribute]| -> bool, } // Support conditional compilation by transforming the AST, stripping out diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index fbe3d7bbe9eea..dd70d29ec5b2d 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -74,7 +74,7 @@ fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) -> ret } -pub type GetCrateDataCb<'self> = &'self fn(ast::CrateNum) -> Cmd; +pub type GetCrateDataCb<'self> = 'self |ast::CrateNum| -> Cmd; pub fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option { fn eq_item(bytes: &[u8], item_id: int) -> bool { @@ -528,7 +528,7 @@ struct EachItemContext<'self> { cdata: Cmd, get_crate_data: GetCrateDataCb<'self>, path_builder: &'self mut ~str, - callback: &'self fn(&str, DefLike, ast::visibility) -> bool, + callback: 'self |&str, DefLike, ast::visibility| -> bool, } impl<'self> EachItemContext<'self> { @@ -901,11 +901,11 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ast_map::path { item_path(lookup_item(id, cdata.data)) } -pub type decode_inlined_item<'self> = &'self fn( - cdata: @cstore::crate_metadata, - tcx: ty::ctxt, - path: ast_map::path, - par_doc: ebml::Doc) -> Option; +pub type decode_inlined_item<'self> = 'self |cdata: @cstore::crate_metadata, + tcx: ty::ctxt, + path: ast_map::path, + par_doc: ebml::Doc| + -> Option; pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt, id: ast::NodeId, diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 340a4241da23b..c22f05d249cde 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -52,10 +52,10 @@ use std::cast; // used by astencode: type abbrev_map = @mut HashMap; -pub type encode_inlined_item<'self> = &'self fn(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - path: &[ast_map::path_elt], - ii: ast::inlined_item); +pub type encode_inlined_item<'self> = 'self |ecx: &EncodeContext, + ebml_w: &mut writer::Encoder, + path: &[ast_map::path_elt], + ii: ast::inlined_item|; pub struct EncodeParams<'self> { diag: @mut span_handler, diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index eccbe049e2b90..4a27450bb43d8 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -23,7 +23,7 @@ pub enum FileMatch { FileMatches, FileDoesntMatch } /// Functions with type `pick` take a parent directory as well as /// a file found in that directory. -pub type pick<'self> = &'self fn(path: &Path) -> FileMatch; +pub type pick<'self> = 'self |path: &Path| -> FileMatch; pub fn pick_file(file: Path, path: &Path) -> Option { if path.filename() == Some(file.as_vec()) { diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 281998b081146..27bca78b7b725 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -54,7 +54,7 @@ pub enum DefIdSource { RegionParameter, } type conv_did<'self> = - &'self fn(source: DefIdSource, ast::DefId) -> ast::DefId; + 'self |source: DefIdSource, ast::DefId| -> ast::DefId; pub struct PState<'self> { data: &'self [u8], diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 92913983d8659..27d1e887bd32f 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -477,7 +477,7 @@ fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::Pat) { } } -type enter_pat<'self> = &'self fn(@ast::Pat) -> Option<~[@ast::Pat]>; +type enter_pat<'self> = 'self |@ast::Pat| -> Option<~[@ast::Pat]>; fn enter_match<'r>(bcx: @mut Block, dm: DefMap, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0ece7c8c024de..ea9690ce40609 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -669,7 +669,8 @@ pub fn compare_scalar_values(cx: @mut Block, } } -pub type val_and_ty_fn<'self> = &'self fn(@mut Block, ValueRef, ty::t) -> @mut Block; +pub type val_and_ty_fn<'self> = 'self |@mut Block, ValueRef, ty::t| + -> @mut Block; pub fn load_inbounds(cx: @mut Block, p: ValueRef, idxs: &[uint]) -> ValueRef { return Load(cx, GEPi(cx, p, idxs)); diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 0993d3322f1e6..3eef1267429c7 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -642,7 +642,8 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { return inf; } -pub type glue_helper<'self> = &'self fn(@mut Block, ValueRef, ty::t) -> @mut Block; +pub type glue_helper<'self> = 'self |@mut Block, ValueRef, ty::t| + -> @mut Block; pub fn declare_generic_glue(ccx: &mut CrateContext, t: ty::t, llfnty: Type, name: &str) -> ValueRef { diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 93718fc1a2382..82615b1e119a0 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -539,7 +539,8 @@ pub fn get_base_and_len(bcx: @mut Block, llval: ValueRef, vec_ty: ty::t) -> (Val } } -pub type iter_vec_block<'self> = &'self fn(@mut Block, ValueRef, ty::t) -> @mut Block; +pub type iter_vec_block<'self> = 'self |@mut Block, ValueRef, ty::t| + -> @mut Block; pub fn iter_vec_loop(bcx: @mut Block, data_ptr: ValueRef, diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index dc4fca0176a5f..2f35121dc02ae 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -224,7 +224,7 @@ pub fn super_fold_trait_store(this: &mut T, pub struct BottomUpFolder<'self> { tcx: ty::ctxt, - fldop: &'self fn(ty::t) -> ty::t, + fldop: 'self |ty::t| -> ty::t, } impl<'self> TypeFolder for BottomUpFolder<'self> { @@ -241,14 +241,14 @@ impl<'self> TypeFolder for BottomUpFolder<'self> { pub struct RegionFolder<'self> { tcx: ty::ctxt, - fld_t: &'self fn(ty::t) -> ty::t, - fld_r: &'self fn(ty::Region) -> ty::Region, + fld_t: 'self |ty::t| -> ty::t, + fld_r: 'self |ty::Region| -> ty::Region, } impl<'self> RegionFolder<'self> { pub fn general(tcx: ty::ctxt, - fld_r: &'self fn(ty::Region) -> ty::Region, - fld_t: &'self fn(ty::t) -> ty::t) + fld_r: 'self |ty::Region| -> ty::Region, + fld_t: 'self |ty::t| -> ty::t) -> RegionFolder<'self> { RegionFolder { tcx: tcx, @@ -257,8 +257,7 @@ impl<'self> RegionFolder<'self> { } } - pub fn regions(tcx: ty::ctxt, - fld_r: &'self fn(ty::Region) -> ty::Region) + pub fn regions(tcx: ty::ctxt, fld_r: 'self |ty::Region| -> ty::Region) -> RegionFolder<'self> { fn noop(t: ty::t) -> ty::t { t } diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index ebdd4b5f48c2f..7bf5eacb3d5c4 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -88,7 +88,7 @@ pub fn relate_nested_regions(tcx: ty::ctxt, struct RegionRelator<'self> { tcx: ty::ctxt, stack: ~[ty::Region], - relate_op: &'self fn(ty::Region, ty::Region), + relate_op: 'self |ty::Region, ty::Region|, } // FIXME(#10151) -- Define more precisely when a region is diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 04bf5fda7258d..dbf11ab68bcae 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -52,7 +52,7 @@ pub trait LatticeValue { } pub type LatticeOp<'self, T> = - &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres; + 'self |cf: &CombineFields, a: &T, b: &T| -> cres; impl LatticeValue for ty::t { fn sub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures { @@ -407,7 +407,7 @@ pub fn super_lattice_tys(this: &L, } } -pub type LatticeDirOp<'self, T> = &'self fn(a: &T, b: &T) -> cres; +pub type LatticeDirOp<'self, T> = 'self |a: &T, b: &T| -> cres; #[deriving(Clone)] pub enum LatticeVarResult { diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index ffbea94c4774b..28fe067293b89 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -61,7 +61,7 @@ pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::Expr] { } struct LoopQueryVisitor<'self> { - p: &'self fn(&ast::Expr_) -> bool, + p: 'self |&ast::Expr_| -> bool, flag: bool, } @@ -89,7 +89,7 @@ pub fn loop_query(b: &ast::Block, p: |&ast::Expr_| -> bool) -> bool { } struct BlockQueryVisitor<'self> { - p: &'self fn(@ast::Expr) -> bool, + p: 'self |@ast::Expr| -> bool, flag: bool, } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index ee2aaee240ec8..b191eb37af1bc 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -148,8 +148,8 @@ fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool, } fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, - root: &fn(&render::Cache, &[~str]) -> Option<~str>, - info: &fn(&render::Cache) -> Option<(~[~str], &'static str)>) { + root: |&render::Cache, &[~str]| -> Option<~str>, + info: |&render::Cache| -> Option<(~[~str], &'static str)>) { // The generics will get written to both the title and link let mut generics = ~""; let last = path.segments.last(); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 96219479e104b..9f0a4cefc4c12 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -335,7 +335,7 @@ fn mkdir(path: &Path) { /// things like ".." to components which preserve the "top down" hierarchy of a /// static HTML tree. // FIXME (#9639): The closure should deal with &[u8] instead of &str -fn clean_srcpath(src: &[u8], f: &fn(&str)) { +fn clean_srcpath(src: &[u8], f: |&str|) { let p = Path::new(src); if p.as_vec() != bytes!(".") { for c in p.str_components().map(|x|x.unwrap()) { @@ -645,7 +645,7 @@ impl<'self> Cache { impl Context { /// Recurse in the directory structure and change the "root path" to make /// sure it always points to the top (relatively) - fn recurse(&mut self, s: ~str, f: &fn(&mut Context) -> T) -> T { + fn recurse(&mut self, s: ~str, f: |&mut Context| -> T) -> T { if s.len() == 0 { fail!("what {:?}", self); } @@ -768,7 +768,7 @@ impl Context { /// all sub-items which need to be rendered. /// /// The rendering driver uses this closure to queue up more work. - fn item(&mut self, item: clean::Item, f: &fn(&mut Context, clean::Item)) { + fn item(&mut self, item: clean::Item, f: |&mut Context, clean::Item|) { fn render(w: io::File, cx: &mut Context, it: &clean::Item, pushname: bool) { // A little unfortunate that this is done like this, but it sure diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index 855f6bbc3e50f..3eed6314a0333 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -16,7 +16,7 @@ use std::os; use std::io; use std::io::fs; -pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool { +pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool { let workspaces = rust_path(); for p in workspaces.iter() { let binfiles = do io::ignore_io_error { fs::readdir(&p.join("bin")) }; diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 7e1430792ffbd..4f48dab811f27 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -348,7 +348,7 @@ impl PkgSrc { self.find_crates_with_filter(|_| true); } - pub fn find_crates_with_filter(&mut self, filter: &fn(&str) -> bool) { + pub fn find_crates_with_filter(&mut self, filter: |&str| -> bool) { use conditions::missing_pkg_files::cond; let prefix = self.start_dir.components().len(); diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index bce41e5a49fe0..adf86d2cf9d75 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -63,7 +63,7 @@ pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool { pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, // Returns the directory it was actually found in - workspace_to_src_dir: &fn(&Path) -> Path) -> Option { + workspace_to_src_dir: |&Path| -> Path) -> Option { if !workspace.is_dir() { return None; } diff --git a/src/librustpkg/sha1.rs b/src/librustpkg/sha1.rs index d955fd1aa97d0..db31f603d6ee0 100644 --- a/src/librustpkg/sha1.rs +++ b/src/librustpkg/sha1.rs @@ -94,7 +94,7 @@ fn add_bytes_to_bits(bits: T, bytes: T) -> T { trait FixedBuffer { /// Input a vector of bytes. If the buffer becomes full, process it with the provided /// function and then clear the buffer. - fn input(&mut self, input: &[u8], func: &fn(&[u8])); + fn input(&mut self, input: &[u8], func: |&[u8]|); /// Reset the buffer. fn reset(&mut self); @@ -137,7 +137,7 @@ impl FixedBuffer64 { } impl FixedBuffer for FixedBuffer64 { - fn input(&mut self, input: &[u8], func: &fn(&[u8])) { + fn input(&mut self, input: &[u8], func: |&[u8]|) { let mut i = 0; let size = 64; @@ -217,11 +217,11 @@ trait StandardPadding { /// and is guaranteed to have exactly rem remaining bytes when it returns. If there are not at /// least rem bytes available, the buffer will be zero padded, processed, cleared, and then /// filled with zeros again until only rem bytes are remaining. - fn standard_padding(&mut self, rem: uint, func: &fn(&[u8])); + fn standard_padding(&mut self, rem: uint, func: |&[u8]|); } impl StandardPadding for T { - fn standard_padding(&mut self, rem: uint, func: &fn(&[u8])) { + fn standard_padding(&mut self, rem: uint, func: |&[u8]|) { let size = self.size(); self.next(1)[0] = 128; diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 4f3d431543b7d..befb6aaa21809 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -425,7 +425,7 @@ struct ViewItemVisitor<'self> { sess: session::Session, exec: &'self mut workcache::Exec, c: &'self ast::Crate, - save: &'self fn(Path), + save: 'self |Path|, deps: &'self mut DepMap } @@ -587,7 +587,7 @@ pub fn find_and_install_dependencies(context: &BuildContext, exec: &mut workcache::Exec, c: &ast::Crate, deps: &mut DepMap, - save: &fn(Path)) { + save: |Path|) { debug!("In find_and_install_dependencies..."); let mut visitor = ViewItemVisitor { context: context, diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index e65f3ce5bb6ab..22d673333e954 100644 --- a/src/librustpkg/workspace.rs +++ b/src/librustpkg/workspace.rs @@ -18,7 +18,10 @@ use path_util::rust_path; use util::option_to_vec; use package_id::PkgId; -pub fn each_pkg_parent_workspace(cx: &Context, pkgid: &PkgId, action: &fn(&Path) -> bool) -> bool { +pub fn each_pkg_parent_workspace(cx: &Context, + pkgid: &PkgId, + action: |&Path| -> bool) + -> bool { // Using the RUST_PATH, find workspaces that contain // this package ID let workspaces = pkg_parent_workspaces(cx, pkgid); diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index a1f8509786562..2f7b27b55e321 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -15,7 +15,7 @@ use ptr; use unstable::intrinsics::TyDesc; use unstable::raw; -type DropGlue<'self> = &'self fn(**TyDesc, *c_void); +type DropGlue<'self> = 'self |**TyDesc, *c_void|; /* * Box annihilation diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 56d5a8594012f..03994043dcf0c 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -104,7 +104,7 @@ impl Condition { /// // use `trap`'s inside method to register the handler and then run a /// // block of code with the handler registered /// ``` - pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> { + pub fn trap<'a>(&'a self, h: 'a |T| -> U) -> Trap<'a, T, U> { let h: Closure = unsafe { ::cast::transmute(h) }; let prev = local_data::get(self.key, |k| k.map(|x| *x)); let h = @Handler { handle: h, prev: prev }; @@ -181,7 +181,7 @@ impl<'self, T, U> Trap<'self, T, U> { /// }; /// assert_eq!(result, 7); /// ``` - pub fn inside(&self, inner: &'self fn() -> V) -> V { + pub fn inside(&self, inner: 'self || -> V) -> V { let _g = Guard { cond: self.cond }; debug!("Trap: pushing handler to TLS"); local_data::set(self.cond.key, self.handler); diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index f736b10cc4fc5..b1958bde60d2a 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -156,7 +156,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn map<'r, B>(self, f: &'r fn(A) -> B) -> Map<'r, A, B, Self> { + fn map<'r, B>(self, f: 'r |A| -> B) -> Map<'r, A, B, Self> { Map{iter: self, f: f} } @@ -173,7 +173,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> Filter<'r, A, Self> { + fn filter<'r>(self, predicate: 'r |&A| -> bool) -> Filter<'r, A, Self> { Filter{iter: self, predicate: predicate} } @@ -190,7 +190,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn filter_map<'r, B>(self, f: &'r fn(A) -> Option) -> FilterMap<'r, A, B, Self> { + fn filter_map<'r, B>(self, f: 'r |A| -> Option) -> FilterMap<'r, A, B, Self> { FilterMap { iter: self, f: f } } @@ -249,7 +249,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhile<'r, A, Self> { + fn skip_while<'r>(self, predicate: 'r |&A| -> bool) -> SkipWhile<'r, A, Self> { SkipWhile{iter: self, flag: false, predicate: predicate} } @@ -267,7 +267,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhile<'r, A, Self> { + fn take_while<'r>(self, predicate: 'r |&A| -> bool) -> TakeWhile<'r, A, Self> { TakeWhile{iter: self, flag: false, predicate: predicate} } @@ -327,7 +327,7 @@ pub trait Iterator { /// assert!(it.next().is_none()); /// ``` #[inline] - fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option) + fn scan<'r, St, B>(self, initial_state: St, f: 'r |&mut St, A| -> Option) -> Scan<'r, A, B, Self, St> { Scan{iter: self, f: f, state: initial_state} } @@ -349,7 +349,7 @@ pub trait Iterator { /// } /// ``` #[inline] - fn flat_map<'r, B, U: Iterator>(self, f: &'r fn(A) -> U) + fn flat_map<'r, B, U: Iterator>(self, f: 'r |A| -> U) -> FlatMap<'r, A, Self, U> { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -401,7 +401,7 @@ pub trait Iterator { ///println(sum.to_str()); /// ``` #[inline] - fn inspect<'r>(self, f: &'r fn(&A)) -> Inspect<'r, A, Self> { + fn inspect<'r>(self, f: 'r |&A|) -> Inspect<'r, A, Self> { Inspect{iter: self, f: f} } @@ -1123,7 +1123,7 @@ RandomAccessIterator<(A, B)> for Zip { /// An iterator which maps the values of `iter` with `f` pub struct Map<'self, A, B, T> { priv iter: T, - priv f: &'self fn(A) -> B + priv f: 'self |A| -> B } impl<'self, A, B, T> Map<'self, A, B, T> { @@ -1172,7 +1172,7 @@ impl<'self, A, B, T: RandomAccessIterator> RandomAccessIterator for Map<'s /// An iterator which filters the elements of `iter` with `predicate` pub struct Filter<'self, A, T> { priv iter: T, - priv predicate: &'self fn(&A) -> bool + priv predicate: 'self |&A| -> bool } impl<'self, A, T: Iterator> Iterator for Filter<'self, A, T> { @@ -1216,7 +1216,7 @@ impl<'self, A, T: DoubleEndedIterator> DoubleEndedIterator for Filter<'sel /// An iterator which uses `f` to both filter and map elements from `iter` pub struct FilterMap<'self, A, B, T> { priv iter: T, - priv f: &'self fn(A) -> Option + priv f: 'self |A| -> Option } impl<'self, A, B, T: Iterator> Iterator for FilterMap<'self, A, B, T> { @@ -1359,7 +1359,7 @@ impl<'self, A, T: Iterator> Peekable { pub struct SkipWhile<'self, A, T> { priv iter: T, priv flag: bool, - priv predicate: &'self fn(&A) -> bool + priv predicate: 'self |&A| -> bool } impl<'self, A, T: Iterator> Iterator for SkipWhile<'self, A, T> { @@ -1397,7 +1397,7 @@ impl<'self, A, T: Iterator> Iterator for SkipWhile<'self, A, T> { pub struct TakeWhile<'self, A, T> { priv iter: T, priv flag: bool, - priv predicate: &'self fn(&A) -> bool + priv predicate: 'self |&A| -> bool } impl<'self, A, T: Iterator> Iterator for TakeWhile<'self, A, T> { @@ -1544,7 +1544,7 @@ impl> RandomAccessIterator for Take { /// An iterator to maintain state while iterating another iterator pub struct Scan<'self, A, B, T, St> { priv iter: T, - priv f: &'self fn(&mut St, A) -> Option, + priv f: 'self |&mut St, A| -> Option, /// The current internal state to be passed to the closure next. state: St @@ -1568,7 +1568,7 @@ impl<'self, A, B, T: Iterator, St> Iterator for Scan<'self, A, B, T, St> { /// pub struct FlatMap<'self, A, T, U> { priv iter: T, - priv f: &'self fn(A) -> U, + priv f: 'self |A| -> U, priv frontiter: Option, priv backiter: Option, } @@ -1699,7 +1699,7 @@ impl Fuse { /// element before yielding it. pub struct Inspect<'self, A, T> { priv iter: T, - priv f: &'self fn(&A) + priv f: 'self |&A| } impl<'self, A, T> Inspect<'self, A, T> { @@ -1751,7 +1751,7 @@ for Inspect<'self, A, T> { /// An iterator which just modifies the contained state throughout iteration. pub struct Unfold<'self, A, St> { - priv f: &'self fn(&mut St) -> Option, + priv f: 'self |&mut St| -> Option, /// Internal state that will be yielded on the next iteration state: St } @@ -1760,8 +1760,8 @@ impl<'self, A, St> Unfold<'self, A, St> { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the iterator #[inline] - pub fn new<'a>(initial_state: St, f: &'a fn(&mut St) -> Option) - -> Unfold<'a, A, St> { + pub fn new<'a>(initial_state: St, f: 'a |&mut St| -> Option) + -> Unfold<'a, A, St> { Unfold { f: f, state: initial_state diff --git a/src/libstd/rand/distributions/mod.rs b/src/libstd/rand/distributions/mod.rs index dfdb08b7550b9..247a7824a4465 100644 --- a/src/libstd/rand/distributions/mod.rs +++ b/src/libstd/rand/distributions/mod.rs @@ -205,12 +205,14 @@ mod ziggurat_tables; // the perf improvement (25-50%) is definitely worth the extra code // size from force-inlining. #[inline(always)] -fn ziggurat(rng: &mut R, - symmetric: bool, - X: ziggurat_tables::ZigTable, - F: ziggurat_tables::ZigTable, - pdf: &'static fn(f64) -> f64, - zero_case: &'static fn(&mut R, f64) -> f64) -> f64 { +fn ziggurat( + rng: &mut R, + symmetric: bool, + X: ziggurat_tables::ZigTable, + F: ziggurat_tables::ZigTable, + pdf: 'static |f64| -> f64, + zero_case: 'static |&mut R, f64| -> f64) + -> f64 { static SCALE: f64 = (1u64 << 53) as f64; loop { // reimplement the f64 generation as an optimisation suggested diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3582782fc5ecd..11f552e73ae7e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -322,7 +322,7 @@ impl CharEq for char { fn only_ascii(&self) -> bool { (*self as uint) < 128 } } -impl<'self> CharEq for &'self fn(char) -> bool { +impl<'self> CharEq for 'self |char| -> bool { #[inline] fn matches(&self, c: char) -> bool { (*self)(c) } diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 28b79bdd320b4..ded7cd8df072b 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -22,7 +22,7 @@ use rc::Rc; use str::{Str, StrSlice}; use vec::{Vector, ImmutableVector}; -pub type Cb<'self> = &'self fn(buf: &[u8]) -> bool; +pub type Cb<'self> = 'self |buf: &[u8]| -> bool; /// /// A trait to implement in order to make a type hashable; diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index 58504832b2d69..226ce9ef6f2e6 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -44,7 +44,7 @@ macro_rules! finally_fn { } } -impl<'self,T> Finally for &'self fn() -> T { +impl<'self,T> Finally for 'self || -> T { fn finally(&self, dtor: ||) -> T { let _d = Finallyalizer { dtor: dtor @@ -57,7 +57,7 @@ impl<'self,T> Finally for &'self fn() -> T { finally_fn!(extern "Rust" fn() -> T) struct Finallyalizer<'self> { - dtor: &'self fn() + dtor: 'self || } #[unsafe_destructor] diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 5fbf03c3cbb94..0b08f9d00faf9 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -222,7 +222,7 @@ pub fn build(size: Option, builder: |push: |v: A||) -> ~[A] { pub struct SplitIterator<'self, T> { priv v: &'self [T], priv n: uint, - priv pred: &'self fn(t: &T) -> bool, + priv pred: 'self |t: &T| -> bool, priv finished: bool } @@ -271,7 +271,7 @@ impl<'self, T> Iterator<&'self [T]> for SplitIterator<'self, T> { pub struct RSplitIterator<'self, T> { priv v: &'self [T], priv n: uint, - priv pred: &'self fn(t: &T) -> bool, + priv pred: 'self |t: &T| -> bool, priv finished: bool } @@ -859,20 +859,20 @@ pub trait ImmutableVector<'self, T> { fn rev_iter(self) -> RevIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. - fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; + fn split(self, pred: 'self |&T| -> bool) -> SplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`, limited to splitting /// at most `n` times. - fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>; + fn splitn(self, n: uint, pred: |&T| -> bool) -> SplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. This starts at the /// end of the vector and works backwards. - fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; + fn rsplit(self, pred: |&T| -> bool) -> RSplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred` limited to splitting /// at most `n` times. This starts at the end of the vector and /// works backwards. - fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>; + fn rsplitn(self, n: uint, pred: 'self |&T| -> bool) -> RSplitIterator<'self, T>; /** * Returns an iterator over all contiguous windows of length @@ -1024,12 +1024,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } #[inline] - fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { + fn split(self, pred: 'self |&T| -> bool) -> SplitIterator<'self, T> { self.splitn(uint::max_value, pred) } #[inline] - fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> { + fn splitn(self, n: uint, pred: 'self |&T| -> bool) -> SplitIterator<'self, T> { SplitIterator { v: self, n: n, @@ -1039,12 +1039,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } #[inline] - fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { + fn rsplit(self, pred: 'self |&T| -> bool) -> RSplitIterator<'self, T> { self.rsplitn(uint::max_value, pred) } #[inline] - fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> { + fn rsplitn(self, n: uint, pred: 'self |&T| -> bool) -> RSplitIterator<'self, T> { RSplitIterator { v: self, n: n, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 16846823e0c6f..c14375604b1e2 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -669,7 +669,7 @@ pub trait EachViewItem { } struct EachViewItemData<'self> { - callback: &'self fn(&ast::view_item) -> bool, + callback: 'self |&ast::view_item| -> bool, } impl<'self> Visitor<()> for EachViewItemData<'self> { diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 23dc38fdc31e5..2f6cfeb24da1f 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -294,7 +294,7 @@ Combine the values of all the fields together. The last argument is all the fields of all the structures, see above for details. */ pub type CombineSubstructureFunc<'self> = - &'self fn(@ExtCtxt, Span, &Substructure) -> @Expr; + 'self |@ExtCtxt, Span, &Substructure| -> @Expr; /** Deal with non-matching enum variants, the arguments are a list @@ -302,10 +302,11 @@ representing each variant: (variant index, ast::variant instance, [variant fields]), and a list of the nonself args of the type */ pub type EnumNonMatchFunc<'self> = - &'self fn(@ExtCtxt, Span, - &[(uint, ast::variant, - ~[(Span, Option, @Expr)])], - &[@Expr]) -> @Expr; + 'self |@ExtCtxt, + Span, + &[(uint, ast::variant, ~[(Span, Option, @Expr)])], + &[@Expr]| + -> @Expr; impl<'self> TraitDef<'self> { diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 3e65f7bdefbc5..8729382141b8a 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -46,17 +46,17 @@ pub mod totalord; pub mod generic; -pub type ExpandDerivingStructDefFn<'self> = &'self fn(@ExtCtxt, - Span, - x: &struct_def, - Ident, - y: &Generics) - -> @item; -pub type ExpandDerivingEnumDefFn<'self> = &'self fn(@ExtCtxt, - Span, - x: &enum_def, - Ident, - y: &Generics) +pub type ExpandDerivingStructDefFn<'self> = 'self |@ExtCtxt, + Span, + x: &struct_def, + Ident, + y: &Generics| + -> @item; +pub type ExpandDerivingEnumDefFn<'self> = 'self |@ExtCtxt, + Span, + x: &enum_def, + Ident, + y: &Generics| -> @item; pub fn expand_meta_deriving(cx: @ExtCtxt, diff --git a/src/test/auxiliary/iss.rs b/src/test/auxiliary/iss.rs index a3ead83321f64..3855a348f60c0 100644 --- a/src/test/auxiliary/iss.rs +++ b/src/test/auxiliary/iss.rs @@ -13,7 +13,7 @@ // part of issue-6919.rs struct C<'self> { - k: &'self fn(), + k: 'self ||, } fn no_op() { } diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index e3fe631068c1f..7621d5d7b087f 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -14,11 +14,11 @@ // returns an infinite iterator of repeated applications of f to x, // i.e. [x, f(x), f(f(x)), ...], as haskell iterate function. -fn iterate<'a, T>(x: T, f: &'a fn(&T) -> T) -> Iterate<'a, T> { +fn iterate<'a, T>(x: T, f: 'a |&T| -> T) -> Iterate<'a, T> { Iterate {f: f, next: x} } struct Iterate<'self, T> { - priv f: &'self fn(&T) -> T, + priv f: &'self |&T| -> T, priv next: T } impl<'self, T> Iterator for Iterate<'self, T> { diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index 032b2564f4fb2..4cfa543a93fbe 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -10,7 +10,9 @@ fn id(t: T) -> T { t } -fn f<'r, T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR cannot infer an appropriate lifetime +fn f<'r, T>(v: &'r T) -> 'r || -> T { + id(|| *v) //~ ERROR cannot infer an appropriate lifetime +} fn main() { let v = &5; diff --git a/src/test/compile-fail/issue-4523.rs b/src/test/compile-fail/issue-4523.rs index 332db60c836fc..952a528b427ba 100644 --- a/src/test/compile-fail/issue-4523.rs +++ b/src/test/compile-fail/issue-4523.rs @@ -10,7 +10,7 @@ fn foopy() {} -static f: &'static fn() = foopy; //~ ERROR found extern fn +static f: 'static || = foopy; //~ ERROR found extern fn fn main () { f(); diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index db8effb1de3df..bf7383f9c72b8 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -16,7 +16,7 @@ struct R<'self> { // This struct is needed to create the // otherwise infinite type of a fn that // accepts itself as argument: - c: &'self fn(&R, bool) + c: 'self |&R, bool| } fn innocent_looking_victim() { diff --git a/src/test/compile-fail/regions-freevar.rs b/src/test/compile-fail/regions-freevar.rs index 251be91235975..7e5abe8e2f7e4 100644 --- a/src/test/compile-fail/regions-freevar.rs +++ b/src/test/compile-fail/regions-freevar.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn wants_static_fn(_x: &'static fn()) {} +fn wants_static_fn(_x: 'static ||) {} fn main() { let i = 3; diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs index 3ddae976ce317..6347fa97c4dd5 100644 --- a/src/test/compile-fail/regions-infer-at-fn-not-param.rs +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -9,15 +9,15 @@ // except according to those terms. struct parameterized1<'self> { - g: &'self fn() + g: 'self || } struct not_parameterized1 { - g: &'static fn() + g: 'static || } struct not_parameterized2 { - g: &'static fn() + g: 'static || } fn take1(p: parameterized1) -> parameterized1 { p } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs index 775164453e0d8..c7364a60bdf91 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs @@ -11,7 +11,7 @@ #[feature(managed_boxes)]; struct invariant<'self> { - f: &'static fn(x: @mut &'self int) + f: 'static |x: @mut &'self int| } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs index 44856d9e531e6..8070d1f1dce72 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs @@ -11,7 +11,7 @@ #[feature(managed_boxes)]; struct invariant<'self> { - f: &'static fn() -> @mut &'self int + f: 'static || -> @mut &'self int } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index 47c1f7a5757de..92159489ae707 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -14,12 +14,12 @@ struct direct<'self> { struct indirect1 { // Here the lifetime parameter of direct is bound by the fn() - g: &'static fn(direct) + g: 'static |direct| } struct indirect2<'self> { // But here it is set to 'self - g: &'static fn(direct<'self>) + g: 'static |direct<'self>| } fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types diff --git a/src/test/compile-fail/regions-steal-closure.rs b/src/test/compile-fail/regions-steal-closure.rs index be034eda67dcf..292e282dd073e 100644 --- a/src/test/compile-fail/regions-steal-closure.rs +++ b/src/test/compile-fail/regions-steal-closure.rs @@ -9,10 +9,10 @@ // except according to those terms. struct closure_box<'self> { - cl: &'self fn() + cl: 'self || } -fn box_it<'r>(x: &'r fn()) -> closure_box<'r> { +fn box_it<'r>(x: 'r ||) -> closure_box<'r> { closure_box {cl: x} } diff --git a/src/test/run-fail/unwind-lambda.rs b/src/test/run-fail/unwind-lambda.rs index bd415e9eac3e7..ee570fa2e950d 100644 --- a/src/test/run-fail/unwind-lambda.rs +++ b/src/test/run-fail/unwind-lambda.rs @@ -16,7 +16,7 @@ fn main() { let cheese = ~"roquefort"; let carrots = @~"crunchy"; - let result: &'static fn(@~str, |~str|) = (|tasties, macerate| { + let result: 'static |@~str, |~str|| = (|tasties, macerate| { macerate((*tasties).clone()); }); result(carrots, |food| { diff --git a/src/test/run-pass/const-fn-val.rs b/src/test/run-pass/const-fn-val.rs index dfcfb30f77ffb..126d53621dd7b 100644 --- a/src/test/run-pass/const-fn-val.rs +++ b/src/test/run-pass/const-fn-val.rs @@ -12,7 +12,7 @@ fn foo() -> int { return 0xca7f000d; } -struct Bar<'self> { f: &'self fn() -> int } +struct Bar<'self> { f: 'self || -> int } static b : Bar<'static> = Bar { f: foo }; diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 6117ea962afac..593d0e3125d67 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -20,7 +20,7 @@ fn f() { } static bare_fns: &'static [extern fn()] = &[f, f]; -struct S<'self>(&'self fn()); +struct S<'self>('self ||); static closures: &'static [S<'static>] = &[S(f), S(f)]; pub fn main() { diff --git a/src/test/run-pass/expr-block-fn.rs b/src/test/run-pass/expr-block-fn.rs index 63e5c7688d345..e18509252235d 100644 --- a/src/test/run-pass/expr-block-fn.rs +++ b/src/test/run-pass/expr-block-fn.rs @@ -11,7 +11,7 @@ fn test_fn() { - type t = &'static fn() -> int; + type t = 'static || -> int; fn ten() -> int { return 10; } let rs: t = { ten }; assert!((rs() == 10)); diff --git a/src/test/run-pass/expr-block-generic-box1.rs b/src/test/run-pass/expr-block-generic-box1.rs index 04c96bb2b9804..f081d13a5b0b1 100644 --- a/src/test/run-pass/expr-block-generic-box1.rs +++ b/src/test/run-pass/expr-block-generic-box1.rs @@ -10,7 +10,7 @@ #[feature(managed_boxes)]; -type compare = &'static fn(@T, @T) -> bool; +type compare = 'static |@T, @T| -> bool; fn test_generic(expected: @T, eq: compare) { let actual: @T = { expected }; diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 562c3c1e52303..04721c6bd94ec 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -12,7 +12,7 @@ // xfail-fast -type compare<'self, T> = &'self fn(T, T) -> bool; +type compare<'self, T> = 'self |T, T| -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index 159c2bfb8eff4..f1df0e167b9a1 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -10,7 +10,7 @@ -type compare<'self, T> = &'self fn(~T, ~T) -> bool; +type compare<'self, T> = 'self |~T, ~T| -> bool; fn test_generic(expected: ~T, eq: compare) { let actual: ~T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index ff811a9f458f3..b666a2f6760e6 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -10,7 +10,7 @@ // xfail-fast -type compare<'self, T> = &'self fn(T, T) -> bool; +type compare<'self, T> = 'self |T, T| -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index 800f22169d3d4..bc8c4c8983d96 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -12,7 +12,7 @@ // xfail-fast // Tests for standalone blocks as expressions with dynamic type sizes -type compare<'self, T> = &'self fn(T, T) -> bool; +type compare<'self, T> = 'self |T, T| -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-if-generic-box1.rs b/src/test/run-pass/expr-if-generic-box1.rs index e6039d0601e38..cba01fbd8dd81 100644 --- a/src/test/run-pass/expr-if-generic-box1.rs +++ b/src/test/run-pass/expr-if-generic-box1.rs @@ -10,7 +10,7 @@ #[feature(managed_boxes)]; -type compare = &'static fn(@T, @T) -> bool; +type compare = 'static |@T, @T| -> bool; fn test_generic(expected: @T, not_expected: @T, eq: compare) { let actual: @T = if true { expected } else { not_expected }; diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index b8d872742ab61..5ef97832221bf 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -12,7 +12,7 @@ // xfail-fast -type compare = &'static fn(T, T) -> bool; +type compare = 'static |T, T| -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected.clone() } else { not_expected }; diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index 8e6e3f7ddda85..bd1a550e205fc 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -11,7 +11,7 @@ // xfail-fast // Tests for if as expressions with dynamic type sizes -type compare = &'static fn(T, T) -> bool; +type compare = 'static |T, T| -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected.clone() } else { not_expected }; diff --git a/src/test/run-pass/expr-match-generic-box1.rs b/src/test/run-pass/expr-match-generic-box1.rs index 9220b0d697a8e..82e80e7da7dc3 100644 --- a/src/test/run-pass/expr-match-generic-box1.rs +++ b/src/test/run-pass/expr-match-generic-box1.rs @@ -10,7 +10,7 @@ #[feature(managed_boxes)]; -type compare = &'static fn(@T, @T) -> bool; +type compare = 'static |@T, @T| -> bool; fn test_generic(expected: @T, eq: compare) { let actual: @T = match true { true => { expected }, _ => fail!() }; diff --git a/src/test/run-pass/expr-match-generic-box2.rs b/src/test/run-pass/expr-match-generic-box2.rs index 430bd0f52c313..8fed749e3022e 100644 --- a/src/test/run-pass/expr-match-generic-box2.rs +++ b/src/test/run-pass/expr-match-generic-box2.rs @@ -12,7 +12,7 @@ // xfail-fast -type compare = &'static fn(T, T) -> bool; +type compare = 'static |T, T| -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") }; diff --git a/src/test/run-pass/expr-match-generic-unique1.rs b/src/test/run-pass/expr-match-generic-unique1.rs index b4bc7d3bef697..af9022ed3222c 100644 --- a/src/test/run-pass/expr-match-generic-unique1.rs +++ b/src/test/run-pass/expr-match-generic-unique1.rs @@ -10,7 +10,7 @@ -type compare = &'static fn(~T, ~T) -> bool; +type compare = 'static |~T, ~T| -> bool; fn test_generic(expected: ~T, eq: compare) { let actual: ~T = match true { diff --git a/src/test/run-pass/expr-match-generic-unique2.rs b/src/test/run-pass/expr-match-generic-unique2.rs index 8eb5861f71ee7..2bd0f18ba0a74 100644 --- a/src/test/run-pass/expr-match-generic-unique2.rs +++ b/src/test/run-pass/expr-match-generic-unique2.rs @@ -10,7 +10,7 @@ // xfail-fast -type compare<'self, T> = &'self fn(T, T) -> bool; +type compare<'self, T> = 'self |T, T| -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { diff --git a/src/test/run-pass/fn-coerce-field.rs b/src/test/run-pass/fn-coerce-field.rs index ae2e353f913ba..809005258b51a 100644 --- a/src/test/run-pass/fn-coerce-field.rs +++ b/src/test/run-pass/fn-coerce-field.rs @@ -9,7 +9,7 @@ // except according to those terms. struct r<'self> { - field: &'self fn() + field: 'self || } pub fn main() { diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 73595fd782c47..1716f882dd86e 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -24,7 +24,7 @@ mod map_reduce { use std::str; use std::task; - pub type putter<'self> = &'self fn(~str, ~str); + pub type putter<'self> = 'self |~str, ~str|; pub type mapper = extern fn(~str, putter); diff --git a/src/test/run-pass/issue-1516.rs b/src/test/run-pass/issue-1516.rs index 4b73d83595e64..f3ffed7dc7bc3 100644 --- a/src/test/run-pass/issue-1516.rs +++ b/src/test/run-pass/issue-1516.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let early_error: &'static fn(&str) -> ! = |_msg| { fail!() }; + let early_error: 'static |&str| -> ! = |_msg| { fail!() }; } diff --git a/src/test/run-pass/issue-2185.rs b/src/test/run-pass/issue-2185.rs index afe7656b7a343..9ebeec092cf15 100644 --- a/src/test/run-pass/issue-2185.rs +++ b/src/test/run-pass/issue-2185.rs @@ -18,7 +18,7 @@ // // Running /usr/local/bin/rustc: // issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait -// issue-2185.rs:24 impl iterable for &'static fn(|uint|) { +// issue-2185.rs:24 impl iterable for 'static ||uint|| { // issue-2185.rs:25 fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) } // issue-2185.rs:26 } // issue-2185.rs:20:0: 22:1 note: note conflicting implementation here diff --git a/src/test/run-pass/issue-3052.rs b/src/test/run-pass/issue-3052.rs index cb1ffc3890898..8179d85e601f3 100644 --- a/src/test/run-pass/issue-3052.rs +++ b/src/test/run-pass/issue-3052.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type Connection = &'static fn(~[u8]); +type Connection = 'static |~[u8]|; fn f() -> Option { let mock_connection: Connection = |_| {}; diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index d014a3cf1a15c..b72ef59075ce2 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -12,10 +12,10 @@ struct A { a: ~int } -fn foo() -> &'static fn() -> int { +fn foo() -> 'static || -> int { let k = ~22; let _u = A {a: k.clone()}; - let result: &'static fn() -> int = || 22; + let result: 'static || -> int = || 22; result } diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index 0b962731ecf3c..19fd120641997 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -9,10 +9,10 @@ // except according to those terms. struct closure_box<'self> { - cl: &'self fn(), + cl: 'self ||, } -fn box_it<'r>(x: &'r fn()) -> closure_box<'r> { +fn box_it<'r>(x: 'r ||) -> closure_box<'r> { closure_box {cl: x} } diff --git a/src/test/run-pass/regions-dependent-autofn.rs b/src/test/run-pass/regions-dependent-autofn.rs index bce2159cc7b9f..b50930dd2947b 100644 --- a/src/test/run-pass/regions-dependent-autofn.rs +++ b/src/test/run-pass/regions-dependent-autofn.rs @@ -11,9 +11,9 @@ // Test lifetimes are linked properly when we autoslice a vector. // Issue #3148. -fn subslice<'r>(v: &'r fn()) -> &'r fn() { v } +fn subslice<'r>(v: 'r ||) -> 'r || { v } -fn both<'r>(v: &'r fn()) -> &'r fn() { +fn both<'r>(v: 'r ||) -> 'r || { subslice(subslice(v)) } diff --git a/src/test/run-pass/regions-static-closure.rs b/src/test/run-pass/regions-static-closure.rs index a2eb459ce206e..941f2c5edfda0 100644 --- a/src/test/run-pass/regions-static-closure.rs +++ b/src/test/run-pass/regions-static-closure.rs @@ -9,10 +9,10 @@ // except according to those terms. struct closure_box<'self> { - cl: &'self fn(), + cl: 'self ||, } -fn box_it<'r>(x: &'r fn()) -> closure_box<'r> { +fn box_it<'r>(x: 'r ||) -> closure_box<'r> { closure_box {cl: x} } From 6801bc8f552ce740deb60212903ba43de197689c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Nov 2013 18:15:10 -0800 Subject: [PATCH 03/12] libsyntax: Remove the old-style borrowed closure type syntax from the language. --- src/compiletest/compiletest.rs | 4 ++-- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 9 ++++++--- src/librustuv/addrinfo.rs | 2 +- src/librustuv/file.rs | 7 +++---- src/librustuv/lib.rs | 2 +- src/librustuv/net.rs | 2 +- src/librustuv/process.rs | 4 ++-- src/librustuv/uvio.rs | 2 +- src/libsyntax/parse/obsolete.rs | 6 ++++++ src/libsyntax/parse/parser.rs | 3 ++- .../closure-bounds-cant-promote-superkind-in-struct.rs | 4 ++-- src/test/compile-fail/once-cant-call-twice-on-stack.rs | 2 +- src/test/compile-fail/once-fn-subtyping.rs | 4 ++-- src/test/run-pass/once-move-out-on-stack.rs | 2 +- 15 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 15bddfc80221c..9c8fdafe9ad10 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -301,8 +301,8 @@ pub fn is_test(config: &config, testfile: &Path) -> bool { return valid; } -pub fn make_test(config: &config, testfile: &Path, - f: &fn()->test::TestFn) -> test::TestDescAndFn { +pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn) + -> test::TestDescAndFn { test::TestDescAndFn { desc: test::TestDesc { name: make_test_name(config, testfile), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 2c01907d7fae1..f722f873d5e67 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -102,7 +102,7 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool { !val } -fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool { +fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool { use std::io::buffered::BufferedReader; use std::io::File; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 035f0b83406df..7104a506fccc5 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -730,9 +730,12 @@ fn compose_and_run(config: &config, testfile: &Path, prog, args, procenv, input); } -fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str], - xform: &fn(&config, (&Path)) -> Path, - testfile: &Path) -> ProcArgs { +fn make_compile_args(config: &config, + props: &TestProps, + extras: ~[~str], + xform: |&config, &Path| -> Path, + testfile: &Path) + -> ProcArgs { let xform_file = xform(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths let mut args = ~[testfile.as_str().unwrap().to_owned(), diff --git a/src/librustuv/addrinfo.rs b/src/librustuv/addrinfo.rs index 49782c62838f8..e90d320e72321 100644 --- a/src/librustuv/addrinfo.rs +++ b/src/librustuv/addrinfo.rs @@ -120,7 +120,7 @@ impl Drop for Addrinfo { } } -fn each_ai_flag(_f: &fn(c_int, ai::Flag)) { +fn each_ai_flag(_f: |c_int, ai::Flag|) { /* XXX: do we really want to support these? unsafe { f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig); diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index ceda5f22adb1b..a94ae695eb743 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -294,7 +294,7 @@ impl Drop for FsRequest { } } -fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int) +fn execute(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int) -> Result { let mut req = FsRequest { @@ -326,9 +326,8 @@ fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int) } } -fn execute_nop(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int) - -> Result<(), UvError> -{ +fn execute_nop(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int) + -> Result<(), UvError> { execute(f).map(|_| {}) } diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index e8ce8113033a9..4690a347f1143 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -196,7 +196,7 @@ impl Drop for ForbidUnwind { } } -fn wait_until_woken_after(slot: *mut Option, f: &fn()) { +fn wait_until_woken_after(slot: *mut Option, f: ||) { let _f = ForbidUnwind::new("wait_until_woken_after"); unsafe { assert!((*slot).is_none()); diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index c009cc3998cab..0e90e01c46aff 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -34,7 +34,7 @@ use uvll::sockaddr; /// Generic functions related to dealing with sockaddr things //////////////////////////////////////////////////////////////////////////////// -fn socket_addr_as_sockaddr(addr: SocketAddr, f: &fn(*sockaddr) -> T) -> T { +fn socket_addr_as_sockaddr(addr: SocketAddr, f: |*sockaddr| -> T) -> T { let malloc = match addr.ip { Ipv4Addr(*) => uvll::rust_malloc_ip4_addr, Ipv6Addr(*) => uvll::rust_malloc_ip6_addr, diff --git a/src/librustuv/process.rs b/src/librustuv/process.rs index c537ee582cb8d..1ab84210face7 100644 --- a/src/librustuv/process.rs +++ b/src/librustuv/process.rs @@ -148,7 +148,7 @@ unsafe fn set_stdio(dst: *uvll::uv_stdio_container_t, } /// Converts the program and arguments to the argv array expected by libuv -fn with_argv(prog: &str, args: &[~str], f: &fn(**libc::c_char) -> T) -> T { +fn with_argv(prog: &str, args: &[~str], f: |**libc::c_char| -> T) -> T { // First, allocation space to put all the C-strings (we need to have // ownership of them somewhere let mut c_strs = vec::with_capacity(args.len() + 1); @@ -167,7 +167,7 @@ fn with_argv(prog: &str, args: &[~str], f: &fn(**libc::c_char) -> T) -> T { } /// Converts the environment to the env array expected by libuv -fn with_env(env: Option<&[(~str, ~str)]>, f: &fn(**libc::c_char) -> T) -> T { +fn with_env(env: Option<&[(~str, ~str)]>, f: |**libc::c_char| -> T) -> T { let env = match env { Some(s) => s, None => { return f(ptr::null()); } diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index 0ce3e56c29dfc..fbf81a6f3a094 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -161,7 +161,7 @@ impl EventLoop for UvEventLoop { ~AsyncWatcher::new(self.uvio.uv_loop(), f) as ~RemoteCallback } - fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) { + fn io<'a>(&'a mut self, f: |&'a mut IoFactory|) { f(&mut self.uvio as &mut IoFactory) } } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 3adedf76eb840..8e291ca6705f3 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -43,6 +43,7 @@ pub enum ObsoleteSyntax { ObsoleteStructWildcard, ObsoleteVecDotDotWildcard, ObsoleteBoxedClosure, + ObsoleteClosureType, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -134,6 +135,11 @@ impl ParserObsoleteMethods for Parser { "managed closures have been removed and owned closures are \ now written `proc()`" ), + ObsoleteClosureType => ( + "closure type", + "closures are now written `|A| -> B` rather than `&fn(A) -> \ + B`." + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7de8e3087c877..5db26dd99dda6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1286,7 +1286,7 @@ impl Parser { return self.parse_ty_closure(Some(sigil), Some(lifetime)); } - token::IDENT(*) if sigil == ast::BorrowedSigil => { + token::IDENT(*) => { if self.token_is_old_style_closure_keyword() { self.obsolete(*self.last_span, ObsoleteBoxedClosure); return self.parse_ty_closure(Some(sigil), None); @@ -1311,6 +1311,7 @@ impl Parser { let opt_lifetime = self.parse_opt_lifetime(); if self.token_is_old_style_closure_keyword() { + self.obsolete(*self.last_span, ObsoleteClosureType); return self.parse_ty_closure(Some(BorrowedSigil), opt_lifetime); } 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 00eb31485b9d7..e5898b33e7785 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: &'static fn:Send(), + field: 'static ||:Send, } -fn foo(blk: &'static fn:()) -> X { +fn foo(blk: 'static ||:) -> X { return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds } diff --git a/src/test/compile-fail/once-cant-call-twice-on-stack.rs b/src/test/compile-fail/once-cant-call-twice-on-stack.rs index 9469d123d18d7..9cc69228c56f5 100644 --- a/src/test/compile-fail/once-cant-call-twice-on-stack.rs +++ b/src/test/compile-fail/once-cant-call-twice-on-stack.rs @@ -16,7 +16,7 @@ extern mod extra; use extra::arc; use std::util; -fn foo(blk: &once fn()) { +fn foo(blk: once ||) { blk(); blk(); //~ ERROR use of moved value } diff --git a/src/test/compile-fail/once-fn-subtyping.rs b/src/test/compile-fail/once-fn-subtyping.rs index 503b4d3e77b97..3a0afd70e3e71 100644 --- a/src/test/compile-fail/once-fn-subtyping.rs +++ b/src/test/compile-fail/once-fn-subtyping.rs @@ -10,8 +10,8 @@ #[feature(once_fns)]; fn main() { - let f: &once fn() = ||(); + let f: once || = ||(); let g: || = f; //~ ERROR mismatched types let h: || = ||(); - let i: &once fn() = h; // ok + let i: once || = h; // ok } diff --git a/src/test/run-pass/once-move-out-on-stack.rs b/src/test/run-pass/once-move-out-on-stack.rs index 8e340275d7fde..645948f142625 100644 --- a/src/test/run-pass/once-move-out-on-stack.rs +++ b/src/test/run-pass/once-move-out-on-stack.rs @@ -17,7 +17,7 @@ extern mod extra; use extra::arc; use std::util; -fn foo(blk: &once fn()) { +fn foo(blk: once ||) { blk(); } From 1eca34de7dd55719cd83153994e5caf2027f62a2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Nov 2013 14:17:12 -0800 Subject: [PATCH 04/12] libstd: Remove all non-`proc` uses of `do` from libstd --- src/libstd/ascii.rs | 2 +- src/libstd/at_vec.rs | 60 ++++------ src/libstd/c_str.rs | 96 +++++++--------- src/libstd/cell.rs | 1 + src/libstd/cleanup.rs | 12 +- src/libstd/either.rs | 8 +- src/libstd/fmt/mod.rs | 28 ++--- src/libstd/hash.rs | 60 +++++----- src/libstd/hashmap.rs | 16 ++- src/libstd/io/fs.rs | 68 +++++------ src/libstd/io/mod.rs | 22 ++-- src/libstd/io/native/file.rs | 84 +++++++------- src/libstd/io/native/process.rs | 40 +++---- src/libstd/io/net/addrinfo.rs | 4 +- src/libstd/io/net/ip.rs | 44 +++----- src/libstd/io/net/tcp.rs | 8 +- src/libstd/io/net/udp.rs | 12 +- src/libstd/io/net/unix.rs | 8 +- src/libstd/io/pipe.rs | 4 +- src/libstd/io/process.rs | 4 +- src/libstd/io/signal.rs | 10 +- src/libstd/io/stdio.rs | 38 +++---- src/libstd/io/timer.rs | 4 +- src/libstd/local_data.rs | 4 +- src/libstd/num/int_macros.rs | 8 +- src/libstd/num/uint_macros.rs | 8 +- src/libstd/os.rs | 128 ++++++++++----------- src/libstd/path/mod.rs | 4 +- src/libstd/rand/isaac.rs | 10 +- src/libstd/rc.rs | 30 ++++- src/libstd/reflect.rs | 8 +- src/libstd/repr.rs | 80 +++++++------ src/libstd/rt/basic.rs | 16 +-- src/libstd/rt/borrowck.rs | 34 +++--- src/libstd/rt/comm.rs | 100 ++++++++--------- src/libstd/rt/kill.rs | 5 +- src/libstd/rt/local.rs | 16 +-- src/libstd/rt/local_heap.rs | 12 +- src/libstd/rt/local_ptr.rs | 6 +- src/libstd/rt/logging.rs | 8 +- src/libstd/rt/mpmc_bounded_queue.rs | 4 +- src/libstd/rt/sched.rs | 40 ++++--- src/libstd/rt/task.rs | 32 +++--- src/libstd/rt/tube.rs | 4 +- src/libstd/rt/work_queue.rs | 8 +- src/libstd/run.rs | 8 +- src/libstd/select.rs | 8 +- src/libstd/str.rs | 168 ++++++++++------------------ src/libstd/task/mod.rs | 8 +- src/libstd/to_bytes.rs | 8 +- src/libstd/trie.rs | 22 ++-- src/libstd/unicode.rs | 8 +- src/libstd/unstable/dynamic_lib.rs | 32 +++--- src/libstd/unstable/lang.rs | 4 +- src/libstd/unstable/sync.rs | 57 ++++------ src/libstd/vec.rs | 96 ++++++++-------- 56 files changed, 722 insertions(+), 895 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 5d4f6ee112136..18b6a1ef52a00 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -290,7 +290,7 @@ impl<'self> AsciiStr for &'self [Ascii] { #[inline] fn eq_ignore_case(self, other: &[Ascii]) -> bool { - do self.iter().zip(other.iter()).all |(&a, &b)| { a.eq_ignore_case(b) } + self.iter().zip(other.iter()).all(|(&a, &b)| a.eq_ignore_case(b)) } } diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index a052ae87a41c5..4405d5be3886b 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -56,24 +56,24 @@ pub fn build(size: Option, builder: |push: |v: A||) -> @[A] { /// `lhs`. Afterwards, the `lhs` is then returned for use again. #[inline] pub fn append(lhs: @[T], rhs: &[T]) -> @[T] { - do build(Some(lhs.len() + rhs.len())) |push| { + build(Some(lhs.len() + rhs.len()), |push| { for x in lhs.iter() { push((*x).clone()); } for elt in rhs.iter() { push(elt.clone()); } - } + }) } /// Apply a function to each element of a vector and return the results pub fn map(v: &[T], f: |x: &T| -> U) -> @[U] { - do build(Some(v.len())) |push| { + build(Some(v.len()), |push| { for elem in v.iter() { push(f(elem)); } - } + }) } /** @@ -83,10 +83,10 @@ pub fn map(v: &[T], f: |x: &T| -> U) -> @[U] { * to the value returned by the function `op`. */ pub fn from_fn(n_elts: uint, op: |uint| -> T) -> @[T] { - do build(Some(n_elts)) |push| { + build(Some(n_elts), |push| { let mut i: uint = 0u; while i < n_elts { push(op(i)); i += 1u; } - } + }) } /** @@ -96,13 +96,13 @@ pub fn from_fn(n_elts: uint, op: |uint| -> T) -> @[T] { * to the value `t`. */ pub fn from_elem(n_elts: uint, t: T) -> @[T] { - do build(Some(n_elts)) |push| { + build(Some(n_elts), |push| { let mut i: uint = 0u; while i < n_elts { push(t.clone()); i += 1u; } - } + }) } /** @@ -137,11 +137,11 @@ impl Clone for @[T] { impl FromIterator for @[A] { fn from_iterator>(iterator: &mut T) -> @[A] { let (lower, _) = iterator.size_hint(); - do build(Some(lower)) |push| { + build(Some(lower), |push| { for x in *iterator { push(x); } - } + }) } } @@ -259,9 +259,9 @@ pub mod raw { use rt::local::Local; use rt::task::Task; - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { task.heap.realloc(ptr as *mut Box<()>, size) as *() - } + }) } } @@ -295,11 +295,11 @@ mod test { fn test() { // Some code that could use that, then: fn seq_range(lo: uint, hi: uint) -> @[uint] { - do build(None) |push| { + build(None, |push| { for i in range(lo, hi) { push(i); } - } + }) } assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); @@ -333,9 +333,7 @@ mod test { #[bench] fn bench_capacity(b: &mut bh) { let x = @[1, 2, 3]; - do b.iter { - capacity(x); - } + b.iter(|| capacity(x)); } #[bench] @@ -359,54 +357,42 @@ mod test { fn bench_append(b: &mut bh) { let lhs = @[7, ..128]; let rhs = range(0, 256).to_owned_vec(); - do b.iter { - append(lhs, rhs); - } + b.iter(|| append(lhs, rhs)) } #[bench] fn bench_map(b: &mut bh) { let elts = range(0, 256).to_owned_vec(); - do b.iter { - map(elts, |x| x*2); - } + b.iter(|| map(elts, |x| x*2)) } #[bench] fn bench_from_fn(b: &mut bh) { - do b.iter { - from_fn(1024, |x| x); - } + b.iter(|| from_fn(1024, |x| x)); } #[bench] fn bench_from_elem(b: &mut bh) { - do b.iter { - from_elem(1024, 0u64); - } + b.iter(|| from_elem(1024, 0u64)); } #[bench] fn bench_to_managed_move(b: &mut bh) { - do b.iter { + b.iter(|| { let elts = range(0, 1024).to_owned_vec(); // yikes! can't move out of capture, though to_managed_move(elts); - } + }) } #[bench] fn bench_to_managed(b: &mut bh) { let elts = range(0, 1024).to_owned_vec(); - do b.iter { - to_managed(elts); - } + b.iter(|| to_managed(elts)); } #[bench] fn bench_clone(b: &mut bh) { let elts = to_managed(range(0, 1024).to_owned_vec()); - do b.iter { - elts.clone(); - } + b.iter(|| elts.clone()); } } diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index a9c4d2cacde2c..306ee331929bb 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -49,15 +49,15 @@ let my_string = "Hello, world!"; // Allocate the C string with an explicit local that owns the string. The // `c_buffer` pointer will be deallocated when `my_c_string` goes out of scope. let my_c_string = my_string.to_c_str(); -do my_c_string.with_ref |c_buffer| { +my_c_string.with_ref(|c_buffer| { unsafe { puts(c_buffer); } -} +}) // Don't save off the allocation of the C string, the `c_buffer` will be // deallocated when this block returns! -do my_string.with_c_str |c_buffer| { +my_string.with_c_str(|c_buffer| { unsafe { puts(c_buffer); } -} +}) ``` */ @@ -262,14 +262,12 @@ static BUF_LEN: uint = 128; impl<'self> ToCStr for &'self [u8] { fn to_c_str(&self) -> CString { let mut cs = unsafe { self.to_c_str_unchecked() }; - do cs.with_mut_ref |buf| { - check_for_null(*self, buf); - } + cs.with_mut_ref(|buf| check_for_null(*self, buf)); cs } unsafe fn to_c_str_unchecked(&self) -> CString { - do self.as_imm_buf |self_buf, self_len| { + self.as_imm_buf(|self_buf, self_len| { let buf = libc::malloc(self_len as libc::size_t + 1) as *mut u8; if buf.is_null() { fail!("failed to allocate memory!"); @@ -279,7 +277,7 @@ impl<'self> ToCStr for &'self [u8] { *ptr::mut_offset(buf, self_len as int) = 0; CString::new(buf as *libc::c_char, true) - } + }) } fn with_c_str(&self, f: |*libc::c_char| -> T) -> T { @@ -298,13 +296,13 @@ unsafe fn with_c_str(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T { vec::bytes::copy_memory(buf, v, v.len()); buf[v.len()] = 0; - do buf.as_mut_buf |buf, _| { + buf.as_mut_buf(|buf, _| { if checked { check_for_null(v, buf as *mut libc::c_char); } f(buf as *libc::c_char) - } + }) } else if checked { v.to_c_str().with_ref(f) } else { @@ -390,10 +388,10 @@ mod tests { let ptr = vec::raw::to_ptr(input); let expected = ["zero", "one"]; let mut it = expected.iter(); - let result = do from_c_multistring(ptr as *libc::c_char, None) |c| { + let result = from_c_multistring(ptr as *libc::c_char, None, |c| { let cbytes = c.as_bytes().slice_to(c.len()); assert_eq!(cbytes, it.next().unwrap().as_bytes()); - }; + }); assert_eq!(result, 2); assert!(it.next().is_none()); } @@ -401,13 +399,13 @@ mod tests { #[test] fn test_str_to_c_str() { - do "".to_c_str().with_ref |buf| { + "".to_c_str().with_ref(|buf| { unsafe { assert_eq!(*ptr::offset(buf, 0), 0); } - } + }); - do "hello".to_c_str().with_ref |buf| { + "hello".to_c_str().with_ref(|buf| { unsafe { assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char); assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char); @@ -416,19 +414,19 @@ mod tests { assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char); assert_eq!(*ptr::offset(buf, 5), 0); } - } + }) } #[test] fn test_vec_to_c_str() { let b: &[u8] = []; - do b.to_c_str().with_ref |buf| { + b.to_c_str().with_ref(|buf| { unsafe { assert_eq!(*ptr::offset(buf, 0), 0); } - } + }); - do bytes!("hello").to_c_str().with_ref |buf| { + let _ = bytes!("hello").to_c_str().with_ref(|buf| { unsafe { assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char); assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char); @@ -437,9 +435,9 @@ mod tests { assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char); assert_eq!(*ptr::offset(buf, 5), 0); } - } + }); - do bytes!("foo", 0xff).to_c_str().with_ref |buf| { + let _ = bytes!("foo", 0xff).to_c_str().with_ref(|buf| { unsafe { assert_eq!(*ptr::offset(buf, 0), 'f' as libc::c_char); assert_eq!(*ptr::offset(buf, 1), 'o' as libc::c_char); @@ -447,7 +445,7 @@ mod tests { assert_eq!(*ptr::offset(buf, 3), 0xff); assert_eq!(*ptr::offset(buf, 4), 0); } - } + }); } #[test] @@ -500,18 +498,16 @@ mod tests { use c_str::null_byte::cond; let mut error_happened = false; - do cond.trap(|err| { + cond.trap(|err| { assert_eq!(err, bytes!("he", 0, "llo").to_owned()) error_happened = true; Truncate - }).inside { - "he\x00llo".to_c_str() - }; + }).inside(|| "he\x00llo".to_c_str()); assert!(error_happened); - do cond.trap(|_| { + cond.trap(|_| { ReplaceWith('?' as libc::c_char) - }).inside(|| "he\x00llo".to_c_str()).with_ref |buf| { + }).inside(|| "he\x00llo".to_c_str()).with_ref(|buf| { unsafe { assert_eq!(*buf.offset(0), 'h' as libc::c_char); assert_eq!(*buf.offset(1), 'e' as libc::c_char); @@ -521,13 +517,13 @@ mod tests { assert_eq!(*buf.offset(5), 'o' as libc::c_char); assert_eq!(*buf.offset(6), 0); } - } + }) } #[test] fn test_to_c_str_unchecked() { unsafe { - do "he\x00llo".to_c_str_unchecked().with_ref |buf| { + "he\x00llo".to_c_str_unchecked().with_ref(|buf| { assert_eq!(*buf.offset(0), 'h' as libc::c_char); assert_eq!(*buf.offset(1), 'e' as libc::c_char); assert_eq!(*buf.offset(2), 0); @@ -535,7 +531,7 @@ mod tests { assert_eq!(*buf.offset(4), 'l' as libc::c_char); assert_eq!(*buf.offset(5), 'o' as libc::c_char); assert_eq!(*buf.offset(6), 0); - } + }) } } @@ -579,7 +575,7 @@ mod bench { #[inline] fn check(s: &str, c_str: *libc::c_char) { - do s.as_imm_buf |s_buf, s_len| { + s.as_imm_buf(|s_buf, s_len| { for i in range(0, s_len) { unsafe { assert_eq!( @@ -587,7 +583,7 @@ mod bench { *ptr::offset(c_str, i as int)); } } - } + }) } static s_short: &'static str = "Mary"; @@ -601,12 +597,10 @@ mod bench { Mary had a little lamb, Little lamb"; fn bench_to_str(bh: &mut BenchHarness, s: &str) { - do bh.iter { + bh.iter(|| { let c_str = s.to_c_str(); - do c_str.with_ref |c_str_buf| { - check(s, c_str_buf) - } - } + c_str.with_ref(|c_str_buf| check(s, c_str_buf)) + }) } #[bench] @@ -625,12 +619,10 @@ mod bench { } fn bench_to_c_str_unchecked(bh: &mut BenchHarness, s: &str) { - do bh.iter { + bh.iter(|| { let c_str = unsafe { s.to_c_str_unchecked() }; - do c_str.with_ref |c_str_buf| { - check(s, c_str_buf) - } - } + c_str.with_ref(|c_str_buf| check(s, c_str_buf)) + }) } #[bench] @@ -649,11 +641,9 @@ mod bench { } fn bench_with_c_str(bh: &mut BenchHarness, s: &str) { - do bh.iter { - do s.with_c_str |c_str_buf| { - check(s, c_str_buf) - } - } + bh.iter(|| { + s.with_c_str(|c_str_buf| check(s, c_str_buf)) + }) } #[bench] @@ -672,13 +662,11 @@ mod bench { } fn bench_with_c_str_unchecked(bh: &mut BenchHarness, s: &str) { - do bh.iter { + bh.iter(|| { unsafe { - do s.with_c_str_unchecked |c_str_buf| { - check(s, c_str_buf) - } + s.with_c_str_unchecked(|c_str_buf| check(s, c_str_buf)) } - } + }) } #[bench] diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index e49cf3e5303b3..634558b9b971d 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -82,6 +82,7 @@ pub struct RefCell { priv nc: NonCopyable } +<<<<<<< HEAD // Values [1, MAX-1] represent the number of `Ref` active // (will not outgrow its range since `uint` is the size of the address space) type BorrowFlag = uint; diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index 2f7b27b55e321..7c972ed86b4dd 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -82,7 +82,7 @@ pub unsafe fn annihilate() { // // In this pass, nothing gets freed, so it does not matter whether // we read the next field before or after the callback. - do each_live_alloc(true) |box, uniq| { + each_live_alloc(true, |box, uniq| { stats.n_total_boxes += 1; if uniq { stats.n_unique_boxes += 1; @@ -90,21 +90,21 @@ pub unsafe fn annihilate() { (*box).ref_count = managed::RC_IMMORTAL; } true - }; + }); // Pass 2: Drop all boxes. // // In this pass, unique-managed boxes may get freed, but not // managed boxes, so we must read the `next` field *after* the // callback, as the original value may have been freed. - do each_live_alloc(false) |box, uniq| { + each_live_alloc(false, |box, uniq| { if !uniq { let tydesc = (*box).type_desc; let data = &(*box).data as *(); ((*tydesc).drop_glue)(data as *i8); } true - }; + }); // Pass 3: Free all boxes. // @@ -112,7 +112,7 @@ pub unsafe fn annihilate() { // unique-managed boxes, though I think that none of those are // left), so we must read the `next` field before, since it will // not be valid after. - do each_live_alloc(true) |box, uniq| { + each_live_alloc(true, |box, uniq| { if !uniq { stats.n_bytes_freed += (*((*box).type_desc)).size @@ -120,7 +120,7 @@ pub unsafe fn annihilate() { local_free(box as *i8); } true - }; + }); if debug_mem() { // We do logging here w/o allocation. diff --git a/src/libstd/either.rs b/src/libstd/either.rs index d2874a6f7f578..6d152d8c179a8 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -209,23 +209,23 @@ pub type Rights = FilterMap<'static, Either, R, Iter>; /// Extracts all the left values pub fn lefts>>(eithers: Iter) -> Lefts { - do eithers.filter_map |elt| { + eithers.filter_map(|elt| { match elt { Left(x) => Some(x), _ => None, } - } + }) } /// Extracts all the right values pub fn rights>>(eithers: Iter) -> Rights { - do eithers.filter_map |elt| { + eithers.filter_map(|elt| { match elt { Right(x) => Some(x), _ => None, } - } + }) } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 427690a4aa589..33ef4731405fa 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -801,12 +801,12 @@ impl<'self> Formatter<'self> { } fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) { - do ::uint::to_str_bytes(value, 10) |buf| { + ::uint::to_str_bytes(value, 10, |buf| { let valuestr = str::from_utf8_slice(buf); for piece in pieces.iter() { self.run(piece, Some(valuestr)); } - } + }) } // Helper methods used for padding and processing formatting arguments that @@ -868,9 +868,9 @@ impl<'self> Formatter<'self> { self.fill = '0'; sign(self); } - do self.with_padding(min - actual_len, parse::AlignRight) |me| { + self.with_padding(min - actual_len, parse::AlignRight, |me| { emit(me); - } + }) } } } @@ -924,9 +924,9 @@ impl<'self> Formatter<'self> { // If we're under both the maximum and the minimum width, then fill // up the minimum width with the specified string + some alignment. Some(width) => { - do self.with_padding(width - s.len(), parse::AlignLeft) |me| { + self.with_padding(width - s.len(), parse::AlignLeft, |me| { me.buf.write(s.as_bytes()); - } + }) } } } @@ -1007,18 +1007,18 @@ macro_rules! int_base(($ty:ident, $into:ident, $base:expr, $name:ident, $prefix:expr) => { impl $name for $ty { fn fmt(c: &$ty, f: &mut Formatter) { - do ::$into::to_str_bytes(*c as $into, $base) |buf| { + ::$into::to_str_bytes(*c as $into, $base, |buf| { f.pad_integral(buf, $prefix, true); - } + }) } } }) macro_rules! upper_hex(($ty:ident, $into:ident) => { impl UpperHex for $ty { fn fmt(c: &$ty, f: &mut Formatter) { - do ::$into::to_str_bytes(*c as $into, 16) |buf| { + ::$into::to_str_bytes(*c as $into, 16, |buf| { upperhex(buf, f); - } + }) } } }) @@ -1045,9 +1045,9 @@ macro_rules! integer(($signed:ident, $unsigned:ident) => { // nothing else should do that, however. impl Signed for $signed { fn fmt(c: &$signed, f: &mut Formatter) { - do ::$unsigned::to_str_bytes(c.abs() as $unsigned, 10) |buf| { + ::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| { f.pad_integral(buf, "", *c >= 0); - } + }) } } int_base!($signed, $unsigned, 2, Binary, "0b") @@ -1104,9 +1104,9 @@ impl Poly for T { impl Pointer for *T { fn fmt(t: &*T, f: &mut Formatter) { f.flags |= 1 << (parse::FlagAlternate as uint); - do ::uint::to_str_bytes(*t as uint, 16) |buf| { + ::uint::to_str_bytes(*t as uint, 16, |buf| { f.pad_integral(buf, "0x", true); - } + }) } } impl Pointer for *mut T { diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs index f15abff831690..5a671eea7a348 100644 --- a/src/libstd/hash.rs +++ b/src/libstd/hash.rs @@ -83,10 +83,10 @@ impl Hash for A { #[inline] fn hash_keyed(&self, k0: u64, k1: u64) -> u64 { let mut s = State::new(k0, k1); - do self.iter_bytes(true) |bytes| { + self.iter_bytes(true, |bytes| { s.input(bytes); true - }; + }); s.result_u64() } } @@ -94,14 +94,14 @@ impl Hash for A { fn hash_keyed_2(a: &A, b: &B, k0: u64, k1: u64) -> u64 { let mut s = State::new(k0, k1); - do a.iter_bytes(true) |bytes| { + a.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do b.iter_bytes(true) |bytes| { + }); + b.iter_bytes(true, |bytes| { s.input(bytes); true - }; + }); s.result_u64() } @@ -109,18 +109,18 @@ fn hash_keyed_3(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64 { let mut s = State::new(k0, k1); - do a.iter_bytes(true) |bytes| { + a.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do b.iter_bytes(true) |bytes| { + }); + b.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do c.iter_bytes(true) |bytes| { + }); + c.iter_bytes(true, |bytes| { s.input(bytes); true - }; + }); s.result_u64() } @@ -136,22 +136,22 @@ fn hash_keyed_4 u64 { let mut s = State::new(k0, k1); - do a.iter_bytes(true) |bytes| { + a.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do b.iter_bytes(true) |bytes| { + }); + b.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do c.iter_bytes(true) |bytes| { + }); + c.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do d.iter_bytes(true) |bytes| { + }); + d.iter_bytes(true, |bytes| { s.input(bytes); true - }; + }); s.result_u64() } @@ -169,26 +169,26 @@ fn hash_keyed_5 u64 { let mut s = State::new(k0, k1); - do a.iter_bytes(true) |bytes| { + a.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do b.iter_bytes(true) |bytes| { + }); + b.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do c.iter_bytes(true) |bytes| { + }); + c.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do d.iter_bytes(true) |bytes| { + }); + d.iter_bytes(true, |bytes| { s.input(bytes); true - }; - do e.iter_bytes(true) |bytes| { + }); + e.iter_bytes(true, |bytes| { s.input(bytes); true - }; + }); s.result_u64() } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 0bc1aa8935353..a61871cbb5e27 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -110,7 +110,7 @@ impl HashMap { k: &K) -> SearchResult { let mut ret = TableFull; - do self.bucket_sequence(hash) |i| { + self.bucket_sequence(hash, |i| { match self.buckets[i] { Some(ref bkt) if bkt.hash == hash && *k == bkt.key => { ret = FoundEntry(i); false @@ -118,7 +118,7 @@ impl HashMap { None => { ret = FoundHole(i); false } _ => true, } - }; + }); ret } @@ -128,7 +128,7 @@ impl HashMap { k: &Q) -> SearchResult { let mut ret = TableFull; - do self.bucket_sequence(hash) |i| { + self.bucket_sequence(hash, |i| { match self.buckets[i] { Some(ref bkt) if bkt.hash == hash && k.equiv(&bkt.key) => { ret = FoundEntry(i); false @@ -136,7 +136,7 @@ impl HashMap { None => { ret = FoundHole(i); false } _ => true, } - }; + }); ret } @@ -236,9 +236,7 @@ impl HashMap { let len_buckets = self.buckets.len(); let bucket = self.buckets[idx].take(); - let value = do bucket.map |bucket| { - bucket.value - }; + let value = bucket.map(|bucket| bucket.value); /* re-inserting buckets may cause changes in size, so remember what our new size is ahead of time before we start insertions */ @@ -500,12 +498,12 @@ impl Eq for HashMap { fn eq(&self, other: &HashMap) -> bool { if self.len() != other.len() { return false; } - do self.iter().all |(key, value)| { + self.iter().all(|(key, value)| { match other.find(key) { None => false, Some(v) => value == v } - } + }) } fn ne(&self, other: &HashMap) -> bool { !self.eq(other) } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 930f58ef33f27..d1502df047e70 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -76,7 +76,7 @@ pub struct File { } fn io_raise(f: |io: &mut IoFactory| -> Result) -> Option { - do with_local_io |io| { + with_local_io(|io| { match f(io) { Ok(t) => Some(t), Err(ioerr) => { @@ -84,7 +84,7 @@ fn io_raise(f: |io: &mut IoFactory| -> Result) -> Option { None } } - } + }) } impl File { @@ -97,9 +97,9 @@ impl File { /// /// let p = Path::new("/some/file/path.txt"); /// - /// do io_error::cond.trap(|_| { + /// io_error::cond.trap(|_| { /// // hoo-boy... - /// }).inside { + /// }).inside(|| { /// let file = match File::open_mode(&p, Open, ReadWrite) { /// Some(s) => s, /// None => fail!("whoops! I'm sure this raised, anyways..") @@ -107,7 +107,7 @@ impl File { /// // do some stuff with that file /// /// // the file will be closed at the end of this block - /// } + /// }) /// // .. /// /// `FileMode` and `FileAccess` provide information about the permissions @@ -132,7 +132,7 @@ impl File { pub fn open_mode(path: &Path, mode: FileMode, access: FileAccess) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.fs_open(&path.to_c_str(), mode, access) { Ok(fd) => Some(File { path: path.clone(), @@ -144,7 +144,7 @@ impl File { None } } - } + }) } /// Attempts to open a file in read-only mode. This function is equivalent to @@ -244,7 +244,7 @@ impl File { /// directory, the user lacks permissions to remove the file, or if some /// other filesystem-level error occurs. pub fn unlink(path: &Path) { - do io_raise |io| { io.fs_unlink(&path.to_c_str()) }; + io_raise(|io| io.fs_unlink(&path.to_c_str())); } /// Given a path, query the file system to get information about a file, @@ -272,9 +272,7 @@ pub fn unlink(path: &Path) { /// requisite permissions to perform a `stat` call on the given path or if /// there is no entry in the filesystem at the provided path. pub fn stat(path: &Path) -> FileStat { - do io_raise |io| { - io.fs_stat(&path.to_c_str()) - }.unwrap_or_else(dummystat) + io_raise(|io| io.fs_stat(&path.to_c_str())).unwrap_or_else(dummystat) } fn dummystat() -> FileStat { @@ -310,9 +308,7 @@ fn dummystat() -> FileStat { /// /// See `stat` pub fn lstat(path: &Path) -> FileStat { - do io_raise |io| { - io.fs_lstat(&path.to_c_str()) - }.unwrap_or_else(dummystat) + io_raise(|io| io.fs_lstat(&path.to_c_str())).unwrap_or_else(dummystat) } /// Rename a file or directory to a new name. @@ -330,9 +326,7 @@ pub fn lstat(path: &Path) -> FileStat { /// the process lacks permissions to view the contents, or if some other /// intermittent I/O error occurs. pub fn rename(from: &Path, to: &Path) { - do io_raise |io| { - io.fs_rename(&from.to_c_str(), &to.to_c_str()) - }; + io_raise(|io| io.fs_rename(&from.to_c_str(), &to.to_c_str())); } /// Copies the contents of one file to another. This function will also @@ -403,9 +397,7 @@ pub fn copy(from: &Path, to: &Path) { /// condition. Some possible error situations are not having the permission to /// change the attributes of a file or the file not existing. pub fn chmod(path: &Path, mode: io::FilePermission) { - do io_raise |io| { - io.fs_chmod(&path.to_c_str(), mode) - }; + io_raise(|io| io.fs_chmod(&path.to_c_str(), mode)); } /// Change the user and group owners of a file at the specified path. @@ -414,7 +406,7 @@ pub fn chmod(path: &Path, mode: io::FilePermission) { /// /// This funtion will raise on the `io_error` condition on failure. pub fn chown(path: &Path, uid: int, gid: int) { - do io_raise |io| { io.fs_chown(&path.to_c_str(), uid, gid) }; + io_raise(|io| io.fs_chown(&path.to_c_str(), uid, gid)); } /// Creates a new hard link on the filesystem. The `dst` path will be a @@ -425,7 +417,7 @@ pub fn chown(path: &Path, uid: int, gid: int) { /// /// This function will raise on the `io_error` condition on failure. pub fn link(src: &Path, dst: &Path) { - do io_raise |io| { io.fs_link(&src.to_c_str(), &dst.to_c_str()) }; + io_raise(|io| io.fs_link(&src.to_c_str(), &dst.to_c_str())); } /// Creates a new symbolic link on the filesystem. The `dst` path will be a @@ -435,7 +427,7 @@ pub fn link(src: &Path, dst: &Path) { /// /// This function will raise on the `io_error` condition on failure. pub fn symlink(src: &Path, dst: &Path) { - do io_raise |io| { io.fs_symlink(&src.to_c_str(), &dst.to_c_str()) }; + io_raise(|io| io.fs_symlink(&src.to_c_str(), &dst.to_c_str())); } /// Reads a symlink, returning the file that the symlink points to. @@ -446,7 +438,7 @@ pub fn symlink(src: &Path, dst: &Path) { /// conditions include reading a file that does not exist or reading a file /// which is not a symlink. pub fn readlink(path: &Path) -> Option { - do io_raise |io| { io.fs_readlink(&path.to_c_str()) } + io_raise(|io| io.fs_readlink(&path.to_c_str())) } /// Create a new, empty directory at the provided path @@ -466,9 +458,7 @@ pub fn readlink(path: &Path) -> Option { /// to make a new directory at the provided path, or if the directory already /// exists. pub fn mkdir(path: &Path, mode: FilePermission) { - do io_raise |io| { - io.fs_mkdir(&path.to_c_str(), mode) - }; + io_raise(|io| io.fs_mkdir(&path.to_c_str(), mode)); } /// Remove an existing, empty directory @@ -487,9 +477,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) { /// to remove the directory at the provided path, or if the directory isn't /// empty. pub fn rmdir(path: &Path) { - do io_raise |io| { - io.fs_rmdir(&path.to_c_str()) - }; + io_raise(|io| io.fs_rmdir(&path.to_c_str())); } /// Retrieve a vector containing all entries within a provided directory @@ -516,9 +504,7 @@ pub fn rmdir(path: &Path) { /// the process lacks permissions to view the contents or if the `path` points /// at a non-directory file pub fn readdir(path: &Path) -> ~[Path] { - do io_raise |io| { - io.fs_readdir(&path.to_c_str(), 0) - }.unwrap_or_else(|| ~[]) + io_raise(|io| io.fs_readdir(&path.to_c_str(), 0)).unwrap_or_else(|| ~[]) } /// Returns an iterator which will recursively walk the directory structure @@ -599,9 +585,7 @@ pub fn rmdir_recursive(path: &Path) { /// happens. // FIXME(#10301) these arguments should not be u64 pub fn change_file_times(path: &Path, atime: u64, mtime: u64) { - do io_raise |io| { - io.fs_utime(&path.to_c_str(), atime, mtime) - }; + io_raise(|io| io.fs_utime(&path.to_c_str(), atime, mtime)); } impl Reader for File { @@ -797,12 +781,12 @@ mod test { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_that_does_not_exist.txt"); let mut called = false; - do io_error::cond.trap(|_| { + io_error::cond.trap(|_| { called = true; - }).inside { + }).inside(|| { let result = File::open_mode(filename, Open, Read); assert!(result.is_none()); - } + }); assert!(called); }) @@ -810,11 +794,9 @@ mod test { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_another_file_that_does_not_exist.txt"); let mut called = false; - do io_error::cond.trap(|_| { + io_error::cond.trap(|_| { called = true; - }).inside { - unlink(filename); - } + }).inside(|| unlink(filename)); assert!(called); }) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 8f66215105a3b..8cc4e7b389b46 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -40,9 +40,9 @@ Some examples of obvious things you might want to do * Iterate over the lines of a file - do File::open("message.txt").each_line |line| { + File::open("message.txt").each_line(|line| { println(line) - } + }) * Pull the lines of a file into a vector of strings @@ -395,13 +395,11 @@ condition! { /// Helper for wrapper calls where you want to /// ignore any io_errors that might be raised pub fn ignore_io_error(cb: || -> T) -> T { - do io_error::cond.trap(|_| { + io_error::cond.trap(|_| { // just swallow the error.. downstream users // who can make a decision based on a None result // won't care - }).inside { - cb() - } + }).inside(|| cb()) } /// Helper for catching an I/O error and wrapping it in a Result object. The @@ -501,7 +499,7 @@ pub trait Reader { buf.reserve_additional(len); vec::raw::set_len(buf, start_len + len); - do (|| { + (|| { while total_read < len { let len = buf.len(); let slice = buf.mut_slice(start_len + total_read, len); @@ -515,9 +513,7 @@ pub trait Reader { } } } - }).finally { - vec::raw::set_len(buf, start_len + total_read); - } + }).finally(|| vec::raw::set_len(buf, start_len + total_read)) } } @@ -542,17 +538,17 @@ pub trait Reader { fn read_to_end(&mut self) -> ~[u8] { let mut buf = vec::with_capacity(DEFAULT_BUF_SIZE); let mut keep_reading = true; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { if e.kind == EndOfFile { keep_reading = false; } else { io_error::cond.raise(e) } - }).inside { + }).inside(|| { while keep_reading { self.push_bytes(&mut buf, DEFAULT_BUF_SIZE) } - } + }); return buf; } diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index abaeab609aaa0..c21326262e4c6 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -37,7 +37,7 @@ 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; - let (data, origamt) = do data.as_imm_buf |data, amt| { (data, amt) }; + let (data, origamt) = data.as_imm_buf(|data, amt| (data, amt)); let mut data = data; let mut amt = origamt; while amt > 0 { @@ -83,11 +83,11 @@ impl FileDesc { fn inner_read(&mut self, buf: &mut [u8]) -> Result { #[cfg(windows)] type rlen = libc::c_uint; #[cfg(not(windows))] type rlen = libc::size_t; - let ret = do keep_going(buf) |buf, len| { + let ret = keep_going(buf, |buf, len| { unsafe { libc::read(self.fd, buf as *mut libc::c_void, len as rlen) as i64 } - }; + }); if ret == 0 { Err(io::standard_error(io::EndOfFile)) } else if ret < 0 { @@ -99,11 +99,11 @@ impl FileDesc { fn inner_write(&mut self, buf: &[u8]) -> Result<(), IoError> { #[cfg(windows)] type wlen = libc::c_uint; #[cfg(not(windows))] type wlen = libc::size_t; - let ret = do keep_going(buf) |buf, len| { + let ret = keep_going(buf, |buf, len| { unsafe { libc::write(self.fd, buf as *libc::c_void, len as wlen) as i64 } - }; + }); if ret < 0 { Err(super::last_error()) } else { @@ -344,12 +344,12 @@ impl CFile { impl rtio::RtioFileStream for CFile { fn read(&mut self, buf: &mut [u8]) -> Result { - let ret = do keep_going(buf) |buf, len| { + let ret = keep_going(buf, |buf, len| { unsafe { libc::fread(buf as *mut libc::c_void, 1, len as libc::size_t, self.file) as i64 } - }; + }); if ret == 0 { Err(io::standard_error(io::EndOfFile)) } else if ret < 0 { @@ -360,12 +360,12 @@ impl rtio::RtioFileStream for CFile { } fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { - let ret = do keep_going(buf) |buf, len| { + let ret = keep_going(buf, |buf, len| { unsafe { libc::fwrite(buf as *libc::c_void, 1, len as libc::size_t, self.file) as i64 } - }; + }); if ret < 0 { Err(super::last_error()) } else { @@ -445,9 +445,9 @@ pub fn open(path: &CString, fm: io::FileMode, fa: io::FileAccess) #[cfg(windows)] fn os_open(path: &CString, flags: c_int, mode: c_int) -> c_int { - do as_utf16_p(path.as_str().unwrap()) |path| { + as_utf16_p(path.as_str().unwrap(), |path| { unsafe { libc::wopen(path, flags, mode) } - } + }) } #[cfg(unix)] @@ -463,9 +463,9 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> { fn os_mkdir(p: &CString, _mode: c_int) -> IoResult<()> { super::mkerr_winbool(unsafe { // FIXME: turn mode into something useful? #2623 - do as_utf16_p(p.as_str().unwrap()) |buf| { + as_utf16_p(p.as_str().unwrap(), |buf| { libc::CreateDirectoryW(buf, ptr::mut_null()) - } + }) }) } @@ -497,9 +497,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { } debug!("os::list_dir -- BEFORE OPENDIR"); - let dir_ptr = do p.with_ref |buf| { - opendir(buf) - }; + let dir_ptr = p.with_ref(|buf| opendir(buf)); if (dir_ptr as uint != 0) { let mut paths = ~[]; @@ -540,7 +538,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { let p = CString::new(p.with_ref(|p| p), false); let p = Path::new(p); let star = p.join("*"); - do as_utf16_p(star.as_str().unwrap()) |path_ptr| { + as_utf16_p(star.as_str().unwrap(), |path_ptr| { let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint); let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE); if find_handle as libc::c_int != INVALID_HANDLE_VALUE { @@ -565,7 +563,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { } else { Err(super::last_error()) } - } + }) } get_list(p).map(|paths| prune(p, paths)) @@ -578,9 +576,7 @@ pub fn unlink(p: &CString) -> IoResult<()> { #[cfg(windows)] fn os_unlink(p: &CString) -> IoResult<()> { super::mkerr_winbool(unsafe { - do as_utf16_p(p.as_str().unwrap()) |buf| { - libc::DeleteFileW(buf) - } + as_utf16_p(p.as_str().unwrap(), |buf| libc::DeleteFileW(buf)); }) } @@ -596,11 +592,11 @@ pub fn rename(old: &CString, new: &CString) -> IoResult<()> { #[cfg(windows)] fn os_rename(old: &CString, new: &CString) -> IoResult<()> { super::mkerr_winbool(unsafe { - do as_utf16_p(old.as_str().unwrap()) |old| { - do as_utf16_p(new.as_str().unwrap()) |new| { + as_utf16_p(old.as_str().unwrap(), |old| { + as_utf16_p(new.as_str().unwrap(), |new| { libc::MoveFileExW(old, new, libc::MOVEFILE_REPLACE_EXISTING) - } - } + }) + }) }) } @@ -618,9 +614,7 @@ pub fn chmod(p: &CString, mode: io::FilePermission) -> IoResult<()> { #[cfg(windows)] fn os_chmod(p: &CString, mode: c_int) -> c_int { unsafe { - do as_utf16_p(p.as_str().unwrap()) |p| { - libc::wchmod(p, mode) - } + as_utf16_p(p.as_str().unwrap(), |p| libc::wchmod(p, mode)) } } @@ -636,7 +630,7 @@ pub fn rmdir(p: &CString) -> IoResult<()> { #[cfg(windows)] fn os_rmdir(p: &CString) -> c_int { unsafe { - do as_utf16_p(p.as_str().unwrap()) |p| { libc::wrmdir(p) } + as_utf16_p(p.as_str().unwrap(), |p| libc::wrmdir(p)) } } @@ -669,7 +663,7 @@ pub fn readlink(p: &CString) -> IoResult { #[cfg(windows)] fn os_readlink(p: &CString) -> IoResult { let handle = unsafe { - do as_utf16_p(p.as_str().unwrap()) |p| { + as_utf16_p(p.as_str().unwrap(), |p| { libc::CreateFileW(p, libc::GENERIC_READ, libc::FILE_SHARE_READ, @@ -677,15 +671,15 @@ pub fn readlink(p: &CString) -> IoResult { libc::OPEN_EXISTING, libc::FILE_ATTRIBUTE_NORMAL, ptr::mut_null()) - } + }) }; if handle == ptr::mut_null() { return Err(super::last_error()) } - let ret = do fill_utf16_buf_and_decode |buf, sz| { + let ret = fill_utf16_buf_and_decode(|buf, sz| { unsafe { libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz, libc::VOLUME_NAME_NT) } - }; + }); let ret = match ret { Some(s) => Ok(Path::new(s)), None => Err(super::last_error()), @@ -722,11 +716,11 @@ pub fn symlink(src: &CString, dst: &CString) -> IoResult<()> { #[cfg(windows)] fn os_symlink(src: &CString, dst: &CString) -> IoResult<()> { - super::mkerr_winbool(do as_utf16_p(src.as_str().unwrap()) |src| { - do as_utf16_p(dst.as_str().unwrap()) |dst| { + super::mkerr_winbool(as_utf16_p(src.as_str().unwrap(), |src| { + as_utf16_p(dst.as_str().unwrap(), |dst| { unsafe { libc::CreateSymbolicLinkW(dst, src, 0) } - } - }) + }) + })) } #[cfg(unix)] @@ -742,11 +736,11 @@ pub fn link(src: &CString, dst: &CString) -> IoResult<()> { #[cfg(windows)] fn os_link(src: &CString, dst: &CString) -> IoResult<()> { - super::mkerr_winbool(do as_utf16_p(src.as_str().unwrap()) |src| { - do as_utf16_p(dst.as_str().unwrap()) |dst| { + super::mkerr_winbool(as_utf16_p(src.as_str().unwrap(), |src| { + as_utf16_p(dst.as_str().unwrap(), |dst| { unsafe { libc::CreateHardLinkW(dst, src, ptr::mut_null()) } - } - }) + }) + })) } #[cfg(unix)] @@ -851,12 +845,12 @@ pub fn stat(p: &CString) -> IoResult { #[cfg(windows)] fn os_stat(p: &CString) -> IoResult { let mut stat: libc::stat = unsafe { intrinsics::uninit() }; - do as_utf16_p(p.as_str().unwrap()) |up| { + as_utf16_p(p.as_str().unwrap(), |up| { match unsafe { libc::wstat(up, &mut stat) } { 0 => Ok(mkstat(&stat, p)), _ => Err(super::last_error()), } - } + }) } #[cfg(unix)] @@ -898,9 +892,7 @@ pub fn utime(p: &CString, atime: u64, mtime: u64) -> IoResult<()> { modtime: (mtime / 1000) as libc::time64_t, }; unsafe { - do as_utf16_p(p.as_str().unwrap()) |p| { - libc::wutime(p, &buf) - } + as_utf16_p(p.as_str().unwrap(), |p| libc::wutime(p, &buf)) } } diff --git a/src/libstd/io/native/process.rs b/src/libstd/io/native/process.rs index 6f726d1a45e55..ef531c8803c76 100644 --- a/src/libstd/io/native/process.rs +++ b/src/libstd/io/native/process.rs @@ -234,18 +234,18 @@ fn spawn_process_os(prog: &str, args: &[~str], let mut pi = zeroed_process_information(); let mut create_err = None; - do with_envp(env) |envp| { - do with_dirp(dir) |dirp| { - do cmd.with_c_str |cmdp| { + with_envp(env, |envp| { + with_dirp(dir, |dirp| { + cmd.with_c_str(|cmdp| { let created = CreateProcessA(ptr::null(), cast::transmute(cmdp), ptr::mut_null(), ptr::mut_null(), TRUE, 0, envp, dirp, &mut si, &mut pi); if created == FALSE { create_err = Some(os::last_os_error()); } - } - } - } + }) + }) + }); CloseHandle(si.hStdInput); CloseHandle(si.hStdOutput); @@ -411,22 +411,22 @@ fn spawn_process_os(prog: &str, args: &[~str], close(fd as c_int); } - do with_dirp(dir) |dirp| { + with_dirp(dir, |dirp| { if !dirp.is_null() && chdir(dirp) == -1 { fail!("failure in chdir: {}", os::last_os_error()); } - } + }); - do with_envp(env) |envp| { + with_envp(env, |envp| { if !envp.is_null() { set_environ(envp); } - do with_argv(prog, args) |argv| { + with_argv(prog, args, |argv| { execvp(*argv, argv); // execvp only returns if an error occurred fail!("failure in execvp: {}", os::last_os_error()); - } - } + }) + }) } } @@ -448,9 +448,7 @@ fn with_argv(prog: &str, args: &[~str], cb: |**libc::c_char| -> T) -> T { // Next, convert each of the byte strings into a pointer. This is // technically unsafe as the caller could leak these pointers out of our // scope. - let mut ptrs = do tmps.map |tmp| { - tmp.with_ref(|buf| buf) - }; + let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf)); // Finally, make sure we add a null pointer. ptrs.push(ptr::null()); @@ -475,14 +473,10 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T { } // Once again, this is unsafe. - let mut ptrs = do tmps.map |tmp| { - tmp.with_ref(|buf| buf) - }; + let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf)); ptrs.push(ptr::null()); - do ptrs.as_imm_buf |buf, _| { - unsafe { cb(cast::transmute(buf)) } - } + ptrs.as_imm_buf(|buf, _| unsafe { cb(cast::transmute(buf)) }) } _ => cb(ptr::null()) } @@ -505,9 +499,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T { blk.push(0); - do blk.as_imm_buf |p, _len| { - unsafe { cb(cast::transmute(p)) } - } + blk.as_imm_buf(|p, _len| unsafe { cb(cast::transmute(p)) }); } _ => cb(ptr::mut_null()) } diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 7e2d1fc5e8349..03af64cc6dccf 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -97,7 +97,7 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> { /// consumption just yet. fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option) -> Option<~[Info]> { - do with_local_io |io| { + with_local_io(|io| { match io.get_host_addresses(hostname, servname, hint) { Ok(i) => Some(i), Err(ioerr) => { @@ -105,7 +105,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, None } } - } + }) } #[cfg(test)] diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 32c732b4fdaf5..e089628b9c779 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -94,9 +94,7 @@ impl<'self> Parser<'self> { // Commit only if parser read till EOF fn read_till_eof(&mut self, cb: |&mut Parser| -> Option) -> Option { - do self.read_atomically |p| { - cb(p).filtered(|_| p.is_eof()) - } + self.read_atomically(|p| cb(p).filtered(|_| p.is_eof())) } // Return result of first successful parser @@ -120,7 +118,7 @@ impl<'self> Parser<'self> { pb: |&mut Parser| -> Option, pc: |&mut Parser| -> Option) -> Option<(A, B, C)> { - do self.read_atomically |p| { + self.read_atomically(|p| { let a = pa(p); let b = if a.is_some() { pb(p) } else { None }; let c = if b.is_some() { pc(p) } else { None }; @@ -128,7 +126,7 @@ impl<'self> Parser<'self> { (Some(a), Some(b), Some(c)) => Some((a, b, c)), _ => None } - } + }) } // Read next char @@ -144,9 +142,9 @@ impl<'self> Parser<'self> { // Return char and advance iff next char is equal to requested fn read_given_char(&mut self, c: char) -> Option { - do self.read_atomically |p| { + self.read_atomically(|p| { p.read_char().filtered(|&next| next == c) - } + }) } // Read digit @@ -165,9 +163,9 @@ impl<'self> Parser<'self> { } } - do self.read_atomically |p| { + self.read_atomically(|p| { p.read_char().and_then(|c| parse_digit(c, radix)) - } + }) } fn read_number_impl(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option { @@ -195,9 +193,7 @@ impl<'self> Parser<'self> { // Read number, failing if max_digits of number value exceeded fn read_number(&mut self, radix: u8, max_digits: u32, upto: u32) -> Option { - do self.read_atomically |p| { - p.read_number_impl(radix, max_digits, upto) - } + self.read_atomically(|p| p.read_number_impl(radix, max_digits, upto)) } fn read_ipv4_addr_impl(&mut self) -> Option { @@ -220,9 +216,7 @@ impl<'self> Parser<'self> { // Read IPv4 address fn read_ipv4_addr(&mut self) -> Option { - do self.read_atomically |p| { - p.read_ipv4_addr_impl() - } + self.read_atomically(|p| p.read_ipv4_addr_impl()) } fn read_ipv6_addr_impl(&mut self) -> Option { @@ -238,13 +232,13 @@ impl<'self> Parser<'self> { let mut i = 0; while i < limit { if i < limit - 1 { - let ipv4 = do p.read_atomically |p| { + let ipv4 = p.read_atomically(|p| { if i == 0 || p.read_given_char(':').is_some() { p.read_ipv4_addr() } else { None } - }; + }); match ipv4 { Some(Ipv4Addr(a, b, c, d)) => { groups[i + 0] = (a as u16 << 8) | (b as u16); @@ -255,13 +249,13 @@ impl<'self> Parser<'self> { } } - let group = do p.read_atomically |p| { + let group = p.read_atomically(|p| { if i == 0 || p.read_given_char(':').is_some() { p.read_number(16, 4, 0x10000).map(|n| n as u16) } else { None } - }; + }); match group { Some(g) => groups[i] = g, None => return (i, false) @@ -296,9 +290,7 @@ impl<'self> Parser<'self> { } fn read_ipv6_addr(&mut self) -> Option { - do self.read_atomically |p| { - p.read_ipv6_addr_impl() - } + self.read_atomically(|p| p.read_ipv6_addr_impl()) } fn read_ip_addr(&mut self) -> Option { @@ -330,17 +322,13 @@ impl<'self> Parser<'self> { impl FromStr for IpAddr { fn from_str(s: &str) -> Option { - do Parser::new(s).read_till_eof |p| { - p.read_ip_addr() - } + Parser::new(s).read_till_eof(|p| p.read_ip_addr()) } } impl FromStr for SocketAddr { fn from_str(s: &str) -> Option { - do Parser::new(s).read_till_eof |p| { - p.read_socket_addr() - } + Parser::new(s).read_till_eof(|p| p.read_socket_addr()) } } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index a59d652d739cd..ac099e67f795f 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -26,7 +26,7 @@ impl TcpStream { } pub fn connect(addr: SocketAddr) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.tcp_connect(addr) { Ok(s) => Some(TcpStream::new(s)), Err(ioerr) => { @@ -34,7 +34,7 @@ impl TcpStream { None } } - } + }) } pub fn peer_name(&mut self) -> Option { @@ -92,7 +92,7 @@ pub struct TcpListener { impl TcpListener { pub fn bind(addr: SocketAddr) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.tcp_bind(addr) { Ok(l) => Some(TcpListener { obj: l }), Err(ioerr) => { @@ -100,7 +100,7 @@ impl TcpListener { None } } - } + }) } pub fn socket_name(&mut self) -> Option { diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index b8cdbfc25cb4c..38def44d9d0e9 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -21,7 +21,7 @@ pub struct UdpSocket { impl UdpSocket { pub fn bind(addr: SocketAddr) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.udp_bind(addr) { Ok(s) => Some(UdpSocket { obj: s }), Err(ioerr) => { @@ -29,7 +29,7 @@ impl UdpSocket { None } } - } + }) } pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, SocketAddr)> { @@ -84,13 +84,13 @@ impl UdpStream { impl Reader for UdpStream { fn read(&mut self, buf: &mut [u8]) -> Option { let peer = self.connectedTo; - do self.as_socket |sock| { + self.as_socket(|sock| { match sock.recvfrom(buf) { Some((_nread, src)) if src != peer => Some(0), Some((nread, _src)) => Some(nread), None => None, } - } + }) } fn eof(&mut self) -> bool { fail!() } @@ -98,9 +98,7 @@ impl Reader for UdpStream { impl Writer for UdpStream { fn write(&mut self, buf: &[u8]) { - do self.as_socket |sock| { - sock.sendto(buf, self.connectedTo); - } + self.as_socket(|sock| sock.sendto(buf, self.connectedTo)); } } diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index 438261ba8a0a3..eb86f0ef97fe3 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -59,7 +59,7 @@ impl UnixStream { /// stream.write([1, 2, 3]); /// pub fn connect(path: &P) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.unix_connect(&path.to_c_str()) { Ok(s) => Some(UnixStream::new(s)), Err(ioerr) => { @@ -67,7 +67,7 @@ impl UnixStream { None } } - } + }) } } @@ -108,7 +108,7 @@ impl UnixListener { /// } /// pub fn bind(path: &P) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.unix_bind(&path.to_c_str()) { Ok(s) => Some(UnixListener{ obj: s }), Err(ioerr) => { @@ -116,7 +116,7 @@ impl UnixListener { None } } - } + }) } } diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index edbc6fa42852f..373de1649edc4 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -44,7 +44,7 @@ impl PipeStream { /// If the pipe cannot be created, an error will be raised on the /// `io_error` condition. pub fn open(fd: file::fd_t) -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.pipe_open(fd) { Ok(obj) => Some(PipeStream { obj: obj }), Err(e) => { @@ -52,7 +52,7 @@ impl PipeStream { None } } - } + }) } pub fn new(inner: ~RtioPipe) -> PipeStream { diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 276f5369cf527..308e969c43a1f 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -121,7 +121,7 @@ impl Process { /// source/destination pub fn new(config: ProcessConfig) -> Option { let config = Cell::new(config); - do with_local_io |io| { + with_local_io(|io| { match io.spawn(config.take()) { Ok((p, io)) => Some(Process{ handle: p, @@ -134,7 +134,7 @@ impl Process { None } } - } + }) } /// Returns the process id of this child process diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index 1310152d05fce..f6e79a0332321 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -123,7 +123,7 @@ impl Listener { if self.handles.contains_key(&signum) { return true; // self is already listening to signum, so succeed } - do with_local_io |io| { + with_local_io(|io| { match io.signal(signum, self.chan.clone()) { Ok(w) => { self.handles.insert(signum, w); @@ -134,7 +134,7 @@ impl Listener { None } } - }.is_some() + }).is_some() } /// Unregisters a signal. If this listener currently had a handler @@ -212,13 +212,13 @@ mod test { use super::User1; let mut s = Listener::new(); let mut called = false; - do io::io_error::cond.trap(|_| { + io::io_error::cond.trap(|_| { called = true; - }).inside { + }).inside(|| { if s.register(User1) { fail!("Unexpected successful registry of signum {:?}", User1); } - } + }); assert!(called); } } diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 1362d702f1c3a..2aa8b0c7ed6d5 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -70,7 +70,7 @@ enum StdSource { } fn src(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { - do with_local_io |io| { + with_local_io(|io| { let fd = unsafe { libc::dup(fd) }; match io.tty_open(fd, readable) { Ok(tty) => Some(f(TTY(tty))), @@ -84,14 +84,14 @@ fn src(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { Some(f(File(io.fs_from_raw_fd(fd, CloseAsynchronously)))) } } - }.unwrap() + }).unwrap() } /// Creates a new non-blocking handle to the stdin of the current process. /// /// See `stdout()` for notes about this function. pub fn stdin() -> StdReader { - do src(libc::STDIN_FILENO, true) |src| { StdReader { inner: src } } + src(libc::STDIN_FILENO, true, |src| StdReader { inner: src }) } /// Creates a new non-blocking handle to the stdout of the current process. @@ -101,14 +101,14 @@ pub fn stdin() -> StdReader { /// task context because the stream returned will be a non-blocking object using /// the local scheduler to perform the I/O. pub fn stdout() -> StdWriter { - do src(libc::STDOUT_FILENO, false) |src| { StdWriter { inner: src } } + src(libc::STDOUT_FILENO, false, |src| StdWriter { inner: src }) } /// Creates a new non-blocking handle to the stderr of the current process. /// /// See `stdout()` for notes about this function. pub fn stderr() -> StdWriter { - do src(libc::STDERR_FILENO, false) |src| { StdWriter { inner: src } } + src(libc::STDERR_FILENO, false, |src| StdWriter { inner: src }) } // Helper to access the local task's stdout handle @@ -116,11 +116,11 @@ pub fn stderr() -> StdWriter { // Note that this is not a safe function to expose because you can create an // aliased pointer very easily: // -// do with_task_stdout |io1| { -// do with_task_stdout |io2| { +// with_task_stdout(|io1| { +// with_task_stdout(|io2| { // // io1 aliases io2 -// } -// } +// }) +// }) fn with_task_stdout(f: |&mut Writer|) { use rt::local::Local; use rt::task::Task; @@ -158,42 +158,34 @@ fn with_task_stdout(f: |&mut Writer|) { /// will emit output to stderr, and while they are line buffered the log /// messages are always terminated in a newline (no need to flush). pub fn flush() { - do with_task_stdout |io| { - io.flush(); - } + with_task_stdout(|io| io.flush()) } /// Prints a string to the stdout of the current process. No newline is emitted /// after the string is printed. pub fn print(s: &str) { - do with_task_stdout |io| { - io.write(s.as_bytes()); - } + with_task_stdout(|io| io.write(s.as_bytes())) } /// Prints a string as a line. to the stdout of the current process. A literal /// `\n` character is printed to the console after the string. pub fn println(s: &str) { - do with_task_stdout |io| { + with_task_stdout(|io| { io.write(s.as_bytes()); io.write(['\n' as u8]); - } + }) } /// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible /// with the `format_args!` macro. pub fn print_args(fmt: &fmt::Arguments) { - do with_task_stdout |io| { - fmt::write(io, fmt); - } + with_task_stdout(|io| fmt::write(io, fmt)) } /// Similar to `println`, but takes a `fmt::Arguments` structure to be /// compatible with the `format_args!` macro. pub fn println_args(fmt: &fmt::Arguments) { - do with_task_stdout |io| { - fmt::writeln(io, fmt); - } + with_task_stdout(|io| fmt::writeln(io, fmt)) } /// Representation of a reader of a standard input stream diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 219f63026d205..8dda79358887e 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -60,7 +60,7 @@ impl Timer { /// for a number of milliseconds, or to possibly create channels which will /// get notified after an amount of time has passed. pub fn new() -> Option { - do with_local_io |io| { + with_local_io(|io| { match io.timer_init() { Ok(t) => Some(Timer { obj: t }), Err(ioerr) => { @@ -70,7 +70,7 @@ impl Timer { } } - } + }) } /// Blocks the current task for `msecs` milliseconds. diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 083de15008a27..89907c7434cdf 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -189,7 +189,7 @@ pub fn get(key: Key, f: |Option<&T>| -> U) -> U { /// 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: |Option<&mut T>| -> U) -> U { - do get_with(key, MutLoan) |x| { + get_with(key, MutLoan, |x| { match x { None => f(None), // We're violating a lot of compiler guarantees with this @@ -199,7 +199,7 @@ pub fn get_mut(key: Key, f: |Option<&mut T>| -> U) -> U { // there is no need to be upset! Some(x) => { f(Some(unsafe { cast::transmute_mut(x) })) } } - } + }) } fn get_with(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { // base 2 number, and then we need another for a possible '-' character. let mut buf = [0u8, ..65]; let mut cur = 0; - do strconv::int_to_str_bytes_common(n, radix, strconv::SignNeg) |i| { + strconv::int_to_str_bytes_common(n, radix, strconv::SignNeg, |i| { buf[cur] = i; cur += 1; - } + }); f(buf.slice(0, cur)) } @@ -440,9 +440,9 @@ impl ToStrRadix for $T { #[inline] fn to_str_radix(&self, radix: uint) -> ~str { let mut buf: ~[u8] = ~[]; - do strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg) |i| { + strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg, |i| { buf.push(i); - } + }); // We know we generated valid utf-8, so we don't need to go through that // check. unsafe { str::raw::from_utf8_owned(buf) } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 49f270369f72c..3c276378df863 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -271,10 +271,10 @@ pub fn to_str_bytes(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { // base 2 number. let mut buf = [0u8, ..64]; let mut cur = 0; - do strconv::int_to_str_bytes_common(n, radix, strconv::SignNone) |i| { + strconv::int_to_str_bytes_common(n, radix, strconv::SignNone, |i| { buf[cur] = i; cur += 1; - } + }); f(buf.slice(0, cur)) } @@ -291,9 +291,9 @@ impl ToStrRadix for $T { #[inline] fn to_str_radix(&self, radix: uint) -> ~str { let mut buf = ~[]; - do strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone) |i| { + strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone, |i| { buf.push(i); - } + }); // We know we generated valid utf-8, so we don't need to go through that // check. unsafe { str::raw::from_utf8_owned(buf) } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index f457649965224..baa4423220c5d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -58,7 +58,7 @@ static BUF_BYTES : uint = 2048u; #[cfg(unix)] pub fn getcwd() -> Path { let mut buf = [0 as libc::c_char, ..BUF_BYTES]; - do buf.as_mut_buf |buf, len| { + buf.as_mut_buf(|buf, len| { unsafe { if libc::getcwd(buf, len as size_t).is_null() { fail!() @@ -66,7 +66,7 @@ pub fn getcwd() -> Path { Path::new(CString::new(buf as *c_char, false)) } - } + }) } #[cfg(windows)] @@ -74,13 +74,13 @@ pub fn getcwd() -> Path { use libc::DWORD; use libc::GetCurrentDirectoryW; let mut buf = [0 as u16, ..BUF_BYTES]; - do buf.as_mut_buf |buf, len| { + buf.as_mut_buf(|buf, len| { unsafe { if libc::GetCurrentDirectoryW(len as DWORD, buf) == 0 as DWORD { fail!(); } } - } + }); Path::new(str::from_utf16(buf)) } @@ -104,7 +104,7 @@ pub mod win32 { while !done { let mut k: DWORD = 0; let mut buf = vec::from_elem(n as uint, 0u16); - do buf.as_mut_buf |b, _sz| { + buf.as_mut_buf(|b, _sz| { k = f(b, TMPBUF_SZ as DWORD); if k == (0 as DWORD) { done = true; @@ -115,7 +115,7 @@ pub mod win32 { } else { done = true; } - } + }); if k != 0 && done { let sub = buf.slice(0, k as uint); res = option::Some(str::from_utf16(sub)); @@ -144,12 +144,10 @@ fn with_env_lock(f: || -> T) -> T { static mut lock: Mutex = MUTEX_INIT; unsafe { - return do (|| { + return (|| { lock.lock(); f() - }).finally { - lock.unlock(); - }; + }).finally(|| lock.unlock()); } } @@ -172,9 +170,9 @@ pub fn env() -> ~[(~str,~str)] { os::last_os_error()); } let mut result = ~[]; - do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| { + c_str::from_c_multistring(ch as *libc::c_char, None, |cstr| { result.push(cstr.as_str().unwrap().to_owned()); - }; + }); FreeEnvironmentStringsA(ch); result } @@ -207,10 +205,10 @@ pub fn env() -> ~[(~str,~str)] { } pairs } - do with_env_lock { + with_env_lock(|| { let unparsed_environ = get_env_pairs(); env_convert(unparsed_environ) - } + }) } } @@ -219,16 +217,14 @@ pub fn env() -> ~[(~str,~str)] { /// None if the variable isn't set. pub fn getenv(n: &str) -> Option<~str> { unsafe { - do with_env_lock { - let s = do n.with_c_str |buf| { - libc::getenv(buf) - }; + with_env_lock(|| { + let s = n.with_c_str(|buf| libc::getenv(buf)); if s.is_null() { None } else { Some(str::raw::from_c_str(s)) } - } + }) } } @@ -237,14 +233,14 @@ pub fn getenv(n: &str) -> Option<~str> { /// None if the variable isn't set. pub fn getenv(n: &str) -> Option<~str> { unsafe { - do with_env_lock { + with_env_lock(|| { use os::win32::{as_utf16_p, fill_utf16_buf_and_decode}; - do as_utf16_p(n) |u| { - do fill_utf16_buf_and_decode() |buf, sz| { + as_utf16_p(n, |u| { + fill_utf16_buf_and_decode(|buf, sz| { libc::GetEnvironmentVariableW(u, buf, sz) - } - } - } + }) + }) + }) } } @@ -254,13 +250,13 @@ pub fn getenv(n: &str) -> Option<~str> { /// process pub fn setenv(n: &str, v: &str) { unsafe { - do with_env_lock { - do n.with_c_str |nbuf| { - do v.with_c_str |vbuf| { + with_env_lock(|| { + n.with_c_str(|nbuf| { + v.with_c_str(|vbuf| { libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1); - } - } - } + }) + }) + }) } } @@ -270,14 +266,14 @@ pub fn setenv(n: &str, v: &str) { /// process pub fn setenv(n: &str, v: &str) { unsafe { - do with_env_lock { + with_env_lock(|| { use os::win32::as_utf16_p; - do as_utf16_p(n) |nbuf| { - do as_utf16_p(v) |vbuf| { + as_utf16_p(n, |nbuf| { + as_utf16_p(v, |vbuf| { libc::SetEnvironmentVariableW(nbuf, vbuf); - } - } - } + }) + }) + }) } } @@ -286,22 +282,22 @@ pub fn unsetenv(n: &str) { #[cfg(unix)] fn _unsetenv(n: &str) { unsafe { - do with_env_lock { - do n.with_c_str |nbuf| { + with_env_lock(|| { + n.with_c_str(|nbuf| { libc::funcs::posix01::unistd::unsetenv(nbuf); - } - } + }) + }) } } #[cfg(windows)] fn _unsetenv(n: &str) { unsafe { - do with_env_lock { + with_env_lock(|| { use os::win32::as_utf16_p; - do as_utf16_p(n) |nbuf| { + as_utf16_p(n, |nbuf| { libc::SetEnvironmentVariableW(nbuf, ptr::null()); - } - } + }) + }) } } @@ -372,10 +368,10 @@ pub fn self_exe_path() -> Option { if err != 0 { return None; } if sz == 0 { return None; } let mut v: ~[u8] = vec::with_capacity(sz as uint); - let err = do v.as_mut_buf |buf,_| { + let err = v.as_mut_buf(|buf,_| { sysctl(vec::raw::to_ptr(mib), mib.len() as ::libc::c_uint, buf as *mut c_void, &mut sz, ptr::null(), 0u as size_t) - }; + }); if err != 0 { return None; } if sz == 0 { return None; } vec::raw::set_len(&mut v, sz as uint - 1); // chop off trailing NUL @@ -403,9 +399,9 @@ pub fn self_exe_path() -> Option { _NSGetExecutablePath(ptr::mut_null(), &mut sz); if sz == 0 { return None; } let mut v: ~[u8] = vec::with_capacity(sz as uint); - let err = do v.as_mut_buf |buf,_| { + let err = v.as_mut_buf(|buf, _| { _NSGetExecutablePath(buf as *mut i8, &mut sz) - }; + }); if err != 0 { return None; } vec::raw::set_len(&mut v, sz as uint - 1); // chop off trailing NUL Some(v) @@ -416,9 +412,9 @@ pub fn self_exe_path() -> Option { fn load_self() -> Option<~[u8]> { unsafe { use os::win32::fill_utf16_buf_and_decode; - do fill_utf16_buf_and_decode() |buf, sz| { + fill_utf16_buf_and_decode(|buf, sz| { libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz) - }.map(|s| s.into_bytes()) + }).map(|s| s.into_bytes()) } } @@ -452,13 +448,13 @@ pub fn homedir() -> Option { #[cfg(windows)] fn secondary() -> Option { - do getenv("USERPROFILE").and_then |p| { + getenv("USERPROFILE").and_then(|p| { if !p.is_empty() { Path::new_opt(p) } else { None } - } + }) } } @@ -536,19 +532,19 @@ pub fn change_dir(p: &Path) -> bool { fn chdir(p: &Path) -> bool { unsafe { use os::win32::as_utf16_p; - return do as_utf16_p(p.as_str().unwrap()) |buf| { + return as_utf16_p(p.as_str().unwrap(), |buf| { libc::SetCurrentDirectoryW(buf) != (0 as libc::BOOL) - }; + }); } } #[cfg(unix)] fn chdir(p: &Path) -> bool { - do p.with_c_str |buf| { + p.with_c_str(|buf| { unsafe { libc::chdir(buf) == (0 as c_int) } - } + }) } } @@ -637,7 +633,7 @@ pub fn last_os_error() -> ~str { let mut buf = [0 as c_char, ..TMPBUF_SZ]; - do buf.as_mut_buf |buf, len| { + buf.as_mut_buf(|buf, len| { unsafe { if strerror_r(errno() as c_int, buf, len as size_t) < 0 { fail!("strerror_r failure"); @@ -645,7 +641,7 @@ pub fn last_os_error() -> ~str { str::raw::from_c_str(buf as *c_char) } - } + }) } #[cfg(windows)] @@ -678,7 +674,7 @@ pub fn last_os_error() -> ~str { let mut buf = [0 as WCHAR, ..TMPBUF_SZ]; unsafe { - do buf.as_mut_buf |buf, len| { + buf.as_mut_buf(|buf, len| { let res = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, ptr::mut_null(), @@ -690,7 +686,7 @@ pub fn last_os_error() -> ~str { if res == 0 { fail!("[{}] FormatMessage failure", errno()); } - } + }); str::from_utf16(buf) } @@ -1466,13 +1462,11 @@ mod tests { let size = MemoryMap::granularity() * 2; let fd = unsafe { - let fd = do path.with_c_str |path| { + let fd = path.with_c_str(|path| { open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR) - }; + }); lseek_(fd, size); - do "x".with_c_str |x| { - assert!(write(fd, x as *c_void, 1) == 1); - } + "x".with_c_str(|x| assert!(write(fd, x as *c_void, 1) == 1)); fd }; let chunk = match MemoryMap::new(size / 2, [ @@ -1491,7 +1485,7 @@ mod tests { assert!(*chunk.data == 0xbe); close(fd); } - do io::ignore_io_error { fs::unlink(&path); } + io::ignore_io_error(|| fs::unlink(&path)); } // More recursive_mkdir tests are in extra::tempfile diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index f58db55d4c5e0..2b6009206acf7 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -530,9 +530,7 @@ pub struct Display<'self, P> { impl<'self, P: GenericPath> fmt::Default for Display<'self, P> { fn fmt(d: &Display

, f: &mut fmt::Formatter) { - do d.with_str |s| { - f.pad(s) - } + d.with_str(|s| f.pad(s)) } } diff --git a/src/libstd/rand/isaac.rs b/src/libstd/rand/isaac.rs index 42254b211a17c..877df1fb644f4 100644 --- a/src/libstd/rand/isaac.rs +++ b/src/libstd/rand/isaac.rs @@ -51,9 +51,9 @@ impl IsaacRng { unsafe { let ptr = raw::to_mut_ptr(rng.rsl); - do raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl)) |slice| { + raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl), |slice| { OSRng::new().fill_bytes(slice); - } + }) } rng.init(true); @@ -94,7 +94,7 @@ impl IsaacRng { }} ); - do 4.times { mix!(); } + 4.times(|| mix!()); if use_rsl { macro_rules! memloop ( @@ -256,9 +256,9 @@ impl Isaac64Rng { unsafe { let ptr = raw::to_mut_ptr(rng.rsl); - do raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl)) |slice| { + raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl), |slice| { OSRng::new().fill_bytes(slice); - } + }) } rng.init(true); diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 1b1546e57a32a..9506a772ee811 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -168,6 +168,28 @@ impl Drop for Rc { } } +impl Clone for RcMut { + /// Return a shallow copy of the reference counted pointer. + #[inline] + fn clone(&self) -> RcMut { + unsafe { + (*self.ptr).count += 1; + RcMut{ptr: self.ptr} + } + } +} + +impl DeepClone for RcMut { + /// Return a deep copy of the reference counted pointer. + #[inline] + fn deep_clone(&self) -> RcMut { + self.with_borrow(|x| { + // FIXME: #6497: should avoid freeze (slow) + unsafe { RcMut::new_unchecked(x.deep_clone()) } + }) + } +} + #[cfg(test)] mod test_rc { use super::*; @@ -177,9 +199,9 @@ mod test_rc { fn test_clone() { let x = Rc::from_send(RefCell::new(5)); let y = x.clone(); - do x.borrow().with_mut |inner| { + x.borrow().with_mut(|inner| { *inner = 20; - } + }); assert_eq!(y.borrow().with(|v| *v), 20); } @@ -187,9 +209,9 @@ mod test_rc { fn test_deep_clone() { let x = Rc::from_send(RefCell::new(5)); let y = x.deep_clone(); - do x.borrow().with_mut |inner| { + x.borrow().with_mut(|inner| { *inner = 20; - } + }); assert_eq!(y.borrow().with(|v| *v), 5); } diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index d0a6964917614..8a3e60eb3e2d5 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -50,16 +50,12 @@ pub fn MovePtrAdaptor(v: V) -> MovePtrAdaptor { impl MovePtrAdaptor { #[inline] pub fn bump(&mut self, sz: uint) { - do self.inner.move_ptr() |p| { - ((p as uint) + sz) as *c_void - }; + self.inner.move_ptr(|p| ((p as uint) + sz) as *c_void) } #[inline] pub fn align(&mut self, a: uint) { - do self.inner.move_ptr() |p| { - align(p as uint, a) as *c_void - }; + self.inner.move_ptr(|p| align(p as uint, a) as *c_void) } #[inline] diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index d30d08870665a..d26989c36e66a 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -53,18 +53,18 @@ impl Repr for bool { impl Repr for int { fn write_repr(&self, writer: &mut io::Writer) { - do ::int::to_str_bytes(*self, 10u) |bits| { + ::int::to_str_bytes(*self, 10u, |bits| { writer.write(bits); - } + }) } } macro_rules! int_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty { fn write_repr(&self, writer: &mut io::Writer) { - do ::$ty::to_str_bytes(*self, 10u) |bits| { + ::$ty::to_str_bytes(*self, 10u, |bits| { writer.write(bits); writer.write(bytes!($suffix)); - } + }) } })) @@ -163,9 +163,9 @@ impl<'self> ReprVisitor<'self> { #[inline] pub fn write(&mut self) -> bool { - do self.get |this, v:&T| { + self.get(|this, v:&T| { v.write_repr(unsafe { ::cast::transmute_copy(&this.writer) }); - } + }) } pub fn write_escaped_slice(&mut self, slice: &str) { @@ -234,9 +234,9 @@ impl<'self> ReprVisitor<'self> { } '\x20'..'\x7e' => self.writer.write([ch as u8]), _ => { - do char::escape_unicode(ch) |c| { + char::escape_unicode(ch, |c| { self.writer.write([c as u8]); - } + }) } } } @@ -265,31 +265,29 @@ impl<'self> TyVisitor for ReprVisitor<'self> { fn visit_f64(&mut self) -> bool { self.write::() } fn visit_char(&mut self) -> bool { - do self.get:: |this, &ch| { + self.get::(|this, &ch| { this.writer.write(['\'' as u8]); this.write_escaped_char(ch, false); this.writer.write(['\'' as u8]); - } + }) } fn visit_estr_box(&mut self) -> bool { - do self.get::<@str> |this, s| { + self.get::<@str>(|this, s| { this.writer.write(['@' as u8]); this.write_escaped_slice(*s); - } + }) } fn visit_estr_uniq(&mut self) -> bool { - do self.get::<~str> |this, s| { + self.get::<~str>(|this, s| { this.writer.write(['~' as u8]); this.write_escaped_slice(*s); - } + }) } fn visit_estr_slice(&mut self) -> bool { - do self.get::<&str> |this, s| { - this.write_escaped_slice(*s); - } + self.get::<&str>(|this, s| this.write_escaped_slice(*s)) } // Type no longer exists, vestigial function. @@ -299,91 +297,91 @@ impl<'self> TyVisitor for ReprVisitor<'self> { fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.writer.write(['@' as u8]); self.write_mut_qualifier(mtbl); - do self.get::<&raw::Box<()>> |this, b| { + self.get::<&raw::Box<()>>(|this, b| { let p = ptr::to_unsafe_ptr(&b.data) as *c_void; this.visit_ptr_inner(p, inner); - } + }) } fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { self.writer.write(['~' as u8]); - do self.get::<*c_void> |this, b| { + self.get::<*c_void>(|this, b| { this.visit_ptr_inner(*b, inner); - } + }) } fn visit_uniq_managed(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { self.writer.write(['~' as u8]); - do self.get::<&raw::Box<()>> |this, b| { + self.get::<&raw::Box<()>>(|this, b| { let p = ptr::to_unsafe_ptr(&b.data) as *c_void; this.visit_ptr_inner(p, inner); - } + }) } fn visit_ptr(&mut self, mtbl: uint, _inner: *TyDesc) -> bool { - do self.get::<*c_void> |this, p| { + self.get::<*c_void>(|this, p| { write!(this.writer, "({} as *", *p); this.write_mut_qualifier(mtbl); this.writer.write("())".as_bytes()); - } + }) } fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.writer.write(['&' as u8]); self.write_mut_qualifier(mtbl); - do self.get::<*c_void> |this, p| { + self.get::<*c_void>(|this, p| { this.visit_ptr_inner(*p, inner); - } + }) } // Type no longer exists, vestigial function. fn visit_vec(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { fail!(); } fn visit_unboxed_vec(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::> |this, b| { + self.get::>(|this, b| { this.write_unboxed_vec_repr(mtbl, b, inner); - } + }) } fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&raw::Box>> |this, b| { + self.get::<&raw::Box>>(|this, b| { this.writer.write(['@' as u8]); this.write_mut_qualifier(mtbl); this.write_unboxed_vec_repr(mtbl, &b.data, inner); - } + }) } fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&raw::Vec<()>> |this, b| { + self.get::<&raw::Vec<()>>(|this, b| { this.writer.write(['~' as u8]); this.write_unboxed_vec_repr(mtbl, *b, inner); - } + }) } fn visit_evec_uniq_managed(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&raw::Box>> |this, b| { + self.get::<&raw::Box>>(|this, b| { this.writer.write(['~' as u8]); this.write_unboxed_vec_repr(mtbl, &b.data, inner); - } + }) } fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - do self.get::> |this, s| { + self.get::>(|this, s| { this.writer.write(['&' as u8]); this.write_mut_qualifier(mtbl); let size = unsafe { if (*inner).size == 0 { 1 } else { (*inner).size } }; this.write_vec_range(s.data, s.len * size, inner); - } + }) } fn visit_evec_fixed(&mut self, n: uint, sz: uint, _align: uint, _: uint, inner: *TyDesc) -> bool { let assumed_size = if sz == 0 { n } else { sz }; - do self.get::<()> |this, b| { + self.get::<()>(|this, b| { this.write_vec_range(ptr::to_unsafe_ptr(b), assumed_size, inner); - } + }) } fn visit_enter_rec(&mut self, _n_fields: uint, @@ -600,10 +598,10 @@ impl<'self> TyVisitor for ReprVisitor<'self> { fn visit_opaque_box(&mut self) -> bool { self.writer.write(['@' as u8]); - do self.get::<&raw::Box<()>> |this, b| { + self.get::<&raw::Box<()>>(|this, b| { let p = ptr::to_unsafe_ptr(&b.data) as *c_void; this.visit_ptr_inner(p, b.type_desc); - } + }) } fn visit_closure_ptr(&mut self, _ck: uint) -> bool { true } diff --git a/src/libstd/rt/basic.rs b/src/libstd/rt/basic.rs index 2c1c5d84be154..d857f39ceaf0a 100644 --- a/src/libstd/rt/basic.rs +++ b/src/libstd/rt/basic.rs @@ -71,13 +71,13 @@ impl BasicLoop { fn remote_work(&mut self) { let messages = unsafe { - do self.messages.with |messages| { + self.messages.with(|messages| { if messages.len() > 0 { Some(util::replace(messages, ~[])) } else { None } - } + }) }; let messages = match messages { Some(m) => m, None => return @@ -139,11 +139,11 @@ impl EventLoop for BasicLoop { unsafe { // We block here if we have no messages to process and we may // receive a message at a later date - do self.messages.hold_and_wait |messages| { + self.messages.hold_and_wait(|messages| { self.remotes.len() > 0 && messages.len() == 0 && self.work.len() == 0 - } + }) } } } @@ -189,9 +189,9 @@ impl BasicRemote { impl RemoteCallback for BasicRemote { fn fire(&mut self) { unsafe { - do self.queue.hold_and_signal |queue| { + self.queue.hold_and_signal(|queue| { queue.push(RunRemote(self.id)); - } + }) } } } @@ -199,9 +199,9 @@ impl RemoteCallback for BasicRemote { impl Drop for BasicRemote { fn drop(&mut self) { unsafe { - do self.queue.hold_and_signal |queue| { + self.queue.hold_and_signal(|queue| { queue.push(RemoveRemote(self.id)); - } + }) } } } diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index 2c78a32a4b6cb..30c2264bd8697 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -35,9 +35,7 @@ pub struct BorrowRecord { } fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> { - do Local::borrow |task: &mut Task| { - task.borrow_list.take() - } + Local::borrow(|task: &mut Task| task.borrow_list.take()) } fn swap_task_borrow_list(f: |~[BorrowRecord]| -> ~[BorrowRecord]) { @@ -47,9 +45,7 @@ fn swap_task_borrow_list(f: |~[BorrowRecord]| -> ~[BorrowRecord]) { }; let borrows = f(borrows); let borrows = Cell::new(borrows); - do Local::borrow |task: &mut Task| { - task.borrow_list = Some(borrows.take()); - } + Local::borrow(|task: &mut Task| task.borrow_list = Some(borrows.take())) } pub fn clear_task_borrow_list() { @@ -64,9 +60,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> match try_take_task_borrow_list() { None => { // not recording borrows let msg = "borrowed"; - do msg.with_c_str |msg_p| { - task::begin_unwind_raw(msg_p, file, line); - } + msg.with_c_str(|msg_p| task::begin_unwind_raw(msg_p, file, line)) } Some(borrow_list) => { // recording borrows let mut msg = ~"borrowed"; @@ -80,9 +74,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> sep = " and at "; } } - do msg.with_c_str |msg_p| { - task::begin_unwind_raw(msg_p, file, line) - } + msg.with_c_str(|msg_p| task::begin_unwind_raw(msg_p, file, line)) } } } @@ -158,33 +150,35 @@ pub unsafe fn record_borrow(a: *u8, old_ref_count: uint, // was not borrowed before let a = a as *mut raw::Box<()>; debug_borrow("record_borrow:", a, old_ref_count, 0, file, line); - do swap_task_borrow_list |borrow_list| { + swap_task_borrow_list(|borrow_list| { let mut borrow_list = borrow_list; borrow_list.push(BorrowRecord {box: a, file: file, line: line}); borrow_list - } + }) } } -pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint, - file: *c_char, line: size_t) { +pub unsafe fn unrecord_borrow(a: *u8, + old_ref_count: uint, + file: *c_char, + line: size_t) { if (old_ref_count & ALL_BITS) == 0 { // was not borrowed before, so we should find the record at // the end of the list let a = a as *mut raw::Box<()>; debug_borrow("unrecord_borrow:", a, old_ref_count, 0, file, line); - do swap_task_borrow_list |borrow_list| { + swap_task_borrow_list(|borrow_list| { let mut borrow_list = borrow_list; assert!(!borrow_list.is_empty()); let br = borrow_list.pop(); if br.box != a || br.file != file || br.line != line { let err = format!("wrong borrow found, br={:?}", br); - do err.with_c_str |msg_p| { + err.with_c_str(|msg_p| { task::begin_unwind_raw(msg_p, file, line) - } + }) } borrow_list - } + }) } } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 8635f9372c472..e3e425f620bd1 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -165,14 +165,14 @@ impl ChanOne { // Port is blocked. Wake it up. let recvr = BlockedTask::cast_from_uint(task_as_state); if do_resched { - do recvr.wake().map |woken_task| { + recvr.wake().map(|woken_task| { Scheduler::run_task(woken_task); - }; + }); } else { let recvr = Cell::new(recvr); - do Local::borrow |sched: &mut Scheduler| { + Local::borrow(|sched: &mut Scheduler| { sched.enqueue_blocked_task(recvr.take()); - } + }) } } } @@ -209,9 +209,9 @@ impl PortOne { // No data available yet. // Switch to the scheduler to put the ~Task into the Packet state. let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |sched, task| { + sched.deschedule_running_task_and_then(|sched, task| { self.block_on(sched, task); - } + }) } // Task resumes. @@ -230,9 +230,9 @@ impl SelectInner for PortOne { // The optimistic check is never necessary for correctness. For testing // purposes, making it randomly return false simulates a racing sender. use rand::{Rand}; - let actually_check = do Local::borrow |sched: &mut Scheduler| { + let actually_check = Local::borrow(|sched: &mut Scheduler| { Rand::rand(&mut sched.rng) - }; + }); if actually_check { unsafe { (*self.packet()).state.load(Acquire) == STATE_ONE } } else { @@ -387,9 +387,9 @@ impl Drop for ChanOne { // The port is blocked waiting for a message we will never send. Wake it. rtassert!((*self.packet()).payload.is_none()); let recvr = BlockedTask::cast_from_uint(task_as_state); - do recvr.wake().map |woken_task| { + recvr.wake().map(|woken_task| { Scheduler::run_task(woken_task); - }; + }); } } } @@ -491,7 +491,7 @@ impl GenericPort for Port { fn try_recv(&self) -> Option { let mut b = self.next.borrow_mut(); - do b.get().take().map_default(None) |pone| { + b.get().take().map_default(None, |pone| { match pone.try_recv() { Some(StreamPayload { val, next }) => { *b.get() = Some(next); @@ -499,7 +499,7 @@ impl GenericPort for Port { } None => None } - } + }) } } @@ -516,7 +516,7 @@ impl Peekable for Port { impl<'self, T: Send> SelectInner for &'self Port { #[inline] fn optimistic_check(&mut self) -> bool { - do self.next.with_mut |pone| { pone.get_mut_ref().optimistic_check() } + self.next.with_mut(|pone| { pone.get_mut_ref().optimistic_check() }) } #[inline] @@ -527,7 +527,7 @@ impl<'self, T: Send> SelectInner for &'self Port { #[inline] fn unblock_from(&mut self) -> bool { - do self.next.with_mut |pone| { pone.get_mut_ref().unblock_from() } + self.next.with_mut(|pone| { pone.get_mut_ref().unblock_from() }) } } @@ -871,7 +871,7 @@ mod test { #[test] fn oneshot_multi_thread_close_stress() { if util::limit_thread_creation_due_to_osx_and_valgrind() { return; } - do stress_factor().times { + stress_factor().times(|| { do run_in_newsched_task { let (port, chan) = oneshot::(); let port_cell = Cell::new(port); @@ -881,13 +881,13 @@ mod test { let _chan = chan; thread.join(); } - } + }) } #[test] fn oneshot_multi_thread_send_close_stress() { if util::limit_thread_creation_due_to_osx_and_valgrind() { return; } - do stress_factor().times { + stress_factor().times(|| { do run_in_newsched_task { let (port, chan) = oneshot::(); let chan_cell = Cell::new(chan); @@ -902,13 +902,13 @@ mod test { thread1.join(); thread2.join(); } - } + }) } #[test] fn oneshot_multi_thread_recv_close_stress() { if util::limit_thread_creation_due_to_osx_and_valgrind() { return; } - do stress_factor().times { + stress_factor().times(|| { do run_in_newsched_task { let (port, chan) = oneshot::(); let chan_cell = Cell::new(chan); @@ -929,13 +929,13 @@ mod test { thread1.join(); thread2.join(); } - } + }) } #[test] fn oneshot_multi_thread_send_recv_stress() { if util::limit_thread_creation_due_to_osx_and_valgrind() { return; } - do stress_factor().times { + stress_factor().times(|| { do run_in_newsched_task { let (port, chan) = oneshot::<~int>(); let chan_cell = Cell::new(chan); @@ -949,13 +949,13 @@ mod test { thread1.join(); thread2.join(); } - } + }) } #[test] fn stream_send_recv_stress() { if util::limit_thread_creation_due_to_osx_and_valgrind() { return; } - do stress_factor().times { + stress_factor().times(|| { do run_in_mt_newsched_task { let (port, chan) = stream::<~int>(); @@ -984,17 +984,17 @@ mod test { }; } } - } + }) } #[test] fn recv_a_lot() { // Regression test that we don't run out of stack in scheduler context - do run_in_newsched_task { + run_in_newsched_task(|| { let (port, chan) = stream(); - do 10000.times { chan.send(()) } - do 10000.times { port.recv() } - } + 10000.times(|| { chan.send(()) }); + 10000.times(|| { port.recv() }); + }) } #[test] @@ -1004,16 +1004,16 @@ mod test { let (port, chan) = stream(); let chan = SharedChan::new(chan); let total = stress_factor() + 100; - do total.times { + total.times(|| { let chan_clone = chan.clone(); do spawntask_random { chan_clone.send(()); } - } + }); - do total.times { + total.times(|| { port.recv(); - } + }) } } @@ -1026,22 +1026,22 @@ mod test { let end_chan = SharedChan::new(end_chan); let port = SharedPort::new(port); let total = stress_factor() + 100; - do total.times { + total.times(|| { let end_chan_clone = end_chan.clone(); let port_clone = port.clone(); do spawntask_random { port_clone.recv(); end_chan_clone.send(()); } - } + }); - do total.times { + total.times(|| { chan.send(()); - } + }); - do total.times { + total.times(|| { end_port.recv(); - } + }) } } @@ -1066,29 +1066,29 @@ mod test { let send_total = 10; let recv_total = 20; do spawntask_random { - do send_total.times { + send_total.times(|| { let chan_clone = chan.clone(); do spawntask_random { chan_clone.send(()); } - } + }) } let end_chan_clone = end_chan.clone(); do spawntask_random { - do recv_total.times { + recv_total.times(|| { let port_clone = port.clone(); let end_chan_clone = end_chan_clone.clone(); do spawntask_random { let recvd = port_clone.try_recv().is_some(); end_chan_clone.send(recvd); } - } + }) } let mut recvd = 0; - do recv_total.times { + recv_total.times(|| { recvd += if end_port.recv() { 1 } else { 0 }; - } + }); assert!(recvd == send_total); } @@ -1107,7 +1107,7 @@ mod test { let pipe = megapipe(); let total = stress_factor() + 10; let mut rng = rand::rng(); - do total.times { + total.times(|| { let msgs = rng.gen_range(0u, 10); let pipe_clone = pipe.clone(); let end_chan_clone = end_chan.clone(); @@ -1121,11 +1121,11 @@ mod test { } end_chan_clone.send(()); - } + }); - do total.times { + total.times(|| { end_port.recv(); - } + }) } } @@ -1152,13 +1152,13 @@ mod test { let cs = Cell::new((cone, cstream, cshared, mp)); unsafe { - do atomically { + atomically(|| { let (cone, cstream, cshared, mp) = cs.take(); cone.send_deferred(()); cstream.send_deferred(()); cshared.send_deferred(()); mp.send_deferred(()); - } + }) } } } diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index ac13b12c9addd..56c77ffaa0d37 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -257,10 +257,7 @@ impl Death { /// Collect failure exit codes from children and propagate them to a parent. pub fn collect_failure(&mut self, result: UnwindResult) { let result = Cell::new(result); - - do self.on_exit.take().map |on_exit| { - on_exit(result.take()); - }; + self.on_exit.take().map(|on_exit| on_exit(result.take())); } /// Enter a possibly-nested "atomic" section of code. Just for assertions. diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index d47dae96283a6..23345926543c0 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -34,10 +34,10 @@ impl Local for Task { let mut res: Option = None; let res_ptr: *mut Option = &mut res; unsafe { - do local_ptr::borrow |task| { + local_ptr::borrow(|task| { let result = f(task); *res_ptr = Some(result); - } + }) } match res { Some(r) => { r } @@ -57,10 +57,10 @@ impl Local for Task { impl Local for Scheduler { fn put(value: ~Scheduler) { let value = Cell::new(value); - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { let task = task; task.sched = Some(value.take()); - }; + }); } #[inline] fn take() -> ~Scheduler { @@ -71,15 +71,15 @@ impl Local for Scheduler { } } fn exists(_: Option) -> bool { - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { match task.sched { Some(ref _task) => true, None => false } - } + }) } fn borrow(f: |&mut Scheduler| -> T) -> T { - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { match task.sched { Some(~ref mut task) => { f(task) @@ -88,7 +88,7 @@ impl Local for Scheduler { rtabort!("no scheduler") } } - } + }) } unsafe fn unsafe_take() -> ~Scheduler { rtabort!("unimpl") } unsafe fn unsafe_borrow() -> *mut Scheduler { diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index d5ec6bd3f370e..a7805a9f55925 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -302,9 +302,7 @@ pub unsafe fn local_free(ptr: *libc::c_char) { } pub fn live_allocs() -> *mut Box { - do Local::borrow |task: &mut Task| { - task.heap.live_allocs - } + Local::borrow(|task: &mut Task| task.heap.live_allocs) } #[cfg(test)] @@ -313,15 +311,11 @@ mod bench { #[bench] fn alloc_managed_small(bh: &mut BenchHarness) { - do bh.iter { - @10; - } + bh.iter(|| @10); } #[bench] fn alloc_managed_big(bh: &mut BenchHarness) { - do bh.iter { - @[10, ..1000]; - } + bh.iter(|| @[10, ..1000]); } } diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 862ecd6499a50..eb7d8ef2f5fe2 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -110,11 +110,7 @@ pub unsafe fn borrow(f: |&mut T|) { let unsafe_ptr = cast::transmute_mut_region(&mut *value); let value_cell = Cell::new(value); - do (|| { - f(unsafe_ptr); - }).finally { - put(value_cell.take()); - } + (|| f(unsafe_ptr)).finally(|| put(value_cell.take())); } /// Borrow a mutable reference to the thread-local value diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 2ca47dbff59dc..13e18f7d9b75e 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -142,19 +142,17 @@ fn update_log_settings(crate_map: &CrateMap, settings: ~str) { if settings.len() > 0 { if settings == ~"::help" || settings == ~"?" { rterrln!("\nCrate log map:\n"); - do iter_crate_map(crate_map) |entry| { - rterrln!(" {}", entry.name); - } + iter_crate_map(crate_map, |entry| rterrln!(" {}", entry.name)); unsafe { exit(1); } } dirs = parse_logging_spec(settings); } let mut n_matches: u32 = 0; - do iter_crate_map(crate_map) |entry| { + iter_crate_map(crate_map, |entry| { let m = update_entry(dirs, entry); n_matches += m; - } + }); if n_matches < (dirs.len() as u32) { rterrln!("warning: got {} RUST_LOG specs but only matched\n\ diff --git a/src/libstd/rt/mpmc_bounded_queue.rs b/src/libstd/rt/mpmc_bounded_queue.rs index 2f61a4339833a..7f607fcf12a63 100644 --- a/src/libstd/rt/mpmc_bounded_queue.rs +++ b/src/libstd/rt/mpmc_bounded_queue.rs @@ -68,9 +68,9 @@ impl State { } else { capacity }; - let buffer = do vec::from_fn(capacity) |i:uint| { + let buffer = vec::from_fn(capacity, |i:uint| { Node{sequence:AtomicUint::new(i),value:None} - }; + }); State{ pad0: [0, ..64], buffer: buffer, diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 1caaf77bd9671..519274bb131cf 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -236,9 +236,9 @@ impl Scheduler { // Our scheduler must be in the task before the event loop // is started. let self_sched = Cell::new(self); - do Local::borrow |stask: &mut Task| { + Local::borrow(|stask: &mut Task| { stask.sched = Some(self_sched.take()); - }; + }); (*event_loop).run(); } @@ -538,9 +538,7 @@ impl Scheduler { /// As enqueue_task, but with the possibility for the blocked task to /// already have been killed. pub fn enqueue_blocked_task(&mut self, blocked_task: BlockedTask) { - do blocked_task.wake().map |task| { - self.enqueue_task(task); - }; + blocked_task.wake().map(|task| self.enqueue_task(task)); } // * Core Context Switching Functions @@ -643,9 +641,9 @@ impl Scheduler { // * Context Swapping Helpers - Here be ugliness! pub fn resume_task_immediately(~self, task: ~Task) { - do self.change_task_context(task) |sched, stask| { + self.change_task_context(task, |sched, stask| { sched.sched_task = Some(stask); - } + }) } fn resume_task_immediately_cl(sched: ~Scheduler, @@ -686,15 +684,15 @@ impl Scheduler { f: |&mut Scheduler, BlockedTask|) { // This is where we convert the BlockedTask-taking closure into one // that takes just a Task - do self.change_task_context(next_task) |sched, task| { + self.change_task_context(next_task, |sched, task| { f(sched, BlockedTask::block(task)) - } + }) } fn switch_task(sched: ~Scheduler, task: ~Task) { - do sched.switch_running_tasks_and_then(task) |sched, last_task| { + sched.switch_running_tasks_and_then(task, |sched, last_task| { sched.enqueue_blocked_task(last_task); - }; + }); } // * Task Context Helpers @@ -705,10 +703,10 @@ impl Scheduler { // Similar to deschedule running task and then, but cannot go through // the task-blocking path. The task is already dying. let stask = self.sched_task.take_unwrap(); - do self.change_task_context(stask) |sched, mut dead_task| { + self.change_task_context(stask, |sched, mut dead_task| { let coroutine = dead_task.coroutine.take_unwrap(); coroutine.recycle(&mut sched.stack_pool); - } + }) } pub fn run_task(task: ~Task) { @@ -718,9 +716,9 @@ impl Scheduler { pub fn run_task_later(next_task: ~Task) { let next_task = Cell::new(next_task); - do Local::borrow |sched: &mut Scheduler| { + Local::borrow(|sched: &mut Scheduler| { sched.enqueue_task(next_task.take()); - }; + }); } /// Yield control to the scheduler, executing another task. This is guaranteed @@ -731,9 +729,9 @@ impl Scheduler { self.yield_check_count = reset_yield_check(&mut self.rng); // Tell the scheduler to start stealing on the next iteration self.steal_for_yield = true; - do self.deschedule_running_task_and_then |sched, task| { + self.deschedule_running_task_and_then(|sched, task| { sched.enqueue_blocked_task(task); - } + }) } pub fn maybe_yield(mut ~self) { @@ -852,9 +850,9 @@ fn new_sched_rng() -> XorShiftRng { use iter::Iterator; use rand::SeedableRng; - let fd = do "/dev/urandom".with_c_str |name| { + let fd = "/dev/urandom".with_c_str(|name| { unsafe { libc::open(name, libc::O_RDONLY, 0) } - }; + }); if fd == -1 { rtabort!("could not open /dev/urandom for reading.") } @@ -862,13 +860,13 @@ fn new_sched_rng() -> XorShiftRng { let mut seeds = [0u32, .. 4]; let size = mem::size_of_val(&seeds); loop { - let nbytes = do seeds.as_mut_buf |buf, _| { + let nbytes = seeds.as_mut_buf(|buf, _| { unsafe { libc::read(fd, buf as *mut libc::c_void, size as libc::size_t) } - }; + }); rtassert!(nbytes as uint == size); if !seeds.iter().all(|x| *x == 0) { diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index bc9496b16cde1..569d96ae388d3 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -142,7 +142,7 @@ impl Task { -> ~Task { let f = Cell::new(f); let home = Cell::new(home); - do Local::borrow |running_task: &mut Task| { + Local::borrow(|running_task: &mut Task| { let mut sched = running_task.sched.take_unwrap(); let new_task = ~running_task.new_child_homed(&mut sched.stack_pool, stack_size, @@ -150,7 +150,7 @@ impl Task { f.take()); running_task.sched = Some(sched); new_task - } + }) } pub fn build_child(stack_size: Option, f: proc()) -> ~Task { @@ -163,7 +163,7 @@ impl Task { -> ~Task { let f = Cell::new(f); let home = Cell::new(home); - do Local::borrow |running_task: &mut Task| { + Local::borrow(|running_task: &mut Task| { let mut sched = running_task.sched.take_unwrap(); let new_task = ~Task::new_root_homed(&mut sched.stack_pool, stack_size, @@ -171,7 +171,7 @@ impl Task { f.take()); running_task.sched = Some(sched); new_task - } + }) } pub fn build_root(stack_size: Option, f: proc()) -> ~Task { @@ -280,10 +280,10 @@ impl Task { // The only try/catch block in the world. Attempt to run the task's // client-specified code and catch any failures. - do self.unwinder.try { + self.unwinder.try(|| { // Run the task main function, then do some cleanup. - do f.finally { + f.finally(|| { // First, destroy task-local storage. This may run user dtors. // @@ -320,8 +320,8 @@ impl Task { None => {} } self.logger.take(); - } - } + }) + }); // Cleanup the dynamic borrowck debugging info borrowck::clear_task_borrow_list(); @@ -364,7 +364,7 @@ impl Task { // Grab both the scheduler and the task from TLS and check if the // task is executing on an appropriate scheduler. pub fn on_appropriate_sched() -> bool { - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { let sched_id = task.sched.get_ref().sched_id(); let sched_run_anything = task.sched.get_ref().run_anything; match task.task_type { @@ -383,7 +383,7 @@ impl Task { rtabort!("type error: expected: GreenTask, found: SchedTask"); } } - } + }) } } @@ -431,9 +431,9 @@ impl Coroutine { unsafe { // Again - might work while safe, or it might not. - do Local::borrow |sched: &mut Scheduler| { + Local::borrow(|sched: &mut Scheduler| { sched.run_cleanup_job(); - } + }); // To call the run method on a task we need a direct // reference to it. The task is in TLS, so we can @@ -442,7 +442,7 @@ impl Coroutine { // need to unsafe_borrow. let task: *mut Task = Local::unsafe_borrow(); - do (*task).run { + (*task).run(|| { // N.B. Removing `start` from the start wrapper // closure by emptying a cell is critical for // correctness. The ~Task pointer, and in turn the @@ -455,7 +455,7 @@ impl Coroutine { // scope while the task is still running. let start = start_cell.take(); start(); - }; + }); } // We remove the sched from the Task in TLS right now. @@ -584,7 +584,7 @@ pub extern "C" fn rust_stack_exhausted() { // #2361 - possible implementation of not using landing pads if in_green_task_context() { - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or(""); // See the message below for why this is not emitted to the @@ -593,7 +593,7 @@ pub extern "C" fn rust_stack_exhausted() { // call would happen to initialized it (calling out to libuv), // and the FFI call needs 2MB of stack when we just ran out. rterrln!("task '{}' has overflowed its stack", n); - } + }) } else { rterrln!("stack overflow in non-task context"); } diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index 16fd3fa38eae9..360764daf156c 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -68,9 +68,9 @@ impl Tube { assert!(self.p.refcount() > 1); // There better be somebody to wake us up assert!((*state).blocked_task.is_none()); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |_, task| { + sched.deschedule_running_task_and_then(|_, task| { (*state).blocked_task = Some(task); - } + }); rtdebug!("waking after tube recv"); let buf = &mut (*state).buf; assert!(!buf.is_empty()); diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index 24792f3904e51..02ea8ab4f5037 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -37,25 +37,25 @@ impl WorkQueue { pub fn pop(&mut self) -> Option { unsafe { - do self.queue.with |q| { + self.queue.with(|q| { if !q.is_empty() { Some(q.shift()) } else { None } - } + }) } } pub fn steal(&mut self) -> Option { unsafe { - do self.queue.with |q| { + self.queue.with(|q| { if !q.is_empty() { Some(q.pop()) } else { None } - } + }) } } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 5b3ba1e6f97f8..7f977fdd2a39f 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -221,20 +221,20 @@ impl Process { let ch_clone = ch.clone(); do spawn { - do io::ignore_io_error { + io::ignore_io_error(|| { match error.take() { Some(ref mut e) => ch.send((2, e.read_to_end())), None => ch.send((2, ~[])) } - } + }) } do spawn { - do io::ignore_io_error { + io::ignore_io_error(|| { match output.take() { Some(ref mut e) => ch_clone.send((1, e.read_to_end())), None => ch_clone.send((1, ~[])) } - } + }) } let status = self.finish(); diff --git a/src/libstd/select.rs b/src/libstd/select.rs index 25f8c5a287514..b619085e20180 100644 --- a/src/libstd/select.rs +++ b/src/libstd/select.rs @@ -59,10 +59,10 @@ pub fn select(ports: &mut [A]) -> uint { let p = Cell::new(p); let c = Cell::new(c); - do (|| { + (|| { let c = Cell::new(c.take()); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |sched, task| { + sched.deschedule_running_task_and_then(|sched, task| { let task_handles = task.make_selectable(ports.len()); for (index, (port, task_handle)) in @@ -77,12 +77,12 @@ pub fn select(ports: &mut [A]) -> uint { let c = Cell::new(c.take()); do sched.event_loop.callback { c.take().send_deferred(()) } } - }).finally { + }).finally(|| { // Unkillable is necessary not because getting killed is dangerous here, // but to force the recv not to use the same kill-flag that we used for // selecting. Otherwise a user-sender could spuriously wakeup us here. p.take().recv(); - } + }); // Task resumes. Now unblock ourselves from all the ports we blocked on. // If the success index wasn't reset, 'take' will just take all of them. diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 11f552e73ae7e..b2ded6ab7541e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -410,11 +410,11 @@ impl<'self> Iterator<(uint, char)> for CharOffsetIterator<'self> { fn next(&mut self) -> Option<(uint, char)> { // Compute the byte offset by using the pointer offset between // the original string slice and the iterator's remaining part - let offset = do self.string.as_imm_buf |a, _| { - do self.iter.string.as_imm_buf |b, _| { + let offset = self.string.as_imm_buf(|a, _| { + self.iter.string.as_imm_buf(|b, _| { b as uint - a as uint - } - }; + }) + }); self.iter.next().map(|ch| (offset, ch)) } @@ -428,11 +428,11 @@ impl<'self> DoubleEndedIterator<(uint, char)> for CharOffsetIterator<'self> { #[inline] fn next_back(&mut self) -> Option<(uint, char)> { self.iter.next_back().map(|ch| { - let offset = do self.string.as_imm_buf |a, _| { - do self.iter.string.as_imm_buf |b, len| { + let offset = self.string.as_imm_buf(|a, _| { + self.iter.string.as_imm_buf(|b, len| { b as uint - a as uint + len - } - }; + }) + }); (offset, ch) }) } @@ -716,14 +716,14 @@ impl<'self> Iterator for NormalizationIterator<'self> { if !self.sorted { for ch in self.iter { - do decomposer(ch) |d| { + decomposer(ch, |d| { let class = canonical_combining_class(d); if class == 0 && !self.sorted { canonical_sort(self.buffer); self.sorted = true; } self.buffer.push((d, class)); - } + }); if self.sorted { break } } } @@ -781,8 +781,8 @@ Section: Comparing strings #[lang="str_eq"] #[inline] pub fn eq_slice(a: &str, b: &str) -> bool { - do a.as_imm_buf |ap, alen| { - do b.as_imm_buf |bp, blen| { + a.as_imm_buf(|ap, alen| { + b.as_imm_buf(|bp, blen| { if (alen != blen) { false } else { unsafe { @@ -791,16 +791,16 @@ pub fn eq_slice(a: &str, b: &str) -> bool { alen as libc::size_t) == 0 } } - } - } + }) + }) } /// Bytewise slice equality #[cfg(test)] #[inline] pub fn eq_slice(a: &str, b: &str) -> bool { - do a.as_imm_buf |ap, alen| { - do b.as_imm_buf |bp, blen| { + a.as_imm_buf(|ap, alen| { + b.as_imm_buf(|bp, blen| { if (alen != blen) { false } else { unsafe { @@ -809,8 +809,8 @@ pub fn eq_slice(a: &str, b: &str) -> bool { alen as libc::size_t) == 0 } } - } - } + }) + }) } /// Bytewise string equality @@ -1029,9 +1029,7 @@ pub mod raw { /// Create a Rust string from a *u8 buffer of the given length pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str { let mut v: ~[u8] = vec::with_capacity(len); - do v.as_mut_buf |vbuf, _len| { - ptr::copy_memory(vbuf, buf as *u8, len) - }; + v.as_mut_buf(|vbuf, _len| ptr::copy_memory(vbuf, buf as *u8, len)); vec::raw::set_len(&mut v, len); assert!(is_utf8(v)); @@ -1059,9 +1057,7 @@ pub mod raw { /// Converts a vector of bytes to a new owned string. pub unsafe fn from_utf8(v: &[u8]) -> ~str { - do v.as_imm_buf |buf, len| { - from_buf_len(buf, len) - } + v.as_imm_buf(|buf, len| from_buf_len(buf, len)) } /// Converts an owned vector of bytes to a new owned string. This assumes @@ -1112,12 +1108,12 @@ pub mod raw { /// Caller must check slice boundaries! #[inline] pub unsafe fn slice_unchecked<'a>(s: &'a str, begin: uint, end: uint) -> &'a str { - do s.as_imm_buf |sbuf, _n| { + s.as_imm_buf(|sbuf, _n| { cast::transmute(Slice { data: sbuf.offset(begin as int), len: end - begin, }) - } + }) } /// Appends a byte to a string. @@ -1351,7 +1347,7 @@ impl<'self> Str for @str { impl<'self> Container for &'self str { #[inline] fn len(&self) -> uint { - do self.as_imm_buf |_p, n| { n } + self.as_imm_buf(|_p, n| n) } } @@ -1876,11 +1872,11 @@ impl<'self> StrSlice<'self> for &'self str { } fn lines_any(&self) -> AnyLineIterator<'self> { - do self.lines().map |line| { + self.lines().map(|line| { let l = line.len(); if l > 0 && line[l - 1] == '\r' as u8 { line.slice(0, l - 1) } else { line } - } + }) } #[inline] @@ -1973,9 +1969,7 @@ impl<'self> StrSlice<'self> for &'self str { let mut out: ~str = ~""; out.reserve_at_least(self.len()); for c in self.chars() { - do c.escape_default |c| { - out.push_char(c); - } + c.escape_default(|c| out.push_char(c)); } out } @@ -1984,9 +1978,7 @@ impl<'self> StrSlice<'self> for &'self str { let mut out: ~str = ~""; out.reserve_at_least(self.len()); for c in self.chars() { - do c.escape_unicode |c| { - out.push_char(c); - } + c.escape_unicode(|c| out.push_char(c)); } out } @@ -2044,17 +2036,15 @@ impl<'self> StrSlice<'self> for &'self str { #[inline] fn to_owned(&self) -> ~str { - do self.as_imm_buf |src, len| { + self.as_imm_buf(|src, len| { unsafe { let mut v = vec::with_capacity(len); - do v.as_mut_buf |dst, _| { - ptr::copy_memory(dst, src, len); - } + v.as_mut_buf(|dst, _| ptr::copy_memory(dst, src, len)); vec::raw::set_len(&mut v, len); ::cast::transmute(v) } - } + }) } #[inline] @@ -2250,8 +2240,8 @@ impl<'self> StrSlice<'self> for &'self str { } fn subslice_offset(&self, inner: &str) -> uint { - do self.as_imm_buf |a, a_len| { - do inner.as_imm_buf |b, b_len| { + self.as_imm_buf(|a, a_len| { + inner.as_imm_buf(|b, b_len| { let a_start: uint; let a_end: uint; let b_start: uint; @@ -2263,8 +2253,8 @@ impl<'self> StrSlice<'self> for &'self str { assert!(a_start <= b_start); assert!(b_end <= a_end); b_start - a_start - } - } + }) + }) } #[inline] @@ -2382,11 +2372,11 @@ impl OwnedStr for ~str { // Attempt to not use an intermediate buffer by just pushing bytes // directly onto this string. - let used = do self.as_mut_buf |buf, _| { - do vec::raw::mut_buf_as_slice(buf.offset(cur_len as int), 4) |slc| { + let used = self.as_mut_buf(|buf, _| { + vec::raw::mut_buf_as_slice(buf.offset(cur_len as int), 4, |slc| { c.encode_utf8(slc) - } - }; + }) + }); raw::set_len(self, cur_len + used); } } @@ -3156,13 +3146,11 @@ mod tests { 0x6d_u8]; let mut error_happened = false; - let _x = do cond.trap(|err| { + let _x = cond.trap(|err| { assert_eq!(err, ~"from_utf8: input is not UTF-8; first bad byte is 255"); error_happened = true; ~"" - }).inside { - from_utf8(bb) - }; + }).inside(|| from_utf8(bb)); assert!(error_happened); } @@ -3201,11 +3189,9 @@ mod tests { #[test] fn test_as_imm_buf() { - do "".as_imm_buf |_, len| { - assert_eq!(len, 0); - } + "".as_imm_buf(|_, len| assert_eq!(len, 0)); - do "hello".as_imm_buf |buf, len| { + "hello".as_imm_buf(|buf, len| { assert_eq!(len, 5); unsafe { assert_eq!(*ptr::offset(buf, 0), 'h' as u8); @@ -3214,7 +3200,7 @@ mod tests { assert_eq!(*ptr::offset(buf, 3), 'l' as u8); assert_eq!(*ptr::offset(buf, 4), 'o' as u8); } - } + }) } #[test] @@ -3864,9 +3850,7 @@ mod bench { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); - do bh.iter { - assert_eq!(s.chars().len(), len); - } + bh.iter(|| assert_eq!(s.chars().len(), len)); } #[bench] @@ -3879,9 +3863,7 @@ mod bench { Mary had a little lamb, Little lamb"; let len = s.char_len(); - do bh.iter { - assert_eq!(s.chars().len(), len); - } + bh.iter(|| assert_eq!(s.chars().len(), len)); } #[bench] @@ -3889,9 +3871,7 @@ mod bench { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); - do bh.iter { - assert_eq!(s.chars_rev().len(), len); - } + bh.iter(|| assert_eq!(s.chars_rev().len(), len)); } #[bench] @@ -3899,9 +3879,7 @@ mod bench { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); - do bh.iter { - assert_eq!(s.char_indices().len(), len); - } + bh.iter(|| assert_eq!(s.char_indices().len(), len)); } #[bench] @@ -3909,18 +3887,14 @@ mod bench { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let len = s.char_len(); - do bh.iter { - assert_eq!(s.char_indices_rev().len(), len); - } + bh.iter(|| assert_eq!(s.char_indices_rev().len(), len)); } #[bench] fn split_unicode_ascii(bh: &mut BenchHarness) { let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam"; - do bh.iter { - assert_eq!(s.split('V').len(), 3); - } + bh.iter(|| assert_eq!(s.split('V').len(), 3)); } #[bench] @@ -3934,9 +3908,7 @@ mod bench { } let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam"; - do bh.iter { - assert_eq!(s.split(NotAscii('V')).len(), 3); - } + bh.iter(|| assert_eq!(s.split(NotAscii('V')).len(), 3)); } @@ -3945,9 +3917,7 @@ mod bench { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').len(); - do bh.iter { - assert_eq!(s.split(' ').len(), len); - } + bh.iter(|| assert_eq!(s.split(' ').len(), len)); } #[bench] @@ -3961,9 +3931,7 @@ mod bench { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').len(); - do bh.iter { - assert_eq!(s.split(NotAscii(' ')).len(), len); - } + bh.iter(|| assert_eq!(s.split(NotAscii(' ')).len(), len)); } #[bench] @@ -3972,9 +3940,7 @@ mod bench { let len = s.split(' ').len(); fn pred(c: char) -> bool { c == ' ' } - do bh.iter { - assert_eq!(s.split(pred).len(), len); - } + bh.iter(|| assert_eq!(s.split(pred).len(), len)); } #[bench] @@ -3982,9 +3948,7 @@ mod bench { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').len(); - do bh.iter { - assert_eq!(s.split(|c: char| c == ' ').len(), len); - } + bh.iter(|| assert_eq!(s.split(|c: char| c == ' ').len(), len)); } #[bench] @@ -3992,9 +3956,7 @@ mod bench { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').len(); - do bh.iter { - assert_eq!(s.split(&[' ']).len(), len); - } + bh.iter(|| assert_eq!(s.split(&[' ']).len(), len)); } #[bench] @@ -4004,34 +3966,28 @@ mod bench { Lorem ipsum dolor sit amet, consectetur. "); assert_eq!(100, s.len()); - do bh.iter { - is_utf8(s); - } + bh.iter(|| is_utf8(s)); } #[bench] fn is_utf8_100_multibyte(bh: &mut BenchHarness) { let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰"); assert_eq!(100, s.len()); - do bh.iter { - is_utf8(s); - } + bh.iter(|| is_utf8(s)); } #[bench] fn bench_with_capacity(bh: &mut BenchHarness) { - do bh.iter { - with_capacity(100); - } + bh.iter(|| with_capacity(100)); } #[bench] fn bench_push_str(bh: &mut BenchHarness) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; - do bh.iter { + bh.iter(|| { let mut r = ~""; r.push_str(s); - } + }); } #[bench] @@ -4039,8 +3995,8 @@ mod bench { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; let sep = "→"; let v = [s, s, s, s, s, s, s, s, s, s]; - do bh.iter { + bh.iter(|| { assert_eq!(v.connect(sep).len(), s.len() * 10 + sep.len() * 9); - } + }) } } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 485fe9edf0eef..85f66d4ada827 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -432,12 +432,12 @@ pub fn with_task_name(blk: |Option<&str>| -> U) -> U { use rt::task::Task; if in_green_task_context() { - do Local::borrow |task: &mut Task| { + Local::borrow(|task: &mut Task| { match task.name { Some(ref name) => blk(Some(name.as_slice())), None => blk(None) } - } + }) } else { fail!("no task name exists in non-green task context") } @@ -459,9 +459,7 @@ pub fn failing() -> bool { use rt::task::Task; - do Local::borrow |local: &mut Task| { - local.unwinder.unwinding - } + Local::borrow(|local: &mut Task| local.unwinder.unwinding) } // The following 8 tests test the following 2^3 combinations: diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index ded7cd8df072b..d81fe0c2fbd8a 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -369,12 +369,12 @@ impl ToBytes for A { use io::mem; use io::Writer; - do mem::with_mem_writer |wr| { - do self.iter_bytes(lsb0) |bytes| { + mem::with_mem_writer(|wr| { + self.iter_bytes(lsb0, |bytes| { wr.write(bytes); true - }; - } + }); + }) } } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 9f5ee75208958..8b534d7d3bebe 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -489,7 +489,7 @@ pub struct TrieSetIterator<'self> { impl<'self> Iterator for TrieSetIterator<'self> { fn next(&mut self) -> Option { - do self.iter.next().map |(key, _)| { key } + self.iter.next().map(|(key, _)| key) } fn size_hint(&self) -> (uint, Option) { @@ -594,12 +594,12 @@ mod test_map { assert!(m.insert(1, 2)); let mut n = 0; - do m.each |k, v| { + m.each(|k, v| { assert_eq!(*k, n); assert_eq!(*v, n * 2); n += 1; true - }; + }); } #[test] @@ -611,7 +611,7 @@ mod test_map { } let mut n = uint::max_value - 10000; - do m.each |k, v| { + m.each(|k, v| { if n == uint::max_value - 5000 { false } else { assert!(n < uint::max_value - 5000); @@ -620,7 +620,7 @@ mod test_map { n += 1; true } - }; + }); } #[test] @@ -634,12 +634,12 @@ mod test_map { assert!(m.insert(1, 2)); let mut n = 4; - do m.each_reverse |k, v| { + m.each_reverse(|k, v| { assert_eq!(*k, n); assert_eq!(*v, n * 2); n -= 1; true - }; + }); } #[test] @@ -651,7 +651,7 @@ mod test_map { } let mut n = uint::max_value - 1; - do m.each_reverse |k, v| { + m.each_reverse(|k, v| { if n == uint::max_value - 5000 { false } else { assert!(n > uint::max_value - 5000); @@ -660,7 +660,7 @@ mod test_map { n -= 1; true } - }; + }); } #[test] @@ -777,11 +777,11 @@ mod test_set { let mut i = 0; - do trie.each |x| { + trie.each(|x| { assert_eq!(expected[i], *x); i += 1; true - }; + }); } #[test] diff --git a/src/libstd/unicode.rs b/src/libstd/unicode.rs index a8f56228dcb69..ac4bc5754fb18 100644 --- a/src/libstd/unicode.rs +++ b/src/libstd/unicode.rs @@ -19,11 +19,11 @@ pub mod general_category { use cmp::{Equal, Less, Greater}; use vec::ImmutableVector; use option::None; - (do r.bsearch |&(lo,hi)| { + (r.bsearch(|&(lo,hi)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } - }) != None + })) != None } @@ -3663,11 +3663,11 @@ pub mod derived_property { use cmp::{Equal, Less, Greater}; use vec::ImmutableVector; use option::None; - (do r.bsearch |&(lo,hi)| { + (r.bsearch(|&(lo,hi)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } - }) != None + })) != None } diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index cdfbf8c004991..2a6e40dc3a0df 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -27,11 +27,11 @@ pub struct DynamicLibrary { priv handle: *libc::c_void } impl Drop for DynamicLibrary { fn drop(&mut self) { - match do dl::check_for_errors_in { + match dl::check_for_errors_in(|| { unsafe { dl::close(self.handle) } - } { + }) { Ok(()) => {}, Err(str) => fail!("{}", str) } @@ -43,12 +43,12 @@ impl DynamicLibrary { /// handle to the calling process pub fn open(filename: Option<&path::Path>) -> Result { unsafe { - let maybe_library = do dl::check_for_errors_in { + let maybe_library = dl::check_for_errors_in(|| { match filename { Some(name) => dl::open_external(name), None => dl::open_internal() } - }; + }); // The dynamic library must not be constructed if there is // an error opening the library so the destructor does not @@ -65,11 +65,11 @@ impl DynamicLibrary { // This function should have a lifetime constraint of 'self on // T but that feature is still unimplemented - let maybe_symbol_value = do dl::check_for_errors_in { - do symbol.with_c_str |raw_string| { + let maybe_symbol_value = dl::check_for_errors_in(|| { + symbol.with_c_str(|raw_string| { dl::symbol(self.handle, raw_string) - } - }; + }) + }); // The value must not be constructed if there is an error so // the destructor does not run. @@ -144,9 +144,9 @@ pub mod dl { use result::*; pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void { - do filename.with_c_str |raw_name| { + filename.with_c_str(|raw_name| { dlopen(raw_name, Lazy as libc::c_int) - } + }) } pub unsafe fn open_internal() -> *libc::c_void { @@ -162,7 +162,7 @@ pub mod dl { // would cause this task to be descheduled, which could deadlock // the scheduler if it happens while the lock is held. // FIXME #9105 use a Rust mutex instead of C++ mutexes. - do atomically { + atomically(|| { lock.lock(); let _old_error = dlerror(); @@ -176,7 +176,7 @@ pub mod dl { }; lock.unlock(); ret - } + }) } } @@ -213,9 +213,9 @@ pub mod dl { use result::*; pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void { - do os::win32::as_utf16_p(filename.as_str().unwrap()) |raw_name| { + os::win32::as_utf16_p(filename.as_str().unwrap(), |raw_name| { LoadLibraryW(raw_name) - } + }) } pub unsafe fn open_internal() -> *libc::c_void { @@ -226,7 +226,7 @@ pub mod dl { pub fn check_for_errors_in(f: || -> T) -> Result { unsafe { - do atomically { + atomically(|| { SetLastError(0); let result = f(); @@ -237,7 +237,7 @@ pub mod dl { } else { Err(format!("Error code {}", error)) } - } + }) } } diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs index 092e9b6d348bc..06f9ba65ae773 100644 --- a/src/libstd/unstable/lang.rs +++ b/src/libstd/unstable/lang.rs @@ -27,9 +27,7 @@ pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) -> ! { let msg = format!("index out of bounds: the len is {} but the index is {}", len as uint, index as uint); - do msg.with_c_str |buf| { - fail_(buf, file, line); - } + msg.with_c_str(|buf| fail_(buf, file, line)) } #[lang="malloc"] diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index e80b58d01efb2..1f243d08243db 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -134,9 +134,8 @@ impl UnsafeArc { /// If called when the task is already unkillable, unwrap will unkillably /// block; otherwise, an unwrapping task can be killed by linked failure. pub fn unwrap(self) -> T { - let this = Cell::new(self); // argh unsafe { - let mut this = this.take(); + let mut this = this; // The ~ dtor needs to run if this code succeeds. let mut data: ~ArcData = cast::transmute(this.data); // Set up the unwrap protocol. @@ -164,7 +163,7 @@ impl UnsafeArc { // Unlike the above one, this cell is necessary. It will get // taken either in the do block or in the finally block. let c2_and_data = Cell::new((c2,data)); - do (|| { + (|| { p1.take().recv(); // Got here. Back in the 'unkillable' without getting killed. let (c2, data) = c2_and_data.take(); @@ -174,7 +173,7 @@ impl UnsafeArc { // user_data let mut data = data; data.data.take_unwrap() - }).finally { + }).finally(|| { if task::failing() { // Killed during wait. Because this might happen while // someone else still holds a reference, we can't free @@ -185,7 +184,7 @@ impl UnsafeArc { } else { assert!(c2_and_data.is_empty()); } - } + }) } } else { // If 'put' returns the server end back to us, we were rejected; @@ -193,7 +192,7 @@ impl UnsafeArc { cast::forget(data); fail!("Another task is already unwrapping this Arc!"); } - } + }) } /// As unwrap above, but without blocking. Returns 'UnsafeArcSelf(self)' if this is @@ -256,8 +255,6 @@ impl Drop for UnsafeArc{ // *awake* task with the data. match data.unwrapper.take(Acquire) { Some(~(message,response)) => { - let cell = Cell::new((message, response, data)); - let (message, response, data) = cell.take(); // Send 'ready' and wait for a response. message.send(()); // Unkillable wait. Message guaranteed to come. @@ -301,12 +298,10 @@ pub unsafe fn atomically(f: || -> U) -> U { Some(t) => { match (*t).task_type { GreenTask(_) => { - do (|| { + (|| { (*t).death.inhibit_deschedule(); f() - }).finally { - (*t).death.allow_deschedule(); - } + }).finally(|| (*t).death.allow_deschedule()) } SchedTask => f() } @@ -425,9 +420,7 @@ impl Exclusive { #[inline] pub unsafe fn with_imm(&self, f: |x: &T| -> U) -> U { - do self.with |x| { - f(cast::transmute_immut(x)) - } + self.with(|x| f(cast::transmute_immut(x))) } #[inline] @@ -469,7 +462,6 @@ impl Exclusive { #[cfg(test)] mod tests { - use cell::Cell; use comm; use option::*; use prelude::*; @@ -489,7 +481,7 @@ mod tests { fn test_atomically() { // NB. The whole runtime will abort on an 'atomic-sleep' violation, // so we can't really test for the converse behaviour. - unsafe { do atomically { } } task::deschedule(); // oughtn't fail + unsafe { atomically(|| ()) } task::deschedule(); // oughtn't fail } #[test] @@ -509,9 +501,7 @@ mod tests { do task::spawn || { for _ in range(0u, count) { - do total.with |count| { - **count += 1; - } + total.with(|count| **count += 1); } chan.send(()); } @@ -519,9 +509,7 @@ mod tests { for f in futures.iter() { f.recv() } - do total.with |total| { - assert!(**total == num_tasks * count) - }; + total.with(|total| assert!(**total == num_tasks * count)); } } @@ -533,13 +521,9 @@ mod tests { let x = Exclusive::new(1); let x2 = x.clone(); do task::try || { - do x2.with |one| { - assert_eq!(*one, 2); - } + x2.with(|one| assert_eq!(*one, 2)) }; - do x.with |one| { - assert_eq!(*one, 1); - } + x.with(|one| assert_eq!(*one, 1)); } } @@ -595,11 +579,11 @@ mod tests { fn arclike_try_unwrap_unwrap_race() { // When an unwrap and a try_unwrap race, the unwrapper should always win. let x = UnsafeArc::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = x.clone(); let (p,c) = comm::stream(); do task::spawn { c.send(()); - assert!(x2.take().unwrap() == ~~"hello"); + assert!(x2.unwrap() == ~~"hello"); c.send(()); } p.recv(); @@ -620,21 +604,19 @@ mod tests { #[test] fn exclusive_new_unwrap_contended() { let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = x.clone(); do task::spawn { - let x2 = x2.take(); - unsafe { do x2.with |_hello| { } } + unsafe { x2.with(|_hello| ()); } task::deschedule(); } assert!(x.unwrap() == ~~"hello"); // Now try the same thing, but with the child task blocking. let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = x.clone(); let mut builder = task::task(); let res = builder.future_result(); do builder.spawn { - let x2 = x2.take(); assert!(x2.unwrap() == ~~"hello"); } // Have to get rid of our reference before blocking. @@ -645,11 +627,10 @@ mod tests { #[test] #[should_fail] fn exclusive_new_unwrap_conflict() { let x = Exclusive::new(~~"hello"); - let x2 = Cell::new(x.clone()); + let x2 = x.clone(); let mut builder = task::task(); let res = builder.future_result(); do builder.spawn { - let x2 = x2.take(); assert!(x2.unwrap() == ~~"hello"); } assert!(x.unwrap() == ~~"hello"); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 0b08f9d00faf9..30627327d7327 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -137,14 +137,14 @@ pub fn from_fn(n_elts: uint, op: |uint| -> T) -> ~[T] { let mut v = with_capacity(n_elts); let p = raw::to_mut_ptr(v); let mut i: uint = 0u; - do (|| { + (|| { while i < n_elts { intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), op(i)); i += 1u; } - }).finally { + }).finally(|| { raw::set_len(&mut v, i); - } + }); v } } @@ -164,14 +164,14 @@ pub fn from_elem(n_elts: uint, t: T) -> ~[T] { let mut v = with_capacity(n_elts); let p = raw::to_mut_ptr(v); let mut i = 0u; - do (|| { + (|| { while i < n_elts { intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), t.clone()); i += 1u; } - }).finally { + }).finally(|| { raw::set_len(&mut v, i); - } + }); v } } @@ -982,14 +982,14 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { fn slice(&self, start: uint, end: uint) -> &'self [T] { assert!(start <= end); assert!(end <= self.len()); - do self.as_imm_buf |p, _len| { + self.as_imm_buf(|p, _len| { unsafe { cast::transmute(Slice { data: ptr::offset(p, start as int), len: (end - start) }) } - } + }) } #[inline] @@ -1639,7 +1639,7 @@ impl OwnedVector for ~[T] { self.pop() } fn truncate(&mut self, newlen: uint) { - do self.as_mut_buf |p, oldlen| { + self.as_mut_buf(|p, oldlen| { assert!(newlen <= oldlen); unsafe { // This loop is optimized out for non-drop types. @@ -1647,7 +1647,7 @@ impl OwnedVector for ~[T] { ptr::read_and_zero_ptr(ptr::mut_offset(p, i as int)); } } - } + }); unsafe { raw::set_len(self, newlen); } } @@ -1932,14 +1932,14 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] { fn mut_slice(self, start: uint, end: uint) -> &'self mut [T] { assert!(start <= end); assert!(end <= self.len()); - do self.as_mut_buf |p, _len| { + self.as_mut_buf(|p, _len| { unsafe { cast::transmute(Slice { data: ptr::mut_offset(p, start as int) as *T, len: (end - start) }) } - } + }) } #[inline] @@ -2153,10 +2153,10 @@ pub mod raw { #[inline] pub unsafe fn init_elem(v: &mut [T], i: uint, val: T) { let mut box = Some(val); - do v.as_mut_buf |p, _len| { + v.as_mut_buf(|p, _len| { intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), box.take_unwrap()); - } + }) } /** @@ -2188,11 +2188,11 @@ pub mod raw { assert!(dst.len() >= count); assert!(src.len() >= count); - do dst.as_mut_buf |p_dst, _len_dst| { - do src.as_imm_buf |p_src, _len_src| { + dst.as_mut_buf(|p_dst, _len_dst| { + src.as_imm_buf(|p_src, _len_src| { ptr::copy_memory(p_dst, p_src, count) - } - } + }) + }) } } @@ -2213,9 +2213,9 @@ pub mod bytes { impl<'self> MutableByteVector for &'self mut [u8] { #[inline] fn set_memory(self, value: u8) { - do self.as_mut_buf |p, len| { + self.as_mut_buf(|p, len| { unsafe { ptr::set_memory(p, value, len) }; - } + }) } } @@ -2278,11 +2278,11 @@ pub mod bytes { let old_len = dst.len(); dst.reserve_additional(src.len()); unsafe { - do dst.as_mut_buf |p_dst, len_dst| { - do src.as_imm_buf |p_src, len_src| { + dst.as_mut_buf(|p_dst, len_dst| { + src.as_imm_buf(|p_src, len_src| { ptr::copy_memory(p_dst.offset(len_dst as int), p_src, len_src) - } - } + }) + }); vec::raw::set_len(dst, old_len + src.len()); } } @@ -3276,10 +3276,10 @@ mod tests { #[test] #[should_fail] fn test_from_fn_fail() { - do from_fn(100) |v| { + from_fn(100, |v| { if v == 50 { fail!() } (~0, @0) - }; + }); } #[test] @@ -3308,25 +3308,25 @@ mod tests { #[test] #[should_fail] fn test_build_fail() { - do build(None) |push| { + build(None, |push| { push((~0, @0)); push((~0, @0)); push((~0, @0)); push((~0, @0)); fail!(); - }; + }); } #[test] #[should_fail] fn test_grow_fn_fail() { let mut v = ~[]; - do v.grow_fn(100) |i| { + v.grow_fn(100, |i| { if i == 50 { fail!() } (~0, @0) - } + }) } #[test] @@ -3334,13 +3334,13 @@ mod tests { fn test_map_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do v.map |_elt| { + v.map(|_elt| { if i == 2 { fail!() } i += 1; ~[(~0, @0)] - }; + }); } #[test] @@ -3348,13 +3348,13 @@ mod tests { fn test_flat_map_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do flat_map(v) |_elt| { + flat_map(v, |_elt| { if i == 2 { fail!() } i += 1; ~[(~0, @0)] - }; + }); } #[test] @@ -3374,18 +3374,18 @@ mod tests { #[should_fail] fn test_as_imm_buf_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - do v.as_imm_buf |_buf, _i| { + v.as_imm_buf(|_buf, _i| { fail!() - } + }) } #[test] #[should_fail] fn test_as_mut_buf_fail() { let mut v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - do v.as_mut_buf |_buf, _i| { + v.as_mut_buf(|_buf, _i| { fail!() - } + }) } #[test] @@ -3843,52 +3843,48 @@ mod bench { // out. let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1)); - do bh.iter { + bh.iter(|| { let mut sum = 0; for x in v.iter() { sum += *x; } // sum == 11806, to stop dead code elimination. if sum == 0 {fail!()} - } + }) } #[bench] fn mut_iterator(bh: &mut BenchHarness) { let mut v = vec::from_elem(100, 0); - do bh.iter { + bh.iter(|| { let mut i = 0; for x in v.mut_iter() { *x = i; i += 1; } - } + }) } #[bench] fn add(bh: &mut BenchHarness) { let xs: &[int] = [5, ..10]; let ys: &[int] = [5, ..10]; - do bh.iter() { + bh.iter(|| { xs + ys; - } + }); } #[bench] fn concat(bh: &mut BenchHarness) { let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect()); - do bh.iter { - xss.concat_vec(); - } + bh.iter(|| xss.concat_vec()); } #[bench] fn connect(bh: &mut BenchHarness) { let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect()); - do bh.iter { - xss.connect_vec(&0); - } + bh.iter(|| xss.connect_vec(&0)); } #[bench] From a61a3678ebe5571842d4223e2a0313714893bbf7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Nov 2013 15:46:49 -0800 Subject: [PATCH 05/12] librustuv: Remove all non-`proc` uses of `do` from `libextra` and `librustuv`. --- src/libextra/arc.rs | 196 +++++++++++++++++----------------- src/libextra/arena.rs | 8 +- src/libextra/bitv.rs | 38 ++++--- src/libextra/comm.rs | 4 +- src/libextra/dlist.rs | 32 +++--- src/libextra/ebml.rs | 40 +++---- src/libextra/flate.rs | 8 +- src/libextra/getopts.rs | 10 +- src/libextra/glob.rs | 8 +- src/libextra/json.rs | 4 +- src/libextra/list.rs | 6 +- src/libextra/num/bigint.rs | 75 ++++++------- src/libextra/num/rational.rs | 16 +-- src/libextra/semver.rs | 4 +- src/libextra/serialize.rs | 156 +++++++++++++-------------- src/libextra/sync.rs | 90 ++++++++-------- src/libextra/task_pool.rs | 4 +- src/libextra/term.rs | 4 +- src/libextra/terminfo/parm.rs | 8 +- src/libextra/test.rs | 20 ++-- src/libextra/treemap.rs | 4 +- src/libextra/workcache.rs | 20 ++-- src/librustuv/addrinfo.rs | 12 +-- src/librustuv/async.rs | 4 +- src/librustuv/file.rs | 24 ++--- src/librustuv/lib.rs | 12 +-- src/librustuv/macros.rs | 2 +- src/librustuv/net.rs | 52 +++++---- src/librustuv/pipe.rs | 4 +- src/librustuv/process.rs | 8 +- src/librustuv/stream.rs | 4 +- src/librustuv/timer.rs | 4 +- src/librustuv/uvio.rs | 24 ++--- 33 files changed, 456 insertions(+), 449 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 0752b9d9a7f4f..b9b1e324e5a96 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -224,11 +224,11 @@ impl MutexArc { let state = self.x.get(); // Borrowck would complain about this if the function were // not already unsafe. See borrow_rwlock, far below. - do (&(*state).lock).lock { + (&(*state).lock).lock(|| { check_poison(true, (*state).failed); let _z = PoisonOnFail(&mut (*state).failed); blk(&mut (*state).data) - } + }) } /// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond(). @@ -237,14 +237,14 @@ impl MutexArc { blk: |x: &mut T, c: &Condvar| -> U) -> U { let state = self.x.get(); - do (&(*state).lock).lock_cond |cond| { + (&(*state).lock).lock_cond(|cond| { check_poison(true, (*state).failed); let _z = PoisonOnFail(&mut (*state).failed); blk(&mut (*state).data, &Condvar {is_mutex: true, failed: &mut (*state).failed, cond: cond }) - } + }) } /** @@ -390,11 +390,11 @@ impl RWArc { pub fn write(&self, blk: |x: &mut T| -> U) -> U { unsafe { let state = self.x.get(); - do (*borrow_rwlock(state)).write { + (*borrow_rwlock(state)).write(|| { check_poison(false, (*state).failed); let _z = PoisonOnFail(&mut (*state).failed); blk(&mut (*state).data) - } + }) } } @@ -405,14 +405,14 @@ impl RWArc { -> U { unsafe { let state = self.x.get(); - do (*borrow_rwlock(state)).write_cond |cond| { + (*borrow_rwlock(state)).write_cond(|cond| { check_poison(false, (*state).failed); let _z = PoisonOnFail(&mut (*state).failed); blk(&mut (*state).data, &Condvar {is_mutex: false, failed: &mut (*state).failed, cond: cond}) - } + }) } } @@ -428,10 +428,10 @@ impl RWArc { pub fn read(&self, blk: |x: &T| -> U) -> U { unsafe { let state = self.x.get(); - do (*state).lock.read { + (*state).lock.read(|| { check_poison(false, (*state).failed); blk(&(*state).data) - } + }) } } @@ -458,14 +458,14 @@ impl RWArc { pub fn write_downgrade(&self, blk: |v: RWWriteMode| -> U) -> U { unsafe { let state = self.x.get(); - do (*borrow_rwlock(state)).write_downgrade |write_mode| { + (*borrow_rwlock(state)).write_downgrade(|write_mode| { check_poison(false, (*state).failed); blk(RWWriteMode { data: &mut (*state).data, token: write_mode, poison: PoisonOnFail(&mut (*state).failed) }) - } + }) } } @@ -544,9 +544,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { token: ref token, poison: _ } => { - do token.write { - blk(data) - } + token.write(|| blk(data)) } } } @@ -561,7 +559,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { token: ref token, poison: ref poison } => { - do token.write_cond |cond| { + token.write_cond(|cond| { unsafe { let cvar = Condvar { is_mutex: false, @@ -570,7 +568,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { }; blk(data, &cvar) } - } + }) } } } @@ -584,7 +582,7 @@ impl<'self, T:Freeze + Send> RWReadMode<'self, T> { data: data, token: ref token } => { - do token.read { blk(data) } + token.read(|| blk(data)) } } } @@ -634,19 +632,19 @@ mod tests { do task::spawn || { // wait until parent gets in p.take().recv(); - do arc2.access_cond |state, cond| { + arc2.access_cond(|state, cond| { *state = true; cond.signal(); - } + }) } - do arc.access_cond |state, cond| { + arc.access_cond(|state, cond| { c.take().send(()); assert!(!*state); while !*state { cond.wait(); } - } + }) } #[test] #[should_fail] @@ -657,19 +655,19 @@ mod tests { do spawn { let _ = p.recv(); - do arc2.access_cond |one, cond| { + arc2.access_cond(|one, cond| { cond.signal(); // Parent should fail when it wakes up. assert_eq!(*one, 0); - } + }) } - do arc.access_cond |one, cond| { + arc.access_cond(|one, cond| { c.send(()); while *one == 1 { cond.wait(); } - } + }) } #[test] #[should_fail] @@ -677,13 +675,13 @@ mod tests { let arc = ~MutexArc::new(1); let arc2 = ~arc.clone(); do task::try || { - do arc2.access |one| { + arc2.access(|one| { assert_eq!(*one, 2); - } + }) }; - do arc.access |one| { + arc.access(|one| { assert_eq!(*one, 1); - } + }) } #[test] #[should_fail] @@ -692,10 +690,10 @@ mod tests { let arc2 = ~(&arc).clone(); let (p, c) = comm::stream(); do task::spawn { - do arc2.access |one| { + arc2.access(|one| { c.send(()); assert!(*one == 2); - } + }) } let _ = p.recv(); let one = arc.unwrap(); @@ -710,11 +708,11 @@ mod tests { let arc = ~MutexArc::new(1); let arc2 = ~MutexArc::new(*arc); do task::spawn || { - do (*arc2).unsafe_access |mutex| { - do (*mutex).access |one| { + (*arc2).unsafe_access(|mutex| { + (*mutex).access(|one| { assert!(*one == 1); - } - } + }) + }) }; } } @@ -724,13 +722,13 @@ mod tests { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.write |one| { + arc2.write(|one| { assert_eq!(*one, 2); - } + }) }; - do arc.read |one| { + arc.read(|one| { assert_eq!(*one, 1); - } + }) } #[test] #[should_fail] @@ -738,70 +736,70 @@ mod tests { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.write |one| { + arc2.write(|one| { assert_eq!(*one, 2); - } + }) }; - do arc.write |one| { + arc.write(|one| { assert_eq!(*one, 1); - } + }) } #[test] #[should_fail] fn test_rw_arc_poison_dw() { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.write_downgrade |mut write_mode| { - do write_mode.write |one| { + arc2.write_downgrade(|mut write_mode| { + write_mode.write(|one| { assert_eq!(*one, 2); - } - } + }) + }) }; - do arc.write |one| { + arc.write(|one| { assert_eq!(*one, 1); - } + }) } #[test] fn test_rw_arc_no_poison_rr() { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.read |one| { + arc2.read(|one| { assert_eq!(*one, 2); - } + }) }; - do arc.read |one| { + arc.read(|one| { assert_eq!(*one, 1); - } + }) } #[test] fn test_rw_arc_no_poison_rw() { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.read |one| { + arc2.read(|one| { assert_eq!(*one, 2); - } + }) }; - do arc.write |one| { + arc.write(|one| { assert_eq!(*one, 1); - } + }) } #[test] fn test_rw_arc_no_poison_dr() { let arc = RWArc::new(1); let arc2 = arc.clone(); do task::try { - do arc2.write_downgrade |write_mode| { + arc2.write_downgrade(|write_mode| { let read_mode = arc2.downgrade(write_mode); - do read_mode.read |one| { + read_mode.read(|one| { assert_eq!(*one, 2); - } - } + }) + }) }; - do arc.write |one| { + arc.write(|one| { assert_eq!(*one, 1); - } + }) } #[test] fn test_rw_arc() { @@ -810,29 +808,29 @@ mod tests { let (p, c) = comm::stream(); do task::spawn { - do arc2.write |num| { - do 10.times { + arc2.write(|num| { + 10.times(|| { let tmp = *num; *num = -1; task::deschedule(); *num = tmp + 1; - } + }); c.send(()); - } + }) } // Readers try to catch the writer in the act let mut children = ~[]; - do 5.times { + 5.times(|| { let arc3 = arc.clone(); let mut builder = task::task(); children.push(builder.future_result()); do builder.spawn { - do arc3.read |num| { + arc3.read(|num| { assert!(*num >= 0); - } + }) } - } + }); // Wait for children to pass their asserts for r in children.iter() { @@ -841,9 +839,9 @@ mod tests { // Wait for writer to finish p.recv(); - do arc.read |num| { + arc.read(|num| { assert_eq!(*num, 10); - } + }) } #[test] fn test_rw_downgrade() { @@ -857,42 +855,42 @@ mod tests { // Reader tasks let mut reader_convos = ~[]; - do 10.times { + 10.times(|| { let ((rp1, rc1), (rp2, rc2)) = (comm::stream(), comm::stream()); reader_convos.push((rc1, rp2)); let arcn = arc.clone(); do task::spawn { rp1.recv(); // wait for downgrader to give go-ahead - do arcn.read |state| { + arcn.read(|state| { assert_eq!(*state, 31337); rc2.send(()); - } + }) } - } + }); // Writer task let arc2 = arc.clone(); let ((wp1, wc1), (wp2, wc2)) = (comm::stream(), comm::stream()); do task::spawn || { wp1.recv(); - do arc2.write_cond |state, cond| { + arc2.write_cond(|state, cond| { assert_eq!(*state, 0); *state = 42; cond.signal(); - } + }); wp1.recv(); - do arc2.write |state| { + arc2.write(|state| { // This shouldn't happen until after the downgrade read // section, and all other readers, finish. assert_eq!(*state, 31337); *state = 42; - } + }); wc2.send(()); } // Downgrader (us) - do arc.write_downgrade |mut write_mode| { - do write_mode.write_cond |state, cond| { + arc.write_downgrade(|mut write_mode| { + write_mode.write_cond(|state, cond| { wc1.send(()); // send to another writer who will wake us up while *state == 0 { cond.wait(); @@ -903,17 +901,17 @@ mod tests { for &(ref rc, _) in reader_convos.iter() { rc.send(()) } - } + }); let read_mode = arc.downgrade(write_mode); - do read_mode.read |state| { + read_mode.read(|state| { // complete handshake with other readers for &(_, ref rp) in reader_convos.iter() { rp.recv() } wc1.send(()); // tell writer to try again assert_eq!(*state, 31337); - } - } + }); + }); wp2.recv(); // complete handshake with writer } @@ -934,42 +932,42 @@ mod tests { // writer task let xw = x.clone(); do task::spawn { - do xw.write_cond |state, c| { + xw.write_cond(|state, c| { wc.send(()); // tell downgrader it's ok to go c.wait(); // The core of the test is here: the condvar reacquire path // must involve order_lock, so that it cannot race with a reader // trying to receive the "reader cloud lock hand-off". *state = false; - } + }) } wp.recv(); // wait for writer to get in - do x.write_downgrade |mut write_mode| { - do write_mode.write_cond |state, c| { + x.write_downgrade(|mut write_mode| { + write_mode.write_cond(|state, c| { assert!(*state); // make writer contend in the cond-reacquire path c.signal(); - } + }); // make a reader task to trigger the "reader cloud lock" handoff let xr = x.clone(); let (rp, rc) = comm::stream(); do task::spawn { rc.send(()); - do xr.read |_state| { } + xr.read(|_state| { }) } rp.recv(); // wait for reader task to exist let read_mode = x.downgrade(write_mode); - do read_mode.read |state| { + read_mode.read(|state| { // if writer mistakenly got in, make sure it mutates state // before we assert on it - do 5.times { task::deschedule(); } + 5.times(|| task::deschedule()); // make sure writer didn't get in. assert!(*state); - } - } + }) + }); } #[test] fn test_rw_write_cond_downgrade_read_race() { @@ -977,6 +975,6 @@ mod tests { // helped to expose the race nearly 100% of the time... but adding // deschedules in the intuitively-right locations made it even less likely, // and I wasn't sure why :( . This is a mediocre "next best" option. - do 8.times { test_rw_write_cond_downgrade_read_race_helper() } + 8.times(|| test_rw_write_cond_downgrade_read_race_helper()); } } diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 2bb36e25fcb04..7da9ac2aed80b 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -96,12 +96,12 @@ impl Drop for Arena { fn drop(&mut self) { unsafe { destroy_chunk(&self.head); - do self.chunks.each |chunk| { + self.chunks.each(|chunk| { if !chunk.is_pod { destroy_chunk(chunk); } true - }; + }); } } } @@ -282,10 +282,10 @@ fn test_arena_destructors() { for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it // doesn't leak. - do arena.alloc { @i }; + arena.alloc(|| @i); // Allocate something with funny size and alignment, to keep // things interesting. - do arena.alloc { [0u8, 1u8, 2u8] }; + arena.alloc(|| [0u8, 1u8, 2u8]); } } diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 393d76f246c7a..306a2abca5506 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -166,7 +166,9 @@ impl BigBitv { } #[inline] - pub fn negate(&mut self) { do self.each_storage |w| { *w = !*w; true }; } + pub fn negate(&mut self) { + self.each_storage(|w| { *w = !*w; true }); + } #[inline] pub fn union(&mut self, b: &BigBitv, nbits: uint) -> bool { @@ -358,26 +360,32 @@ impl Bitv { #[inline] pub fn clear(&mut self) { match self.rep { - Small(ref mut b) => b.clear(), - Big(ref mut s) => { do s.each_storage() |w| { *w = 0u; true }; } + Small(ref mut b) => b.clear(), + Big(ref mut s) => { + s.each_storage(|w| { *w = 0u; true }); + } } } /// Set all bits to 1 #[inline] pub fn set_all(&mut self) { - match self.rep { - Small(ref mut b) => b.set_all(), - Big(ref mut s) => { do s.each_storage() |w| { *w = !0u; true }; } - } + match self.rep { + Small(ref mut b) => b.set_all(), + Big(ref mut s) => { + s.each_storage(|w| { *w = !0u; true }); + } + } } /// Invert all bits #[inline] pub fn negate(&mut self) { - match self.rep { - Small(ref mut b) => b.negate(), - Big(ref mut s) => { do s.each_storage() |w| { *w = !*w; true }; } + match self.rep { + Small(ref mut b) => b.negate(), + Big(ref mut s) => { + s.each_storage(|w| { *w = !*w; true }); + } } } @@ -651,10 +659,10 @@ impl BitvSet { /// Creates a new bit vector set from the given bit vector pub fn from_bitv(bitv: Bitv) -> BitvSet { let mut size = 0; - do bitv.ones |_| { + bitv.ones(|_| { size += 1; true - }; + }); let Bitv{rep, _} = bitv; match rep { Big(b) => BitvSet{ size: size, bitv: b }, @@ -786,7 +794,7 @@ impl Container for BitvSet { impl Mutable for BitvSet { fn clear(&mut self) { - do self.bitv.each_storage |w| { *w = 0; true }; + self.bitv.each_storage(|w| { *w = 0; true }); self.size = 0; } } @@ -797,9 +805,7 @@ impl Set for BitvSet { } fn is_disjoint(&self, other: &BitvSet) -> bool { - do self.intersection(other) |_| { - false - } + self.intersection(other, |_| false) } fn is_subset(&self, other: &BitvSet) -> bool { diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 5321a6288f435..d24f285ced21e 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -114,10 +114,10 @@ impl GenericPort for SyncPort { } fn try_recv(&self) -> Option { - do self.duplex_stream.try_recv().map |val| { + self.duplex_stream.try_recv().map(|val| { self.duplex_stream.try_send(()); val - } + }) } } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 418b8256189f9..a261a2483052f 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -165,14 +165,14 @@ impl DList { /// Remove the first Node and return it, or None if the list is empty #[inline] fn pop_front_node(&mut self) -> Option<~Node> { - do self.list_head.take().map |mut front_node| { + self.list_head.take().map(|mut front_node| { self.length -= 1; match front_node.next.take() { Some(node) => self.list_head = link_with_prev(node, Rawlink::none()), None => self.list_tail = Rawlink::none() } front_node - } + }) } /// Add a Node last in the list @@ -191,14 +191,14 @@ impl DList { /// Remove the last Node and return it, or None if the list is empty #[inline] fn pop_back_node(&mut self) -> Option<~Node> { - do self.list_tail.resolve().map_default(None) |tail| { + self.list_tail.resolve().map_default(None, |tail| { self.length -= 1; self.list_tail = tail.prev; match tail.prev.resolve() { None => self.list_head.take(), Some(tail_prev) => tail_prev.next.take() } - } + }) } } @@ -270,9 +270,9 @@ impl DList { /// If the list is empty, do nothing. #[inline] pub fn rotate_forward(&mut self) { - do self.pop_back_node().map |tail| { + self.pop_back_node().map(|tail| { self.push_front_node(tail) - }; + }); } /// Move the first element to the back of the list. @@ -280,9 +280,9 @@ impl DList { /// If the list is empty, do nothing. #[inline] pub fn rotate_backward(&mut self) { - do self.pop_front_node().map |head| { + self.pop_front_node().map(|head| { self.push_back_node(head) - }; + }); } /// Add all elements from `other` to the end of the list @@ -444,11 +444,11 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> { if self.nelem == 0 { return None; } - do self.head.as_ref().map |head| { + self.head.as_ref().map(|head| { self.nelem -= 1; self.head = &head.next; &head.value - } + }) } #[inline] @@ -464,11 +464,11 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> { return None; } let tmp = self.tail.resolve_immut(); // FIXME: #3511: shouldn't need variable - do tmp.as_ref().map |prev| { + tmp.as_ref().map(|prev| { self.nelem -= 1; self.tail = prev.prev; &prev.value - } + }) } } @@ -480,14 +480,14 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> { if self.nelem == 0 { return None; } - do self.head.resolve().map |next| { + self.head.resolve().map(|next| { self.nelem -= 1; self.head = match next.next { Some(ref mut node) => Rawlink::some(&mut **node), None => Rawlink::none(), }; &mut next.value - } + }) } #[inline] @@ -502,11 +502,11 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A> if self.nelem == 0 { return None; } - do self.tail.resolve().map |prev| { + self.tail.resolve().map(|prev| { self.nelem -= 1; self.tail = prev.prev; &mut prev.value - } + }) } } diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index c82ee733a4cbe..19959dd2705fc 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -546,24 +546,24 @@ pub mod reader { 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| { + self.read_enum("Option", |this| { + this.read_enum_variant(["None", "Some"], |this, idx| { match idx { 0 => f(this, false), 1 => f(this, true), _ => fail!(), } - } - } + }) + }) } fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); - do self.push_doc(EsVec) |d| { + self.push_doc(EsVec, |d| { let len = d._next_uint(EsVecLen); debug!(" len={}", len); f(d, len) - } + }) } fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder| -> T) @@ -574,11 +574,11 @@ pub mod reader { fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); - do self.push_doc(EsMap) |d| { + self.push_doc(EsMap, |d| { let len = d._next_uint(EsMapLen); debug!(" len={}", len); f(d, len) - } + }) } fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> T) @@ -687,21 +687,21 @@ pub mod writer { } pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) { - do u64_to_be_bytes(v, 8u) |v| { + u64_to_be_bytes(v, 8u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) { - do u64_to_be_bytes(v as u64, 4u) |v| { + u64_to_be_bytes(v as u64, 4u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) { - do u64_to_be_bytes(v as u64, 2u) |v| { + u64_to_be_bytes(v as u64, 2u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) { @@ -709,21 +709,21 @@ pub mod writer { } pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) { - do u64_to_be_bytes(v as u64, 8u) |v| { + u64_to_be_bytes(v as u64, 8u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) { - do u64_to_be_bytes(v as u64, 4u) |v| { + u64_to_be_bytes(v as u64, 4u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) { - do u64_to_be_bytes(v as u64, 2u) |v| { + u64_to_be_bytes(v as u64, 2u, |v| { self.wr_tagged_bytes(tag_id, v); - } + }) } pub fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) { diff --git a/src/libextra/flate.rs b/src/libextra/flate.rs index 83a3ef60a8aff..1a295010dc4dd 100644 --- a/src/libextra/flate.rs +++ b/src/libextra/flate.rs @@ -47,7 +47,7 @@ static TINFL_FLAG_PARSE_ZLIB_HEADER : c_int = 0x1; // parse zlib header and adle static TDEFL_WRITE_ZLIB_HEADER : c_int = 0x01000; // write zlib header and adler32 checksum fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] { - do bytes.as_imm_buf |b, len| { + bytes.as_imm_buf(|b, len| { unsafe { let mut outsz : size_t = 0; let res = @@ -61,7 +61,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] { libc::free(res); out } - } + }) } pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] { @@ -73,7 +73,7 @@ pub fn deflate_bytes_zlib(bytes: &[u8]) -> ~[u8] { } fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] { - do bytes.as_imm_buf |b, len| { + bytes.as_imm_buf(|b, len| { unsafe { let mut outsz : size_t = 0; let res = @@ -87,7 +87,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] { libc::free(res); out } - } + }) } pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 47dfaee3f5713..8cdadca1cc296 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -726,9 +726,9 @@ pub mod groups { // here we just need to indent the start of the description let rowlen = row.char_len(); if rowlen < 24 { - do (24 - rowlen).times { + (24 - rowlen).times(|| { row.push_char(' ') - } + }) } else { row.push_str(desc_sep) } @@ -742,10 +742,10 @@ pub mod groups { // FIXME: #5516 should be graphemes not codepoints let mut desc_rows = ~[]; - do each_split_within(desc_normalized_whitespace, 54) |substr| { + each_split_within(desc_normalized_whitespace, 54, |substr| { desc_rows.push(substr.to_owned()); true - }; + }); // FIXME: #5516 should be graphemes not codepoints // wrapped description @@ -840,7 +840,7 @@ pub mod groups { fn test_split_within() { fn t(s: &str, i: uint, u: &[~str]) { let mut v = ~[]; - do each_split_within(s, i) |s| { v.push(s.to_owned()); true }; + each_split_within(s, i, |s| { v.push(s.to_owned()); true }); assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("", 0, []); diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index fde63071bc892..3ee43ca4a5852 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -310,9 +310,9 @@ impl Pattern { */ pub fn matches_path(&self, path: &Path) -> bool { // FIXME (#9639): This needs to handle non-utf8 paths - do path.as_str().map_default(false) |s| { + path.as_str().map_default(false, |s| { self.matches(s) - } + }) } /** @@ -328,9 +328,9 @@ impl Pattern { */ pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool { // FIXME (#9639): This needs to handle non-utf8 paths - do path.as_str().map_default(false) |s| { + path.as_str().map_default(false, |s| { self.matches_with(s, options) - } + }) } fn matches_from(&self, diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 6befdc899d2bc..cb138099cbced 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -79,9 +79,7 @@ fn escape_str(s: &str) -> ~str { fn spaces(n: uint) -> ~str { let mut ss = ~""; - do n.times { - ss.push_str(" "); - } + n.times(|| ss.push_str(" ")); return ss; } diff --git a/src/libextra/list.rs b/src/libextra/list.rs index 22d273e5747cd..a2540d3948e89 100644 --- a/src/libextra/list.rs +++ b/src/libextra/list.rs @@ -46,7 +46,7 @@ pub fn from_vec(v: &[T]) -> @List { */ 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);} + iter(ls, |elt| accum = f(&accum, elt)); accum } @@ -73,9 +73,9 @@ pub fn find(ls: @List, f: |&T| -> bool) -> Option { /// Returns true if a list contains an element with the given value pub fn has(ls: @List, elt: T) -> bool { let mut found = false; - do each(ls) |e| { + each(ls, |e| { if *e == elt { found = true; false } else { true } - }; + }); return found; } diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index b79c2bd5cb565..5b3de10b8b08f 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -158,12 +158,12 @@ impl Orderable for BigUint { impl BitAnd for BigUint { fn bitand(&self, other: &BigUint) -> BigUint { let new_len = num::min(self.data.len(), other.data.len()); - let anded = do vec::from_fn(new_len) |i| { + let anded = vec::from_fn(new_len, |i| { // i will never be less than the size of either data vector let ai = self.data[i]; let bi = other.data[i]; ai & bi - }; + }); return BigUint::new(anded); } } @@ -171,11 +171,11 @@ impl BitAnd for BigUint { impl BitOr for BigUint { fn bitor(&self, other: &BigUint) -> BigUint { let new_len = num::max(self.data.len(), other.data.len()); - let ored = do vec::from_fn(new_len) |i| { + let ored = vec::from_fn(new_len, |i| { let ai = if i < self.data.len() { self.data[i] } else { 0 }; let bi = if i < other.data.len() { other.data[i] } else { 0 }; ai | bi - }; + }); return BigUint::new(ored); } } @@ -183,11 +183,11 @@ impl BitOr for BigUint { impl BitXor for BigUint { fn bitxor(&self, other: &BigUint) -> BigUint { let new_len = num::max(self.data.len(), other.data.len()); - let xored = do vec::from_fn(new_len) |i| { + let xored = vec::from_fn(new_len, |i| { let ai = if i < self.data.len() { self.data[i] } else { 0 }; let bi = if i < other.data.len() { other.data[i] } else { 0 }; ai ^ bi - }; + }); return BigUint::new(xored); } } @@ -230,7 +230,7 @@ impl Add for BigUint { let new_len = num::max(self.data.len(), other.data.len()); let mut carry = 0; - let mut sum = do vec::from_fn(new_len) |i| { + let mut sum = vec::from_fn(new_len, |i| { let ai = if i < self.data.len() { self.data[i] } else { 0 }; let bi = if i < other.data.len() { other.data[i] } else { 0 }; let (hi, lo) = BigDigit::from_uint( @@ -238,7 +238,7 @@ impl Add for BigUint { ); carry = hi; lo - }; + }); if carry != 0 { sum.push(carry); } return BigUint::new(sum); } @@ -249,7 +249,7 @@ impl Sub for BigUint { let new_len = num::max(self.data.len(), other.data.len()); let mut borrow = 0; - let diff = do vec::from_fn(new_len) |i| { + let diff = vec::from_fn(new_len, |i| { let ai = if i < self.data.len() { self.data[i] } else { 0 }; let bi = if i < other.data.len() { other.data[i] } else { 0 }; let (hi, lo) = BigDigit::from_uint( @@ -262,7 +262,7 @@ impl Sub for BigUint { */ borrow = if hi == 0 { 1 } else { 0 }; lo - }; + }); assert_eq!(borrow, 0); // <=> assert!((self >= other)); return BigUint::new(diff); @@ -306,13 +306,13 @@ impl Mul for BigUint { if n == 1 { return (*a).clone(); } let mut carry = 0; - let mut prod = do a.data.iter().map |ai| { + let mut prod = a.data.iter().map(|ai| { let (hi, lo) = BigDigit::from_uint( (*ai as uint) * (n as uint) + (carry as uint) ); carry = hi; lo - }.collect::<~[BigDigit]>(); + }).collect::<~[BigDigit]>(); if carry != 0 { prod.push(carry); } return BigUint::new(prod); } @@ -504,14 +504,14 @@ impl Integer for BigUint { impl ToPrimitive for BigUint { #[inline] fn to_i64(&self) -> Option { - do self.to_u64().and_then |n| { + self.to_u64().and_then(|n| { // If top bit of u64 is set, it's too large to convert to i64. if n >> 63 == 0 { Some(n as i64) } else { None } - } + }) } #[cfg(target_word_size = "32")] @@ -763,13 +763,13 @@ impl BigUint { if n_bits == 0 || self.is_zero() { return (*self).clone(); } let mut carry = 0; - let mut shifted = do self.data.iter().map |elem| { + let mut shifted = self.data.iter().map(|elem| { let (hi, lo) = BigDigit::from_uint( (*elem as uint) << n_bits | (carry as uint) ); carry = hi; lo - }.collect::<~[BigDigit]>(); + }).collect::<~[BigDigit]>(); if carry != 0 { shifted.push(carry); } return BigUint::new(shifted); } @@ -1182,7 +1182,7 @@ impl ToPrimitive for BigInt { Plus => self.data.to_i64(), Zero => Some(0), Minus => { - do self.data.to_u64().and_then |n| { + self.data.to_u64().and_then(|n| { let m: u64 = 1 << 63; if n < m { Some(-(n as i64)) @@ -1191,7 +1191,7 @@ impl ToPrimitive for BigInt { } else { None } - } + }) } } } @@ -1210,13 +1210,14 @@ impl FromPrimitive for BigInt { #[inline] fn from_i64(n: i64) -> Option { if n > 0 { - do FromPrimitive::from_u64(n as u64).and_then |n| { + FromPrimitive::from_u64(n as u64).and_then(|n| { Some(BigInt::from_biguint(Plus, n)) - } + }) } else if n < 0 { - do FromPrimitive::from_u64(u64::max_value - (n as u64) + 1).and_then |n| { - Some(BigInt::from_biguint(Minus, n)) - } + FromPrimitive::from_u64(u64::max_value - (n as u64) + 1).and_then( + |n| { + Some(BigInt::from_biguint(Minus, n)) + }) } else { Some(Zero::zero()) } @@ -1227,9 +1228,9 @@ impl FromPrimitive for BigInt { if n == 0 { Some(Zero::zero()) } else { - do FromPrimitive::from_u64(n).and_then |n| { + FromPrimitive::from_u64(n).and_then(|n| { Some(BigInt::from_biguint(Plus, n)) - } + }) } } } @@ -2051,22 +2052,22 @@ mod biguint_tests { fn test_rand_range() { let mut rng = task_rng(); - do 10.times { + 10.times(|| { assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_uint(236).unwrap(), &FromPrimitive::from_uint(237).unwrap()), FromPrimitive::from_uint(236).unwrap()); - } + }); let l = FromPrimitive::from_uint(403469000 + 2352).unwrap(); let u = FromPrimitive::from_uint(403469000 + 3513).unwrap(); - do 1000.times { + 1000.times(|| { let n: BigUint = rng.gen_biguint_below(&u); assert!(n < u); let n: BigUint = rng.gen_biguint_range(&l, &u); assert!(n >= l); assert!(n < u); - } + }) } #[test] @@ -2548,19 +2549,19 @@ mod bigint_tests { fn test_rand_range() { let mut rng = task_rng(); - do 10.times { + 10.times(|| { assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_uint(236).unwrap(), &FromPrimitive::from_uint(237).unwrap()), FromPrimitive::from_uint(236).unwrap()); - } + }); fn check(l: BigInt, u: BigInt) { let mut rng = task_rng(); - do 1000.times { + 1000.times(|| { let n: BigInt = rng.gen_bigint_range(&l, &u); assert!(n >= l); assert!(n < u); - } + }); } let l: BigInt = FromPrimitive::from_uint(403469000 + 2352).unwrap(); let u: BigInt = FromPrimitive::from_uint(403469000 + 3513).unwrap(); @@ -2614,19 +2615,19 @@ mod bench { #[bench] fn factorial_100(bh: &mut BenchHarness) { - do bh.iter { factorial(100); } + bh.iter(|| factorial(100)); } #[bench] fn fib_100(bh: &mut BenchHarness) { - do bh.iter { fib(100); } + bh.iter(|| fib(100)); } #[bench] fn to_str(bh: &mut BenchHarness) { let fac = factorial(100); let fib = fib(100); - do bh.iter { fac.to_str(); } - do bh.iter { fib.to_str(); } + bh.iter(|| fac.to_str()); + bh.iter(|| fib.to_str()); } } diff --git a/src/libextra/num/rational.rs b/src/libextra/num/rational.rs index 19cb483992017..1aa03350305fc 100644 --- a/src/libextra/num/rational.rs +++ b/src/libextra/num/rational.rs @@ -297,12 +297,12 @@ impl return None } let a_option: Option = FromStr::from_str(split[0]); - do a_option.and_then |a| { + a_option.and_then(|a| { let b_option: Option = FromStr::from_str(split[1]); - do b_option.and_then |b| { + b_option.and_then(|b| { Some(Ratio::new(a.clone(), b.clone())) - } - } + }) + }) } } impl @@ -315,13 +315,13 @@ impl } else { let a_option: Option = FromStrRadix::from_str_radix(split[0], radix); - do a_option.and_then |a| { + a_option.and_then(|a| { let b_option: Option = FromStrRadix::from_str_radix(split[1], radix); - do b_option.and_then |b| { + b_option.and_then(|b| { Some(Ratio::new(a.clone(), b.clone())) - } - } + }) + }) } } } diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index 616125c9960ea..cdaac93c1fcd3 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -238,14 +238,14 @@ pub fn parse(s: &str) -> Option { } let s = s.trim(); let mut bad = false; - do bad_parse::cond.trap(|_| { debug!("bad"); bad = true }).inside { + bad_parse::cond.trap(|_| { debug!("bad"); bad = true }).inside(|| { let v = parse_iter(&mut s.chars()); if bad || v.to_str() != s.to_owned() { None } else { Some(v) } - } + }) } #[test] diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 9b0e00a41e508..aa63ac102e492 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -440,74 +440,74 @@ impl + 'static> Decodable for @mut T { impl<'self, S:Encoder,T:Encodable> Encodable for &'self [T] { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s)) } - } + }) } } impl> Encodable for ~[T] { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s)) } - } + }) } } impl> Decodable for ~[T] { fn decode(d: &mut D) -> ~[T] { - do d.read_seq |d, len| { - do vec::from_fn(len) |i| { + d.read_seq(|d, len| { + vec::from_fn(len, |i| { d.read_seq_elt(i, |d| Decodable::decode(d)) - } - } + }) + }) } } impl> Encodable for @[T] { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s)) } - } + }) } } impl> Decodable for @[T] { fn decode(d: &mut D) -> @[T] { - do d.read_seq |d, len| { - do at_vec::from_fn(len) |i| { + d.read_seq(|d, len| { + at_vec::from_fn(len, |i| { d.read_seq_elt(i, |d| Decodable::decode(d)) - } - } + }) + }) } } impl> Encodable for Option { fn encode(&self, s: &mut S) { - do s.emit_option |s| { + s.emit_option(|s| { match *self { None => s.emit_option_none(), Some(ref v) => s.emit_option_some(|s| v.encode(s)), } - } + }) } } impl> Decodable for Option { fn decode(d: &mut D) -> Option { - do d.read_option |d, b| { + d.read_option(|d, b| { if b { Some(Decodable::decode(d)) } else { None } - } + }) } } @@ -515,10 +515,10 @@ impl,T1:Encodable> Encodable for (T0, T1) { fn encode(&self, s: &mut S) { match *self { (ref t0, ref t1) => { - do s.emit_seq(2) |s| { + s.emit_seq(2, |s| { s.emit_seq_elt(0, |s| t0.encode(s)); s.emit_seq_elt(1, |s| t1.encode(s)); - } + }) } } } @@ -526,13 +526,13 @@ impl,T1:Encodable> Encodable for (T0, T1) { impl,T1:Decodable> Decodable for (T0, T1) { fn decode(d: &mut D) -> (T0, T1) { - do d.read_seq |d, len| { + d.read_seq(|d, len| { assert_eq!(len, 2); ( d.read_seq_elt(0, |d| Decodable::decode(d)), d.read_seq_elt(1, |d| Decodable::decode(d)) ) - } + }) } } @@ -545,11 +545,11 @@ impl< fn encode(&self, s: &mut S) { match *self { (ref t0, ref t1, ref t2) => { - do s.emit_seq(3) |s| { + s.emit_seq(3, |s| { s.emit_seq_elt(0, |s| t0.encode(s)); s.emit_seq_elt(1, |s| t1.encode(s)); s.emit_seq_elt(2, |s| t2.encode(s)); - } + }) } } } @@ -562,14 +562,14 @@ impl< T2: Decodable > Decodable for (T0, T1, T2) { fn decode(d: &mut D) -> (T0, T1, T2) { - do d.read_seq |d, len| { + d.read_seq(|d, len| { assert_eq!(len, 3); ( d.read_seq_elt(0, |d| Decodable::decode(d)), d.read_seq_elt(1, |d| Decodable::decode(d)), d.read_seq_elt(2, |d| Decodable::decode(d)) ) - } + }) } } @@ -583,12 +583,12 @@ impl< fn encode(&self, s: &mut S) { match *self { (ref t0, ref t1, ref t2, ref t3) => { - do s.emit_seq(4) |s| { + s.emit_seq(4, |s| { s.emit_seq_elt(0, |s| t0.encode(s)); s.emit_seq_elt(1, |s| t1.encode(s)); s.emit_seq_elt(2, |s| t2.encode(s)); s.emit_seq_elt(3, |s| t3.encode(s)); - } + }) } } } @@ -602,7 +602,7 @@ impl< T3: Decodable > Decodable for (T0, T1, T2, T3) { fn decode(d: &mut D) -> (T0, T1, T2, T3) { - do d.read_seq |d, len| { + d.read_seq(|d, len| { assert_eq!(len, 4); ( d.read_seq_elt(0, |d| Decodable::decode(d)), @@ -610,7 +610,7 @@ impl< d.read_seq_elt(2, |d| Decodable::decode(d)), d.read_seq_elt(3, |d| Decodable::decode(d)) ) - } + }) } } @@ -625,13 +625,13 @@ impl< fn encode(&self, s: &mut S) { match *self { (ref t0, ref t1, ref t2, ref t3, ref t4) => { - do s.emit_seq(5) |s| { + s.emit_seq(5, |s| { s.emit_seq_elt(0, |s| t0.encode(s)); s.emit_seq_elt(1, |s| t1.encode(s)); s.emit_seq_elt(2, |s| t2.encode(s)); s.emit_seq_elt(3, |s| t3.encode(s)); s.emit_seq_elt(4, |s| t4.encode(s)); - } + }) } } } @@ -646,7 +646,7 @@ impl< T4: Decodable > Decodable for (T0, T1, T2, T3, T4) { fn decode(d: &mut D) -> (T0, T1, T2, T3, T4) { - do d.read_seq |d, len| { + d.read_seq(|d, len| { assert_eq!(len, 5); ( d.read_seq_elt(0, |d| Decodable::decode(d)), @@ -655,7 +655,7 @@ impl< d.read_seq_elt(3, |d| Decodable::decode(d)), d.read_seq_elt(4, |d| Decodable::decode(d)) ) - } + }) } } @@ -664,22 +664,22 @@ impl< T: Encodable > Encodable for DList { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s)); } - } + }) } } impl> Decodable for DList { fn decode(d: &mut D) -> DList { let mut list = DList::new(); - do d.read_seq |d, len| { + d.read_seq(|d, len| { for i in range(0u, len) { list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))); } - } + }); list } } @@ -689,22 +689,22 @@ impl< T: Encodable > Encodable for RingBuf { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s)); } - } + }) } } impl> Decodable for RingBuf { fn decode(d: &mut D) -> RingBuf { let mut deque = RingBuf::new(); - do d.read_seq |d, len| { + d.read_seq(|d, len| { for i in range(0u, len) { deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))); } - } + }); deque } } @@ -715,14 +715,14 @@ impl< V: Encodable > Encodable for HashMap { fn encode(&self, e: &mut E) { - do e.emit_map(self.len()) |e| { + e.emit_map(self.len(), |e| { let mut i = 0; for (key, val) in self.iter() { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; } - } + }) } } @@ -732,7 +732,7 @@ impl< V: Decodable > Decodable for HashMap { fn decode(d: &mut D) -> HashMap { - do d.read_map |d, len| { + d.read_map(|d, len| { let mut map = HashMap::with_capacity(len); for i in range(0u, len) { let key = d.read_map_elt_key(i, |d| Decodable::decode(d)); @@ -740,7 +740,7 @@ impl< map.insert(key, val); } map - } + }) } } @@ -749,13 +749,13 @@ impl< T: Encodable + Hash + IterBytes + Eq > Encodable for HashSet { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { let mut i = 0; for e in self.iter() { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; } - } + }) } } @@ -764,13 +764,13 @@ impl< T: Decodable + Hash + IterBytes + Eq > Decodable for HashSet { fn decode(d: &mut D) -> HashSet { - do d.read_seq |d, len| { + d.read_seq(|d, len| { let mut set = HashSet::with_capacity(len); for i in range(0u, len) { set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))); } set - } + }) } } @@ -779,15 +779,15 @@ impl< V: Encodable > Encodable for TrieMap { fn encode(&self, e: &mut E) { - do e.emit_map(self.len()) |e| { + e.emit_map(self.len(), |e| { let mut i = 0; - do self.each |key, val| { + self.each(|key, val| { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; true - }; - } + }); + }) } } @@ -796,7 +796,7 @@ impl< V: Decodable > Decodable for TrieMap { fn decode(d: &mut D) -> TrieMap { - do d.read_map |d, len| { + d.read_map(|d, len| { let mut map = TrieMap::new(); for i in range(0u, len) { let key = d.read_map_elt_key(i, |d| Decodable::decode(d)); @@ -804,32 +804,32 @@ impl< map.insert(key, val); } map - } + }) } } impl Encodable for TrieSet { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { let mut i = 0; - do self.each |e| { + self.each(|e| { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; true - }; - } + }); + }) } } impl Decodable for TrieSet { fn decode(d: &mut D) -> TrieSet { - do d.read_seq |d, len| { + d.read_seq(|d, len| { let mut set = TrieSet::new(); for i in range(0u, len) { set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))); } set - } + }) } } @@ -839,14 +839,14 @@ impl< V: Encodable + Eq > Encodable for TreeMap { fn encode(&self, e: &mut E) { - do e.emit_map(self.len()) |e| { + e.emit_map(self.len(), |e| { let mut i = 0; for (key, val) in self.iter() { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; } - } + }) } } @@ -856,7 +856,7 @@ impl< V: Decodable + Eq > Decodable for TreeMap { fn decode(d: &mut D) -> TreeMap { - do d.read_map |d, len| { + d.read_map(|d, len| { let mut map = TreeMap::new(); for i in range(0u, len) { let key = d.read_map_elt_key(i, |d| Decodable::decode(d)); @@ -864,7 +864,7 @@ impl< map.insert(key, val); } map - } + }) } } @@ -873,13 +873,13 @@ impl< T: Encodable + Eq + TotalOrd > Encodable for TreeSet { fn encode(&self, s: &mut S) { - do s.emit_seq(self.len()) |s| { + s.emit_seq(self.len(), |s| { let mut i = 0; for e in self.iter() { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; } - } + }) } } @@ -888,13 +888,13 @@ impl< T: Decodable + Eq + TotalOrd > Decodable for TreeSet { fn decode(d: &mut D) -> TreeSet { - do d.read_seq |d, len| { + d.read_seq(|d, len| { let mut set = TreeSet::new(); for i in range(0u, len) { set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))); } set - } + }) } } @@ -909,13 +909,13 @@ pub trait EncoderHelpers { impl EncoderHelpers for S { fn emit_from_vec(&mut self, v: &[T], f: |&mut S, &T|) { - do self.emit_seq(v.len()) |this| { + self.emit_seq(v.len(), |this| { for (i, e) in v.iter().enumerate() { - do this.emit_seq_elt(i) |this| { + this.emit_seq_elt(i, |this| { f(this, e) - } + }) } - } + }) } } @@ -925,10 +925,10 @@ pub trait DecoderHelpers { impl DecoderHelpers for D { fn read_to_vec(&mut self, f: |&mut D| -> T) -> ~[T] { - do self.read_seq |this, len| { - do vec::from_fn(len) |i| { + self.read_seq(|this, len| { + vec::from_fn(len, |i| { this.read_seq_elt(i, |this| f(this)) - } - } + }) + }) } } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index d7b2d5ea4d670..f87ba4ed6a3e0 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -104,16 +104,16 @@ impl Sem { pub fn acquire(&self) { unsafe { let mut waiter_nobe = None; - do (**self).with |state| { + (**self).with(|state| { state.count -= 1; if state.count < 0 { // Create waiter nobe, enqueue ourself, and tell // outer scope we need to block. waiter_nobe = Some(state.waiters.wait_end()); } - } + }); // Uncomment if you wish to test for sem races. Not valgrind-friendly. - /* do 1000.times { task::deschedule(); } */ + /* 1000.times(|| task::deschedule()); */ // Need to wait outside the exclusive. if waiter_nobe.is_some() { let _ = waiter_nobe.unwrap().recv(); @@ -123,22 +123,22 @@ impl Sem { pub fn release(&self) { unsafe { - do (**self).with |state| { + (**self).with(|state| { state.count += 1; if state.count <= 0 { state.waiters.signal(); } - } + }) } } pub fn access(&self, blk: || -> U) -> U { - do (|| { + (|| { self.acquire(); blk() - }).finally { + }).finally(|| { self.release(); - } + }) } } @@ -147,9 +147,7 @@ impl Sem<~[WaitQueue]> { fn new_and_signal(count: int, num_condvars: uint) -> Sem<~[WaitQueue]> { let mut queues = ~[]; - do num_condvars.times { - queues.push(WaitQueue::new()); - } + num_condvars.times(|| queues.push(WaitQueue::new())); Sem::new(count, queues) } } @@ -205,7 +203,7 @@ impl<'self> Condvar<'self> { let mut out_of_bounds = None; // Release lock, 'atomically' enqueuing ourselves in so doing. unsafe { - do (**self.sem).with |state| { + (**self.sem).with(|state| { if condvar_id < state.blocked.len() { // Drop the lock. state.count += 1; @@ -218,18 +216,18 @@ impl<'self> Condvar<'self> { } else { out_of_bounds = Some(state.blocked.len()); } - } + }) } // If deschedule checks start getting inserted anywhere, we can be // killed before or after enqueueing. - do check_cvar_bounds(out_of_bounds, condvar_id, "cond.wait_on()") { + check_cvar_bounds(out_of_bounds, condvar_id, "cond.wait_on()", || { // Unconditionally "block". (Might not actually block if a // signaller already sent -- I mean 'unconditionally' in contrast // with acquire().) - do (|| { + (|| { let _ = WaitEnd.take_unwrap().recv(); - }).finally { + }).finally(|| { // Reacquire the condvar. match self.order { Just(lock) => do lock.access { @@ -239,8 +237,8 @@ impl<'self> Condvar<'self> { self.sem.acquire(); }, } - } - } + }) + }) } /// Wake up a blocked task. Returns false if there was no blocked task. @@ -251,16 +249,17 @@ impl<'self> Condvar<'self> { unsafe { let mut out_of_bounds = None; let mut result = false; - do (**self.sem).with |state| { + (**self.sem).with(|state| { if condvar_id < state.blocked.len() { result = state.blocked[condvar_id].signal(); } else { out_of_bounds = Some(state.blocked.len()); } - } - do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") { - result - } + }); + check_cvar_bounds(out_of_bounds, + condvar_id, + "cond.signal_on()", + || result) } } @@ -272,7 +271,7 @@ impl<'self> Condvar<'self> { let mut out_of_bounds = None; let mut queue = None; unsafe { - do (**self.sem).with |state| { + (**self.sem).with(|state| { if condvar_id < state.blocked.len() { // To avoid :broadcast_heavy, we make a new waitqueue, // swap it out with the old one, and broadcast on the @@ -282,11 +281,14 @@ impl<'self> Condvar<'self> { } else { out_of_bounds = Some(state.blocked.len()); } - } - do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") { + }); + check_cvar_bounds(out_of_bounds, + condvar_id, + "cond.signal_on()", + || { let queue = queue.take_unwrap(); queue.broadcast() - } + }) } } } @@ -315,9 +317,13 @@ 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: |c: &Condvar| -> U) -> U { - do self.access { - blk(&Condvar { sem: self, order: Nothing, token: NonCopyable }) - } + self.access(|| { + blk(&Condvar { + sem: self, + order: Nothing, + token: NonCopyable + }) + }) } } @@ -474,17 +480,17 @@ impl RWLock { */ pub fn read(&self, blk: || -> U) -> U { unsafe { - do (&self.order_lock).access { + (&self.order_lock).access(|| { let state = &mut *self.state.get(); let old_count = state.read_count.fetch_add(1, atomics::Acquire); if old_count == 0 { (&self.access_lock).acquire(); state.read_mode = true; } - } - do (|| { + }); + (|| { blk() - }).finally { + }).finally(|| { let state = &mut *self.state.get(); assert!(state.read_mode); let old_count = state.read_count.fetch_sub(1, atomics::Release); @@ -497,7 +503,7 @@ impl RWLock { // this access MUST NOT go inside the exclusive access. (&self.access_lock).release(); } - } + }) } } @@ -507,10 +513,10 @@ impl RWLock { */ pub fn write(&self, blk: || -> U) -> U { (&self.order_lock).acquire(); - do (&self.access_lock).access { + (&self.access_lock).access(|| { (&self.order_lock).release(); blk() - } + }) } /** @@ -547,12 +553,12 @@ impl RWLock { // The astute reader will also note that making waking writers use the // order_lock is better for not starving readers. (&self.order_lock).acquire(); - do (&self.access_lock).access_cond |cond| { + (&self.access_lock).access_cond(|cond| { (&self.order_lock).release(); let opt_lock = Just(&self.order_lock); blk(&Condvar { sem: cond.sem, order: opt_lock, token: NonCopyable }) - } + }) } /** @@ -582,9 +588,9 @@ impl RWLock { (&self.order_lock).acquire(); (&self.access_lock).acquire(); (&self.order_lock).release(); - do (|| { + (|| { blk(RWLockWriteMode { lock: self, token: NonCopyable }) - }).finally { + }).finally(|| { let writer_or_last_reader; // Check if we're releasing from read mode or from write mode. let state = unsafe { &mut *self.state.get() }; @@ -609,7 +615,7 @@ impl RWLock { // Nobody left inside; release the "reader cloud" lock. (&self.access_lock).release(); } - } + }) } /// To be called inside of the write_downgrade block. diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 37deba43e3a15..1bb07a396ffda 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -53,7 +53,7 @@ impl TaskPool { -> TaskPool { assert!(n_tasks >= 1); - let channels = do vec::from_fn(n_tasks) |i| { + let channels = vec::from_fn(n_tasks, |i| { let (port, chan) = comm::stream::>(); let init_fn = init_fn_factory(); @@ -81,7 +81,7 @@ impl TaskPool { } chan - }; + }); return TaskPool { channels: channels, next_index: 0 }; } diff --git a/src/libextra/term.rs b/src/libextra/term.rs index 4eac6eada22c5..aace15ee7a671 100644 --- a/src/libextra/term.rs +++ b/src/libextra/term.rs @@ -220,9 +220,9 @@ impl Terminal { cap = self.ti.strings.find_equiv(&("op")); } } - let s = do cap.map_default(Err(~"can't find terminfo capability `sgr0`")) |op| { + let s = cap.map_default(Err(~"can't find terminfo capability `sgr0`"), |op| { expand(*op, [], &mut Variables::new()) - }; + }); if s.is_ok() { self.out.write(s.unwrap()); } else if self.num_colors > 0 { diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs index c0a5d9d53aa9e..eac450d9562f2 100644 --- a/src/libextra/terminfo/parm.rs +++ b/src/libextra/terminfo/parm.rs @@ -494,14 +494,14 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { match op { FormatDigit => { let sign = if flags.sign { SignAll } else { SignNeg }; - do int_to_str_bytes_common(d, radix, sign) |c| { + int_to_str_bytes_common(d, radix, sign, |c| { s.push(c); - } + }) } _ => { - do int_to_str_bytes_common(d as uint, radix, SignNone) |c| { + int_to_str_bytes_common(d as uint, radix, SignNone, |c| { s.push(c); - } + }) } }; if flags.precision > s.len() { diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 87bd314c8fb0a..c94cb196bea6b 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -176,7 +176,7 @@ pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) { // semantics into parallel test runners, which in turn requires a ~[] // rather than a &[]. pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) { - let owned_tests = do tests.map |t| { + let owned_tests = tests.map(|t| { match t.testfn { StaticTestFn(f) => TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() }, @@ -188,7 +188,7 @@ pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) { fail!("non-static tests passed to test::test_main_static"); } } - }; + }); test_main(args, owned_tests) } @@ -730,12 +730,12 @@ fn run_tests(opts: &TestOpts, callback(TeFiltered(filtered_descs)); let (filtered_tests, filtered_benchs_and_metrics) = - do filtered_tests.partition |e| { - match e.testfn { - StaticTestFn(_) | DynTestFn(_) => true, - _ => false - } - }; + filtered_tests.partition(|e| { + match e.testfn { + StaticTestFn(_) | DynTestFn(_) => true, + _ => false + } + }); // It's tempting to just spawn all the tests at once, but since we have // many tests that run in other processes we would be making a big mess. @@ -1044,12 +1044,12 @@ impl MetricMap { }; let diff : MetricDiff = self.compare_to_old(&old, pct); - let ok = do diff.iter().all() |(_, v)| { + let ok = diff.iter().all(|(_, v)| { match *v { Regression(_) => false, _ => true } - }; + }); if ok { debug!("rewriting file '{:?}' with updated metrics", p); diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 9912e3d6ef701..05bca853e3bb5 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -394,7 +394,7 @@ impl<'self, T> Iterator<&'self T> for TreeSetIterator<'self, T> { /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`. #[inline] fn next(&mut self) -> Option<&'self T> { - do self.iter.next().map |(value, _)| { value } + self.iter.next().map(|(value, _)| value) } } @@ -402,7 +402,7 @@ impl<'self, T> Iterator<&'self T> for TreeSetRevIterator<'self, T> { /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`. #[inline] fn next(&mut self) -> Option<&'self T> { - do self.iter.next().map |(value, _)| { value } + self.iter.next().map(|(value, _)| value) } } diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 09f95800b3dc1..beb211339083d 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -373,7 +373,7 @@ impl<'self> Prep<'self> { None => fail!("missing freshness-function for '{}'", kind), Some(f) => (*f)(name, val) }; - do self.ctxt.logger.write |lg| { + self.ctxt.logger.write(|lg| { if fresh { lg.info(format!("{} {}:{} is fresh", cat, kind, name)); @@ -381,7 +381,7 @@ impl<'self> Prep<'self> { lg.info(format!("{} {}:{} is not fresh", cat, kind, name)) } - }; + }); fresh } @@ -411,9 +411,9 @@ impl<'self> Prep<'self> { debug!("exec_work: looking up {} and {:?}", self.fn_name, self.declared_inputs); - let cached = do self.ctxt.db.read |db| { + let cached = self.ctxt.db.read(|db| { db.prepare(self.fn_name, &self.declared_inputs) - }; + }); match cached { Some((ref disc_in, ref disc_out, ref res)) @@ -432,7 +432,7 @@ impl<'self> Prep<'self> { let blk = bo.take_unwrap(); let chan = Cell::new(chan); -// What happens if the task fails? + // XXX: What happens if the task fails? do task::spawn { let mut exe = Exec { discovered_inputs: WorkMap::new(), @@ -467,13 +467,13 @@ impl<'self, T:Send + WorkFromTask(prep, port) => { let (exe, v) = port.recv(); let s = json_encode(&v); - do prep.ctxt.db.write |db| { + prep.ctxt.db.write(|db| { db.cache(prep.fn_name, &prep.declared_inputs, &exe.discovered_inputs, &exe.discovered_outputs, - s); - } + s) + }); v } } @@ -507,7 +507,7 @@ fn test() { RWArc::new(Logger::new()), Arc::new(TreeMap::new())); - let s = do cx.with_prep("test1") |prep| { + let s = cx.with_prep("test1", |prep| { let subcx = cx.clone(); let pth = pth.clone(); @@ -529,7 +529,7 @@ fn test() { // FIXME (#9639): This needs to handle non-utf8 paths out.as_str().unwrap().to_owned() } - }; + }); println(s); } diff --git a/src/librustuv/addrinfo.rs b/src/librustuv/addrinfo.rs index e90d320e72321..da096880859bc 100644 --- a/src/librustuv/addrinfo.rs +++ b/src/librustuv/addrinfo.rs @@ -55,11 +55,11 @@ impl GetAddrInfoRequest { let hint = hints.map(|hint| { let mut flags = 0; - do each_ai_flag |cval, aival| { + each_ai_flag(|cval, aival| { if hint.flags & (aival as uint) != 0 { flags |= cval as i32; } - } + }); let socktype = 0; let protocol = 0; @@ -86,9 +86,9 @@ impl GetAddrInfoRequest { req.defuse(); // uv callback now owns this request let mut cx = Ctx { slot: None, status: 0, addrinfo: None }; - do wait_until_woken_after(&mut cx.slot) { + wait_until_woken_after(&mut cx.slot, || { req.set_data(&cx); - } + }); match cx.status { 0 => Ok(accum_addrinfo(cx.addrinfo.get_ref())), @@ -144,11 +144,11 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] { let rustaddr = net::sockaddr_to_socket_addr((*addr).ai_addr); let mut flags = 0; - do each_ai_flag |cval, aival| { + each_ai_flag(|cval, aival| { if (*addr).ai_flags & cval != 0 { flags |= aival as uint; } - } + }); /* XXX: do we really want to support these let protocol = match (*addr).ai_protocol { diff --git a/src/librustuv/async.rs b/src/librustuv/async.rs index 04e7bce5bd181..0f1e967f9bc46 100644 --- a/src/librustuv/async.rs +++ b/src/librustuv/async.rs @@ -111,14 +111,14 @@ impl RemoteCallback for AsyncWatcher { impl Drop for AsyncWatcher { fn drop(&mut self) { unsafe { - do self.exit_flag.with |should_exit| { + self.exit_flag.with(|should_exit| { // NB: These two things need to happen atomically. Otherwise // the event handler could wake up due to a *previous* // signal and see the exit flag, destroying the handle // before the final send. *should_exit = true; uvll::uv_async_send(self.handle) - } + }) } } } diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index a94ae695eb743..7aef62af8eef4 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -86,13 +86,13 @@ impl FsRequest { pub fn read(loop_: &Loop, fd: c_int, buf: &mut [u8], offset: i64) -> Result { - do execute(|req, cb| unsafe { + execute(|req, cb| unsafe { uvll::uv_fs_read(loop_.handle, req, fd, vec::raw::to_ptr(buf) as *c_void, buf.len() as size_t, offset, cb) - }).map |req| { + }).map(|req| { req.get_result() as int - } + }) } pub fn mkdir(loop_: &Loop, path: &CString, mode: c_int) @@ -142,24 +142,25 @@ impl FsRequest { let mut paths = ~[]; let path = CString::new(path.with_ref(|p| p), false); let parent = Path::new(path); - do c_str::from_c_multistring(req.get_ptr() as *libc::c_char, - Some(req.get_result() as uint)) |rel| { + c_str::from_c_multistring(req.get_ptr() as *libc::c_char, + Some(req.get_result() as uint), + |rel| { let p = rel.as_bytes(); paths.push(parent.join(p.slice_to(rel.len()))); - }; + }); paths }) } pub fn readlink(loop_: &Loop, path: &CString) -> Result { - do execute(|req, cb| unsafe { + execute(|req, cb| unsafe { uvll::uv_fs_readlink(loop_.handle, req, path.with_ref(|p| p), cb) - }).map |req| { + }).map(|req| { Path::new(unsafe { CString::new(req.get_ptr() as *libc::c_char, false) }) - } + }) } pub fn chown(loop_: &Loop, path: &CString, uid: int, gid: int) @@ -305,16 +306,15 @@ fn execute(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int) 0 => { req.fired = true; let mut slot = None; - do wait_until_woken_after(&mut slot) { + wait_until_woken_after(&mut slot, || { unsafe { uvll::set_data_for_req(req.req, &slot) } - } + }); match req.get_result() { n if n < 0 => Err(UvError(n)), _ => Ok(req), } } n => Err(UvError(n)) - }; extern fn fs_cb(req: *uvll::uv_fs_t) { diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 4690a347f1143..205a2d20e9214 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -138,9 +138,9 @@ pub trait UvHandle { uvll::uv_close(self.uv_handle() as *uvll::uv_handle_t, close_cb); uvll::set_data_for_uv_handle(self.uv_handle(), ptr::null::<()>()); - do wait_until_woken_after(&mut slot) { + wait_until_woken_after(&mut slot, || { uvll::set_data_for_uv_handle(self.uv_handle(), &slot); - } + }) } extern fn close_cb(handle: *uvll::uv_handle_t) { @@ -201,10 +201,10 @@ fn wait_until_woken_after(slot: *mut Option, f: ||) { unsafe { assert!((*slot).is_none()); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |_, task| { + sched.deschedule_running_task_and_then(|_, task| { f(); *slot = Some(task); - } + }) } } @@ -390,7 +390,7 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf { #[cfg(test)] fn local_loop() -> &'static mut Loop { unsafe { - cast::transmute(do Local::borrow |sched: &mut Scheduler| { + cast::transmute(Local::borrow(|sched: &mut Scheduler| { let mut io = None; do sched.event_loop.io |i| { let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) = @@ -398,7 +398,7 @@ fn local_loop() -> &'static mut Loop { io = Some(uvio); } io.unwrap() - }.uv_loop()) + }).uv_loop()) } } diff --git a/src/librustuv/macros.rs b/src/librustuv/macros.rs index 71744c717d4bd..eb679553e7642 100644 --- a/src/librustuv/macros.rs +++ b/src/librustuv/macros.rs @@ -29,7 +29,7 @@ macro_rules! uvdebug ( // get a handle for the current scheduler macro_rules! get_handle_to_current_scheduler( - () => (do Local::borrow |sched: &mut Scheduler| { sched.make_handle() }) + () => (Local::borrow(|sched: &mut Scheduler| sched.make_handle())) ) pub fn dumb_println(args: &fmt::Arguments) { diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 0e90e01c46aff..cad1ac6709f7b 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -42,11 +42,11 @@ fn socket_addr_as_sockaddr(addr: SocketAddr, f: |*sockaddr| -> T) -> T { let ip = addr.ip.to_str(); let addr = ip.with_c_str(|p| unsafe { malloc(p, addr.port as c_int) }); - do (|| { + (|| { f(addr) - }).finally { + }).finally(|| { unsafe { libc::free(addr) }; - } + }) } pub fn sockaddr_to_socket_addr(addr: *sockaddr) -> SocketAddr { @@ -88,9 +88,9 @@ pub fn sockaddr_to_socket_addr(addr: *sockaddr) -> SocketAddr { fn test_ip4_conversion() { use std::rt; let ip4 = rt::test::next_test_ip4(); - do socket_addr_as_sockaddr(ip4) |addr| { + socket_addr_as_sockaddr(ip4, |addr| { assert_eq!(ip4, sockaddr_to_socket_addr(addr)); - } + }) } #[cfg(test)] @@ -98,9 +98,9 @@ fn test_ip4_conversion() { fn test_ip6_conversion() { use std::rt; let ip6 = rt::test::next_test_ip6(); - do socket_addr_as_sockaddr(ip6) |addr| { + socket_addr_as_sockaddr(ip6, |addr| { assert_eq!(ip6, sockaddr_to_socket_addr(addr)); - } + }) } enum SocketNameKind { @@ -176,7 +176,7 @@ impl TcpWatcher { struct Ctx { status: c_int, task: Option } let tcp = TcpWatcher::new(loop_); - let ret = do socket_addr_as_sockaddr(address) |addr| { + let ret = socket_addr_as_sockaddr(address, |addr| { let mut req = Request::new(uvll::UV_CONNECT); let result = unsafe { uvll::uv_tcp_connect(req.handle, tcp.handle, addr, @@ -196,7 +196,7 @@ impl TcpWatcher { } n => Err(UvError(n)) } - }; + }); return match ret { Ok(()) => Ok(tcp), @@ -286,8 +286,7 @@ impl Drop for TcpWatcher { impl TcpListener { pub fn bind(loop_: &mut Loop, address: SocketAddr) - -> Result<~TcpListener, UvError> - { + -> Result<~TcpListener, UvError> { let handle = unsafe { uvll::malloc_handle(uvll::UV_TCP) }; assert_eq!(unsafe { uvll::uv_tcp_init(loop_.handle, handle) @@ -419,8 +418,7 @@ pub struct UdpWatcher { impl UdpWatcher { pub fn bind(loop_: &Loop, address: SocketAddr) - -> Result - { + -> Result { let udp = UdpWatcher { handle: unsafe { uvll::malloc_handle(uvll::UV_UDP) }, home: get_handle_to_current_scheduler!(), @@ -473,9 +471,9 @@ impl rtio::RtioUdpSocket for UdpWatcher { buf: Some(slice_to_uv_buf(buf)), result: None, }; - do wait_until_woken_after(&mut cx.task) { + wait_until_woken_after(&mut cx.task, || { unsafe { uvll::set_data_for_uv_handle(self.handle, &cx) } - } + }); match cx.result.take_unwrap() { (n, _) if n < 0 => Err(uv_error_to_io_error(UvError(n as c_int))), @@ -545,9 +543,9 @@ impl rtio::RtioUdpSocket for UdpWatcher { 0 => { req.defuse(); // uv callback now owns this request let mut cx = Ctx { task: None, result: 0 }; - do wait_until_woken_after(&mut cx.task) { + wait_until_woken_after(&mut cx.task, || { req.set_data(&cx); - } + }); match cx.result { 0 => Ok(()), n => Err(uv_error_to_io_error(UvError(n))) @@ -570,22 +568,22 @@ impl rtio::RtioUdpSocket for UdpWatcher { fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { let _m = self.fire_homing_missile(); status_to_io_result(unsafe { - do multi.to_str().with_c_str |m_addr| { + multi.to_str().with_c_str(|m_addr| { uvll::uv_udp_set_membership(self.handle, m_addr, ptr::null(), uvll::UV_JOIN_GROUP) - } + }) }) } fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { let _m = self.fire_homing_missile(); status_to_io_result(unsafe { - do multi.to_str().with_c_str |m_addr| { + multi.to_str().with_c_str(|m_addr| { uvll::uv_udp_set_membership(self.handle, m_addr, ptr::null(), uvll::UV_LEAVE_GROUP) - } + }) }) } @@ -1101,11 +1099,11 @@ mod test { }; unsafe fn local_io() -> &'static mut IoFactory { - do Local::borrow |sched: &mut Scheduler| { + Local::borrow(|sched: &mut Scheduler| { let mut io = None; sched.event_loop.io(|i| io = Some(i)); cast::transmute(io.unwrap()) - } + }) } let test_function: proc() = || { @@ -1117,14 +1115,14 @@ mod test { // block self on sched1 let scheduler: ~Scheduler = Local::take(); - do scheduler.deschedule_running_task_and_then |_, task| { + scheduler.deschedule_running_task_and_then(|_, task| { // unblock task - do task.wake().map |task| { + task.wake().map(|task| { // send self to sched2 tasksFriendHandle.take().send(TaskFromFriend(task)); - }; + }); // sched1 should now sleep since it has nothing else to do - } + }) // sched2 will wake up and get the task as we do nothing else, // the function ends and the socket goes out of scope sched2 // will start to run the destructor the destructor will first diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index 3bce635aa9b4d..6b48e823e4286 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -77,7 +77,7 @@ impl PipeWatcher { let mut req = Request::new(uvll::UV_CONNECT); let pipe = PipeWatcher::new(loop_, false); - do wait_until_woken_after(&mut cx.task) { + wait_until_woken_after(&mut cx.task, || { unsafe { uvll::uv_pipe_connect(req.handle, pipe.handle(), @@ -86,7 +86,7 @@ impl PipeWatcher { } req.set_data(&cx); req.defuse(); // uv callback now owns this request - } + }); return match cx.result { 0 => Ok(pipe), n => Err(UvError(n)) diff --git a/src/librustuv/process.rs b/src/librustuv/process.rs index 1ab84210face7..0577d19ec4603 100644 --- a/src/librustuv/process.rs +++ b/src/librustuv/process.rs @@ -57,8 +57,8 @@ impl Process { } } - let ret = do with_argv(config.program, config.args) |argv| { - do with_env(config.env) |envp| { + let ret = with_argv(config.program, config.args, |argv| { + with_env(config.env, |envp| { let options = uvll::uv_process_options_t { exit_cb: on_exit, file: unsafe { *argv }, @@ -88,8 +88,8 @@ impl Process { 0 => Ok(process.install()), err => Err(UvError(err)), } - } - }; + }) + }); match ret { Ok(p) => Ok((p, ret_io)), diff --git a/src/librustuv/stream.rs b/src/librustuv/stream.rs index 47ef26ee9d42c..0304b89dd6fde 100644 --- a/src/librustuv/stream.rs +++ b/src/librustuv/stream.rs @@ -123,9 +123,9 @@ impl StreamWatcher { let mut wcx = WriteContext { result: 0, task: None, }; req.defuse(); // uv callback now owns this request - do wait_until_woken_after(&mut wcx.task) { + wait_until_woken_after(&mut wcx.task, || { req.set_data(&wcx); - } + }); self.last_write_req = Some(Request::wrap(req.handle)); match wcx.result { 0 => Ok(()), diff --git a/src/librustuv/timer.rs b/src/librustuv/timer.rs index 0176399030517..b7babed05024b 100644 --- a/src/librustuv/timer.rs +++ b/src/librustuv/timer.rs @@ -88,10 +88,10 @@ impl RtioTimer for TimerWatcher { let _f = ForbidUnwind::new("timer"); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |_sched, task| { + sched.deschedule_running_task_and_then(|_sched, task| { self.action = Some(WakeTask(task)); self.start(msecs, 0); - } + }); self.stop(); } diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index fbf81a6f3a094..976c0fbf9bc57 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -46,23 +46,23 @@ pub trait HomingIO { let _f = ForbidUnwind::new("going home"); - let current_sched_id = do Local::borrow |sched: &mut Scheduler| { + let current_sched_id = Local::borrow(|sched: &mut Scheduler| { sched.sched_id() - }; + }); // Only need to invoke a context switch if we're not on the right // scheduler. if current_sched_id != self.home().sched_id { let scheduler: ~Scheduler = Local::take(); - do scheduler.deschedule_running_task_and_then |_, task| { - do task.wake().map |task| { + scheduler.deschedule_running_task_and_then(|_, task| { + task.wake().map(|task| { self.home().send(RunOnce(task)); - }; - } + }); + }) } - let current_sched_id = do Local::borrow |sched: &mut Scheduler| { + let current_sched_id = Local::borrow(|sched: &mut Scheduler| { sched.sched_id() - }; + }); assert!(current_sched_id == self.home().sched_id); self.home().sched_id @@ -114,11 +114,11 @@ impl Drop for HomingMissile { // original scheduler. Otherwise, we can just return and keep running if !Task::on_appropriate_sched() { let scheduler: ~Scheduler = Local::take(); - do scheduler.deschedule_running_task_and_then |_, task| { - do task.wake().map |task| { + scheduler.deschedule_running_task_and_then(|_, task| { + task.wake().map(|task| { Scheduler::run_task(task); - }; - } + }); + }) } util::ignore(f); From efc512362b0f2ae200ef079e3566c6b158a857cc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 20 Nov 2013 16:23:04 -0800 Subject: [PATCH 06/12] libsyntax: Remove all non-`proc` `do` syntax. --- src/libsyntax/abi.rs | 14 ++--- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/attr.rs | 28 +++++----- src/libsyntax/diagnostic.rs | 8 +-- src/libsyntax/ext/build.rs | 8 +-- src/libsyntax/ext/deriving/clone.rs | 4 +- src/libsyntax/ext/deriving/decodable.rs | 26 +++++---- src/libsyntax/ext/deriving/default.rs | 4 +- src/libsyntax/ext/deriving/encodable.rs | 16 +++--- src/libsyntax/ext/deriving/generic.rs | 68 ++++++++++++------------ src/libsyntax/ext/deriving/iter_bytes.rs | 4 +- src/libsyntax/ext/deriving/mod.rs | 4 +- src/libsyntax/ext/deriving/rand.rs | 8 +-- src/libsyntax/ext/deriving/ty.rs | 16 +++--- src/libsyntax/ext/deriving/zero.rs | 4 +- src/libsyntax/ext/expand.rs | 8 +-- src/libsyntax/ext/format.rs | 6 +-- src/libsyntax/ext/tt/macro_parser.rs | 10 ++-- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/fold.rs | 24 ++++----- src/libsyntax/parse/comments.rs | 8 ++- src/libsyntax/parse/lexer.rs | 16 +++--- src/libsyntax/parse/parser.rs | 46 ++++++++-------- src/libsyntax/parse/token.rs | 4 +- src/libsyntax/print/pprust.rs | 24 +++------ 26 files changed, 178 insertions(+), 192 deletions(-) diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 60d49b4c9edb7..9f69379f3c58c 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -104,14 +104,14 @@ pub fn lookup(name: &str) -> Option { let mut res = None; - do each_abi |abi| { + each_abi(|abi| { if name == abi.data().name { res = Some(abi); false } else { true } - }; + }); res } @@ -217,21 +217,21 @@ impl AbiSet { let mut res = None; - do self.each |abi| { + self.each(|abi| { let data = abi.data(); match data.abi_arch { Archs(a) if (a & arch.bit()) != 0 => { res = Some(abi); false } Archs(_) => { true } RustArch | AllArch => { res = Some(abi); false } } - }; + }); res.map(|r| r.for_target(os, arch)) } pub fn check_valid(&self) -> Option<(Abi, Abi)> { let mut abis = ~[]; - do self.each |abi| { abis.push(abi); true }; + self.each(|abi| { abis.push(abi); true }); for (i, abi) in abis.iter().enumerate() { let data = abi.data(); @@ -285,10 +285,10 @@ impl ToStr for Abi { impl ToStr for AbiSet { fn to_str(&self) -> ~str { let mut strs = ~[]; - do self.each |abi| { + self.each(|abi| { strs.push(abi.data().name); true - }; + }); format!("\"{}\"", strs.connect(" ")) } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f0be7057c70bf..32b270643afd2 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -52,13 +52,13 @@ pub type path = ~[path_elt]; pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) -> ~str { - let strs = do p.map |e| { + let strs = p.map(|e| { match *e { path_mod(s) | path_name(s) | path_pretty_name(s, _) => { itr.get(s.name) } } - }; + }); strs.connect(sep) } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c14375604b1e2..ef3c23f515380 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -254,12 +254,12 @@ pub fn unguarded_pat(a: &Arm) -> Option<~[@Pat]> { } pub fn public_methods(ms: ~[@method]) -> ~[@method] { - do ms.move_iter().filter |m| { + ms.move_iter().filter(|m| { match m.vis { public => true, _ => false } - }.collect() + }).collect() } // extract a TypeMethod from a trait_method. if the trait_method is diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 7a5a326add40f..ecde00aa30211 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -169,18 +169,18 @@ pub fn mk_sugared_doc_attr(text: @str, lo: BytePos, hi: BytePos) -> Attribute { pub fn contains(haystack: &[@ast::MetaItem], needle: @ast::MetaItem) -> bool { debug!("attr::contains (name={})", needle.name()); - do haystack.iter().any |item| { + haystack.iter().any(|item| { debug!(" testing: {}", item.name()); item.node == needle.node - } + }) } pub fn contains_name(metas: &[AM], name: &str) -> bool { debug!("attr::contains_name (name={})", name); - do metas.iter().any |item| { + metas.iter().any(|item| { debug!(" testing: {}", item.name()); name == item.name() - } + }) } pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) @@ -204,12 +204,10 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] { .map(|&mi| (mi.name(), mi)) .collect::<~[(@str, @MetaItem)]>(); - do extra::sort::quick_sort(v) |&(a, _), &(b, _)| { - a <= b - } + extra::sort::quick_sort(v, |&(a, _), &(b, _)| a <= b); // There doesn't seem to be a more optimal way to do this - do v.move_iter().map |(_, m)| { + v.move_iter().map(|(_, m)| { match m.node { MetaList(n, ref mis) => { @Spanned { @@ -219,7 +217,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] { } _ => m } - }.collect() + }).collect() } /** @@ -248,7 +246,7 @@ pub enum InlineAttr { /// True if something like #[inline] is found in the list of attrs. pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr { // FIXME (#2809)---validate the usage of #[inline] and #[inline] - do attrs.iter().fold(InlineNone) |ia,attr| { + attrs.iter().fold(InlineNone, |ia,attr| { match attr.node.value.node { MetaWord(n) if "inline" == n => InlineHint, MetaList(n, ref items) if "inline" == n => { @@ -262,7 +260,7 @@ pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr { } _ => ia } - } + }) } /// Tests if any `cfg(...)` meta items in `metas` match `cfg`. e.g. @@ -278,7 +276,7 @@ pub fn test_cfg> // this would be much nicer as a chain of iterator adaptors, but // this doesn't work. - let some_cfg_matches = do metas.any |mi| { + let some_cfg_matches = metas.any(|mi| { debug!("testing name: {}", mi.name()); if "cfg" == mi.name() { // it is a #[cfg()] attribute debug!("is cfg"); @@ -287,7 +285,7 @@ pub fn test_cfg> match mi.meta_item_list() { Some(cfg_meta) => { debug!("is cfg(...)"); - do cfg_meta.iter().all |cfg_mi| { + cfg_meta.iter().all(|cfg_mi| { debug!("cfg({}[...])", cfg_mi.name()); match cfg_mi.node { ast::MetaList(s, ref not_cfgs) if "not" == s => { @@ -301,14 +299,14 @@ pub fn test_cfg> } _ => contains(cfg, *cfg_mi) } - } + }) } None => false } } else { false } - }; + }); debug!("test_cfg (no_cfgs={}, some_cfg_matches={})", no_cfgs, some_cfg_matches); no_cfgs || some_cfg_matches } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index bb908919678b8..36e6bf32451f9 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -314,9 +314,7 @@ fn highlight_lines(cm: @codemap::CodeMap, // Skip is the number of characters we need to skip because they are // part of the 'filename:line ' part of the previous line. let skip = fm.name.len() + digits + 3u; - do skip.times() { - s.push_char(' '); - } + skip.times(|| s.push_char(' ')); let orig = fm.get_line(lines.lines[0] as int); for pos in range(0u, left-skip) { let curChar = (orig[pos] as char); @@ -335,9 +333,7 @@ fn highlight_lines(cm: @codemap::CodeMap, if hi.col != lo.col { // the ^ already takes up one space let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; - do num_squigglies.times() { - s.push_char('~') - } + num_squigglies.times(|| s.push_char('~')); } print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl))); } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5ae158045e0e7..2a7f6dfe2d20a 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -370,9 +370,9 @@ impl AstBuilder for @ExtCtxt { } fn strip_bounds(&self, generics: &Generics) -> Generics { - let new_params = do generics.ty_params.map |ty_param| { + let new_params = generics.ty_params.map(|ty_param| { ast::TyParam { bounds: opt_vec::Empty, ..*ty_param } - }; + }); Generics { ty_params: new_params, .. (*generics).clone() @@ -883,9 +883,9 @@ impl AstBuilder for @ExtCtxt { fn view_use_list(&self, sp: Span, vis: ast::visibility, path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item { - let imports = do imports.map |id| { + let imports = imports.map(|id| { respan(sp, ast::path_list_ident_ { name: *id, id: ast::DUMMY_NODE_ID }) - }; + }); self.view_use(sp, vis, ~[@respan(sp, diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 118ada116d9eb..6dd358144a474 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -103,7 +103,7 @@ fn cs_clone( }, _ => { // struct-like - let fields = do all_fields.map |field| { + let fields = all_fields.map(|field| { let ident = match field.name { Some(i) => i, None => cx.span_bug(span, @@ -111,7 +111,7 @@ fn cs_clone( name)) }; cx.field_imm(span, ident, subcall(field.self_)) - }; + }); if fields.is_empty() { // no fields, so construct like `None` diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 2f9222ccb56f6..4ab0cc3bc67f5 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -70,13 +70,16 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span, }; let read_struct_field = cx.ident_of("read_struct_field"); - let result = do decode_static_fields(cx, span, substr.type_ident, - summary) |span, name, field| { + let result = decode_static_fields(cx, + span, + substr.type_ident, + summary, + |span, name, field| { cx.expr_method_call(span, blkdecoder, read_struct_field, ~[cx.expr_str(span, name), cx.expr_uint(span, field), lambdadecode]) - }; + }); cx.expr_method_call(span, decoder, cx.ident_of("read_struct"), ~[cx.expr_str(span, cx.str_of(substr.type_ident)), cx.expr_uint(span, nfields), @@ -93,12 +96,15 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span, let (name, parts) = match *f { (i, ref p) => (i, p) }; variants.push(cx.expr_str(span, cx.str_of(name))); - let decoded = do decode_static_fields(cx, span, name, - parts) |span, _, field| { + let decoded = decode_static_fields(cx, + span, + name, + parts, + |span, _, field| { cx.expr_method_call(span, blkdecoder, rvariant_arg, ~[cx.expr_uint(span, field), lambdadecode]) - }; + }); arms.push(cx.arm(span, ~[cx.pat_lit(span, cx.expr_uint(span, i))], @@ -135,18 +141,18 @@ fn decode_static_fields(cx: @ExtCtxt, if fields.is_empty() { cx.expr_ident(outer_span, outer_pat_ident) } else { - let fields = do fields.iter().enumerate().map |(i, &span)| { + let fields = fields.iter().enumerate().map(|(i, &span)| { getarg(span, format!("_field{}", i).to_managed(), i) - }.collect(); + }).collect(); cx.expr_call_ident(outer_span, outer_pat_ident, fields) } } Named(ref fields) => { // use the field's span to get nicer error messages. - let fields = do fields.iter().enumerate().map |(i, &(name, span))| { + let fields = fields.iter().enumerate().map(|(i, &(name, span))| { cx.field_imm(span, name, getarg(span, cx.str_of(name), i)) - }.collect(); + }).collect(); cx.expr_struct_ident(outer_span, outer_pat_ident, fields) } } diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index 866df36bba4ad..015083f11d35b 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -60,9 +60,9 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp } } Named(ref fields) => { - let default_fields = do fields.map |&(ident, span)| { + let default_fields = fields.map(|&(ident, span)| { cx.field_imm(span, ident, default_call(span)) - }; + }); cx.expr_struct_ident(span, substr.type_ident, default_fields) } } diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 899100f14ba77..96b77c4c16246 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -24,19 +24,19 @@ would generate two implementations like: impl Encodable for Node { fn encode(&self, s: &S) { - do s.emit_struct("Node", 1) { + s.emit_struct("Node", 1, || { s.emit_field("id", 0, || s.emit_uint(self.id)) - } + }) } } impl Decodable for node_id { fn decode(d: &D) -> Node { - do d.read_struct("Node", 1) { + d.read_struct("Node", 1, || { Node { id: d.read_field(~"x", 0, || decode(d)) } - } + }) } } @@ -53,10 +53,10 @@ would yield functions like: T: Encodable > spanned: Encodable { fn encode(s: &S) { - do s.emit_rec { + s.emit_rec(|| { s.emit_field("node", 0, || self.node.encode(s)); s.emit_field("span", 1, || self.span.encode(s)); - } + }) } } @@ -65,12 +65,12 @@ would yield functions like: T: Decodable > spanned: Decodable { fn decode(d: &D) -> spanned { - do d.read_rec { + d.read_rec(|| { { node: d.read_field(~"node", 0, || decode(d)), span: d.read_field(~"span", 1, || decode(d)), } - } + }) } } */ diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 2f6cfeb24da1f..614c719e0a2be 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -362,9 +362,9 @@ impl<'self> TraitDef<'self> { // a TyParamBound requires an ast id let mut bounds = opt_vec::from( // extra restrictions on the generics parameters to the type being derived upon - do self.additional_bounds.map |p| { + self.additional_bounds.map(|p| { cx.typarambound(p.to_path(cx, trait_span, type_ident, generics)) - }); + })); // require the current trait bounds.push(cx.typarambound(trait_path.clone())); @@ -375,9 +375,9 @@ impl<'self> TraitDef<'self> { let trait_ref = cx.trait_ref(trait_path); // Create the type parameters on the `self` path. - let self_ty_params = do generics.ty_params.map |ty_param| { + let self_ty_params = generics.ty_params.map(|ty_param| { cx.ty_ident(trait_span, ty_param.ident) - }; + }); let self_lifetimes = generics.lifetimes.clone(); @@ -405,7 +405,7 @@ impl<'self> TraitDef<'self> { struct_def: &struct_def, type_ident: Ident, generics: &Generics) -> @ast::item { - let methods = do self.methods.map |method_def| { + let methods = self.methods.map(|method_def| { let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, trait_span, type_ident, generics); @@ -426,7 +426,7 @@ impl<'self> TraitDef<'self> { type_ident, generics, explicit_self, tys, body) - }; + }); self.create_derived_impl(cx, trait_span, type_ident, generics, methods) } @@ -436,7 +436,7 @@ impl<'self> TraitDef<'self> { enum_def: &enum_def, type_ident: Ident, generics: &Generics) -> @ast::item { - let methods = do self.methods.map |method_def| { + let methods = self.methods.map(|method_def| { let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, trait_span, type_ident, generics); @@ -457,7 +457,7 @@ impl<'self> TraitDef<'self> { type_ident, generics, explicit_self, tys, body) - }; + }); self.create_derived_impl(cx, trait_span, type_ident, generics, methods) } @@ -547,9 +547,9 @@ impl<'self> MethodDef<'self> { // create the generics that aren't for Self let fn_generics = self.generics.to_generics(cx, trait_span, type_ident, generics); - let args = do arg_types.move_iter().map |(name, ty)| { + let args = arg_types.move_iter().map(|(name, ty)| { cx.arg(trait_span, name, ty) - }.collect(); + }).collect(); let ret_type = self.get_ret_ty(cx, trait_span, generics, type_ident); @@ -624,19 +624,19 @@ impl<'self> MethodDef<'self> { // transpose raw_fields let fields = match raw_fields { [ref self_arg, .. rest] => { - do self_arg.iter().enumerate().map |(i, &(span, opt_id, field))| { - let other_fields = do rest.map |l| { + self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| { + let other_fields = rest.map(|l| { match &l[i] { &(_, _, ex) => ex } - }; + }); FieldInfo { span: span, name: opt_id, self_: field, other: other_fields } - }.collect() + }).collect() } [] => { cx.span_bug(trait_span, "No self arguments to non-static \ method in generic `deriving`") } @@ -787,16 +787,16 @@ impl<'self> MethodDef<'self> { } } let field_tuples = - do self_vec.iter() - .zip(enum_matching_fields.iter()) - .map |(&(span, id, self_f), other)| { + self_vec.iter() + .zip(enum_matching_fields.iter()) + .map(|(&(span, id, self_f), other)| { FieldInfo { span: span, name: id, self_: self_f, other: (*other).clone() } - }.collect(); + }).collect(); substructure = EnumMatching(variant_index, variant, field_tuples); } None => { @@ -901,7 +901,7 @@ impl<'self> MethodDef<'self> { self_args: &[@Expr], nonself_args: &[@Expr]) -> @Expr { - let summary = do enum_def.variants.map |v| { + let summary = enum_def.variants.map(|v| { let ident = v.node.name; let summary = match v.node.kind { ast::tuple_variant_kind(ref args) => Unnamed(args.map(|va| va.ty.span)), @@ -910,7 +910,7 @@ impl<'self> MethodDef<'self> { } }; (ident, summary) - }; + }); self.call_substructure_method(cx, trait_span, type_ident, self_args, nonself_args, @@ -944,10 +944,10 @@ pub fn create_subpatterns(cx: @ExtCtxt, field_paths: ~[ast::Path], mutbl: ast::Mutability) -> ~[@ast::Pat] { - do field_paths.map |path| { + field_paths.map(|path| { cx.pat(path.span, ast::PatIdent(ast::BindByRef(mutbl), (*path).clone(), None)) - } + }) } #[deriving(Eq)] // dogfooding! @@ -1003,10 +1003,10 @@ fn create_struct_pattern(cx: @ExtCtxt, // struct_type is definitely not Unknown, since struct_def.fields // must be nonempty to reach here let pattern = if struct_type == Record { - let field_pats = do subpats.iter().zip(ident_expr.iter()).map |(&pat, &(_, id, _))| { + let field_pats = subpats.iter().zip(ident_expr.iter()).map(|(&pat, &(_, id, _))| { // id is guaranteed to be Some ast::FieldPat { ident: id.unwrap(), pat: pat } - }.collect(); + }).collect(); cx.pat_struct(trait_span, matching_path, field_pats) } else { cx.pat_enum(trait_span, matching_path, subpats) @@ -1075,13 +1075,13 @@ pub fn cs_fold(use_foldl: bool, match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { if use_foldl { - do all_fields.iter().fold(base) |old, field| { + all_fields.iter().fold(base, |old, field| { f(cx, field.span, old, field.self_, field.other) - } + }) } else { - do all_fields.rev_iter().fold(base) |old, field| { + all_fields.rev_iter().fold(base, |old, field| { f(cx, field.span, old, field.self_, field.other) - } + }) } }, EnumNonMatching(ref all_enums) => enum_nonmatch_f(cx, trait_span, @@ -1113,12 +1113,12 @@ pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr, match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) - let called = do all_fields.map |field| { + let called = all_fields.map(|field| { cx.expr_method_call(field.span, field.self_, substructure.method_ident, field.other.clone()) - }; + }); f(cx, trait_span, called) }, @@ -1148,13 +1148,13 @@ pub fn cs_same_method_fold(use_foldl: bool, cs_same_method( |cx, span, vals| { if use_foldl { - do vals.iter().fold(base) |old, &new| { + vals.iter().fold(base, |old, &new| { f(cx, span, old, new) - } + }) } else { - do vals.rev_iter().fold(base) |old, &new| { + vals.rev_iter().fold(base, |old, &new| { f(cx, span, old, new) - } + }) } }, enum_nonmatch_f, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index fed630cc6681b..7e3debd7967f6 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -90,7 +90,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @ cx.span_bug(span, "#[deriving(IterBytes)] needs at least one field"); } - do exprs.slice(1, exprs.len()).iter().fold(exprs[0]) |prev, me| { + exprs.slice(1, exprs.len()).iter().fold(exprs[0], |prev, me| { cx.expr_binary(span, BiAnd, prev, *me) - } + }) } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 8729382141b8a..9c611d7e7b284 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -74,7 +74,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt, in_items } MetaList(_, ref titems) => { - do titems.rev_iter().fold(in_items) |in_items, &titem| { + titems.rev_iter().fold(in_items, |in_items, &titem| { match titem.node { MetaNameValue(tname, _) | MetaList(tname, _) | @@ -112,7 +112,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt, } } } - } + }) } } } diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 1877a6eb85bef..40fdee481edd9 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -104,7 +104,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { value_ref, variant_count); - let mut arms = do variants.iter().enumerate().map |(i, id_sum)| { + let mut arms = variants.iter().enumerate().map(|(i, id_sum)| { let i_expr = cx.expr_uint(span, i); let pat = cx.pat_lit(span, i_expr); @@ -115,7 +115,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { rand_thing(cx, span, ident, summary, |sp| rand_call(sp))) } } - }.collect::<~[ast::Arm]>(); + }).collect::<~[ast::Arm]>(); // _ => {} at the end. Should never occur arms.push(cx.arm_unreachable(span)); @@ -144,9 +144,9 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { } } Named(ref fields) => { - let rand_fields = do fields.map |&(ident, span)| { + let rand_fields = fields.map(|&(ident, span)| { cx.field_imm(span, ident, rand_call(span)) - }; + }); cx.expr_struct_ident(span, ctor_ident, rand_fields) } } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index d1a5af5f7e891..eb957e80835ff 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -171,9 +171,9 @@ impl<'self> Ty<'self> { -> ast::Path { match *self { Self => { - let self_params = do self_generics.ty_params.map |ty_param| { + let self_params = self_generics.ty_params.map(|ty_param| { cx.ty_ident(span, ty_param.ident) - }; + }); let lifetimes = self_generics.lifetimes.clone(); cx.path_all(span, false, ~[self_ty], lifetimes, @@ -192,10 +192,10 @@ impl<'self> Ty<'self> { fn mk_ty_param(cx: @ExtCtxt, span: Span, name: &str, bounds: &[Path], self_ident: Ident, self_generics: &Generics) -> ast::TyParam { let bounds = opt_vec::from( - do bounds.map |b| { + bounds.map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); cx.typarambound(path) - }); + })); cx.typaram(cx.ident_of(name), bounds) } @@ -224,16 +224,16 @@ impl<'self> LifetimeBounds<'self> { self_ty: Ident, self_generics: &Generics) -> Generics { - let lifetimes = do self.lifetimes.map |lt| { + let lifetimes = self.lifetimes.map(|lt| { cx.lifetime(span, cx.ident_of(*lt)) - }; - let ty_params = do self.bounds.map |t| { + }); + let ty_params = self.bounds.map(|t| { match t { &(ref name, ref bounds) => { mk_ty_param(cx, span, *name, *bounds, self_ty, self_generics) } } - }; + }); mk_generics(lifetimes, ty_params) } } diff --git a/src/libsyntax/ext/deriving/zero.rs b/src/libsyntax/ext/deriving/zero.rs index 939c7b5584432..a37cb586f59d4 100644 --- a/src/libsyntax/ext/deriving/zero.rs +++ b/src/libsyntax/ext/deriving/zero.rs @@ -76,9 +76,9 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr { } } Named(ref fields) => { - let zero_fields = do fields.map |&(ident, span)| { + let zero_fields = fields.map(|&(ident, span)| { cx.field_imm(span, ident, zero_call(span)) - }; + }); cx.expr_struct_ident(span, substr.type_ident, zero_fields) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9b6f2a275eebb..f23e13b89311c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -261,8 +261,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv, // For each item, look through the attributes. If any of them are // decorated with "item decorators", then use that function to transform // the item into a new set of items. - let new_items = do vec::flat_map(module_.items) |item| { - do item.attrs.rev_iter().fold(~[*item]) |items, attr| { + let new_items = vec::flat_map(module_.items, |item| { + item.attrs.rev_iter().fold(~[*item], |items, attr| { let mname = attr.name(); match (*extsbox).find(&intern(mname)) { @@ -280,8 +280,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv, }, _ => items, } - } - }; + }) + }); ast::_mod { items: new_items, diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 00919fce5db6c..1c0930f984a71 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -742,12 +742,12 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span, "format argument must be a string literal."); let mut err = false; - do parse::parse_error::cond.trap(|m| { + parse::parse_error::cond.trap(|m| { if !err { err = true; ecx.span_err(efmt.span, m); } - }).inside { + }).inside(|| { for piece in parse::Parser::new(fmt) { if !err { cx.verify_piece(&piece); @@ -755,7 +755,7 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span, cx.pieces.push(piece); } } - } + }); if err { return MRExpr(efmt) } // Make sure that all arguments were used and all arguments have types. diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 50688afc56a5f..3e877d29300da 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -127,12 +127,12 @@ pub fn copy_up(mpu: &matcher_pos_up) -> ~MatcherPos { } pub fn count_names(ms: &[matcher]) -> uint { - do ms.iter().fold(0) |ct, m| { + ms.iter().fold(0, |ct, m| { ct + match m.node { match_tok(_) => 0u, match_seq(ref more_ms, _, _, _, _) => count_names((*more_ms)), match_nonterminal(_,_,_) => 1u - }} + }}) } pub fn initial_matcher_pos(ms: ~[matcher], sep: Option, lo: BytePos) @@ -416,9 +416,9 @@ pub fn parse( } cur_eis.push(ei); - do rust_parser.tokens_consumed.times() || { - rdr.next_token(); - } + rust_parser.tokens_consumed.times(|| { + let _ = rdr.next_token(); + }); } } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index f8d48d00db918..0f7b92b5b0640 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -151,10 +151,10 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis { } match *t { tt_delim(ref tts) | tt_seq(_, ref tts, _, _) => { - do tts.iter().fold(lis_unconstrained) |lis, tt| { + tts.iter().fold(lis_unconstrained, |lis, tt| { let lis2 = lockstep_iter_size(tt, r); lis_merge(lis, lis2) - } + }) } tt_tok(*) => lis_unconstrained, tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index e81973835fe55..b268988c3c567 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -187,12 +187,12 @@ pub trait ast_fold { } PatStruct(ref pth, ref fields, etc) => { let pth_ = self.fold_path(pth); - let fs = do fields.map |f| { + let fs = fields.map(|f| { ast::FieldPat { ident: f.ident, pat: self.fold_pat(f.pat) } - }; + }); PatStruct(pth_, fs, etc) } PatTup(ref elts) => PatTup(elts.map(|x| self.fold_pat(*x))), @@ -455,7 +455,7 @@ fn fold_arg_(a: &arg, fld: &T) -> arg { // build a new vector of tts by appling the ast_fold's fold_ident to // all of the identifiers in the token trees. pub fn fold_tts(tts: &[token_tree], fld: &T) -> ~[token_tree] { - do tts.map |tt| { + tts.map(|tt| { match *tt { tt_tok(span, ref tok) => tt_tok(span,maybe_fold_ident(tok,fld)), @@ -468,7 +468,7 @@ pub fn fold_tts(tts: &[token_tree], fld: &T) -> ~[token_tree] { tt_nonterminal(sp,ref ident) => tt_nonterminal(sp,fld.fold_ident(*ident)) } - } + }) } // apply ident folder if it's an ident, otherwise leave it alone @@ -601,11 +601,11 @@ fn fold_field(f: TypeField, folder: &T) -> TypeField { fn fold_opt_bounds(b: &Option>, folder: &T) -> Option> { - do b.as_ref().map |bounds| { - do bounds.map |bound| { + b.as_ref().map(|bounds| { + bounds.map(|bound| { fold_ty_param_bound(bound, folder) - } - } + }) + }) } fn fold_variant_arg_(va: &variant_arg, folder: &T) @@ -660,9 +660,9 @@ pub fn noop_fold_item_underscore(i: &item_, folder: &T) -> item_ { item_enum(ref enum_definition, ref generics) => { item_enum( ast::enum_def { - variants: do enum_definition.variants.map |x| { + variants: enum_definition.variants.map(|x| { folder.fold_variant(x) - }, + }), }, fold_generics(generics, folder)) } @@ -678,12 +678,12 @@ pub fn noop_fold_item_underscore(i: &item_, folder: &T) -> item_ { ) } item_trait(ref generics, ref traits, ref methods) => { - let methods = do methods.map |method| { + let methods = methods.map(|method| { match *method { required(ref m) => required(folder.fold_type_method(m)), provided(method) => provided(folder.fold_method(method)) } - }; + }); item_trait(fold_generics(generics, folder), traits.map(|p| fold_trait_ref(p, folder)), methods) diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 8defd8a7b6cb6..d8f2d8a53807a 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -106,9 +106,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { } if can_trim { - do lines.map |line| { - line.slice(i + 1, line.len()).to_owned() - } + lines.map(|line| line.slice(i + 1, line.len()).to_owned()) } else { lines } @@ -377,10 +375,10 @@ pub fn gather_comments_and_literals(span_diagnostic: //discard, and look ahead; we're working with internal state let TokenAndSpan {tok: tok, sp: sp} = rdr.peek(); if token::is_lit(&tok) { - do with_str_from(rdr, bstart) |s| { + with_str_from(rdr, bstart, |s| { debug!("tok lit: {}", s); literals.push(lit {lit: s.to_owned(), pos: sp.lo}); - } + }) } else { debug!("tok: {}", token::to_str(get_ident_interner(), &tok)); } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 6aa3962a0e7de..e4b93c3b4d5b5 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -337,7 +337,7 @@ fn consume_any_line_comment(rdr: @mut StringReader) while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } - let ret = do with_str_from(rdr, start_bpos) |string| { + let ret = with_str_from(rdr, start_bpos, |string| { // but comments with only more "/"s are not if !is_line_non_doc_comment(string) { Some(TokenAndSpan{ @@ -347,7 +347,7 @@ fn consume_any_line_comment(rdr: @mut StringReader) } else { None } - }; + }); if ret.is_some() { return ret; @@ -412,7 +412,7 @@ fn consume_block_comment(rdr: @mut StringReader) } let res = if is_doc_comment { - do with_str_from(rdr, start_bpos) |string| { + with_str_from(rdr, start_bpos, |string| { // but comments with only "*"s between two "/"s are not if !is_block_non_doc_comment(string) { Some(TokenAndSpan{ @@ -422,7 +422,7 @@ fn consume_block_comment(rdr: @mut StringReader) } else { None } - } + }) } else { None }; @@ -652,7 +652,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { bump(rdr); } - return do with_str_from(rdr, start) |string| { + return with_str_from(rdr, start, |string| { if string == "_" { token::UNDERSCORE } else { @@ -661,7 +661,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { // FIXME: perform NFKC normalization here. (Issue #2253) token::IDENT(str_to_ident(string), is_mod_name) } - } + }) } if is_dec_digit(c) { return scan_number(c, rdr); @@ -775,9 +775,9 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { while ident_continue(rdr.curr) { bump(rdr); } - return do with_str_from(rdr, start) |lifetime_name| { + return with_str_from(rdr, start, |lifetime_name| { token::LIFETIME(str_to_ident(lifetime_name)) - } + }) } // Otherwise it is a character constant: diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5db26dd99dda6..b9a7ec33ee4ff 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1031,11 +1031,11 @@ impl Parser { // parse the methods in a trait declaration pub fn parse_trait_methods(&self) -> ~[trait_method] { - do self.parse_unspanned_seq( + self.parse_unspanned_seq( &token::LBRACE, &token::RBRACE, - seq_sep_none() - ) |p| { + seq_sep_none(), + |p| { let attrs = p.parse_outer_attributes(); let lo = p.span.lo; @@ -1048,11 +1048,11 @@ impl Parser { let generics = p.parse_generics(); - let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, d) = self.parse_fn_decl_with_self(|p| { // This is somewhat dubious; We don't want to allow argument // names to be left off if there is a definition... p.parse_arg_general(false) - }; + }); let hi = p.last_span.hi; debug!("parse_trait_methods(): trait method signature ends in \ @@ -1108,7 +1108,7 @@ impl Parser { ); } } - } + }) } // parse a possibly mutable type @@ -3000,13 +3000,13 @@ impl Parser { let mutbl = self.parse_mutability(); pat = self.parse_pat_ident(BindByRef(mutbl)); } else { - let can_be_enum_or_struct = do self.look_ahead(1) |t| { + let can_be_enum_or_struct = self.look_ahead(1, |t| { match *t { token::LPAREN | token::LBRACKET | token::LT | token::LBRACE | token::MOD_SEP => true, _ => false, } - }; + }); if self.look_ahead(1, |t| *t == token::DOTDOT) { let start = self.parse_expr_res(RESTRICT_NO_BAR_OP); @@ -3040,18 +3040,18 @@ impl Parser { let mut args: ~[@Pat] = ~[]; match *self.token { token::LPAREN => { - let is_star = do self.look_ahead(1) |t| { + let is_star = self.look_ahead(1, |t| { match *t { token::BINOP(token::STAR) => true, _ => false, } - }; - let is_dotdot = do self.look_ahead(1) |t| { + }); + let is_dotdot = self.look_ahead(1, |t| { match *t { token::DOTDOT => true, _ => false, } - }; + }); if is_star | is_dotdot { // This is a "top constructor only" pat self.bump(); @@ -3884,9 +3884,9 @@ impl Parser { let pur = self.parse_fn_purity(); let ident = self.parse_ident(); let generics = self.parse_generics(); - let (explicit_self, decl) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, decl) = self.parse_fn_decl_with_self(|p| { p.parse_arg() - }; + }); let (inner_attrs, body) = self.parse_inner_attrs_and_block(); let hi = body.span.hi; @@ -4027,11 +4027,11 @@ impl Parser { } else if *self.token == token::LPAREN { // It's a tuple-like struct. is_tuple_like = true; - fields = do self.parse_unspanned_seq( + fields = self.parse_unspanned_seq( &token::LPAREN, &token::RPAREN, - seq_sep_trailing_allowed(token::COMMA) - ) |p| { + seq_sep_trailing_allowed(token::COMMA), + |p| { let attrs = self.parse_outer_attributes(); let lo = p.span.lo; let struct_field_ = ast::struct_field_ { @@ -4041,7 +4041,7 @@ impl Parser { attrs: attrs, }; @spanned(lo, p.span.hi, struct_field_) - }; + }); self.expect(&token::SEMI); } else if self.eat(&token::SEMI) { // It's a unit-like struct. @@ -4259,20 +4259,16 @@ impl Parser { path: Path, outer_attrs: ~[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == path }; + let maybe_i = self.sess.included_mod_stack.iter().position(|p| *p == path); match maybe_i { Some(i) => { let stack = &self.sess.included_mod_stack; let mut err = ~"circular modules: "; for p in stack.slice(i, stack.len()).iter() { - do p.display().with_str |s| { - err.push_str(s); - } + p.display().with_str(|s| err.push_str(s)); err.push_str(" -> "); } - do path.display().with_str |s| { - err.push_str(s); - } + path.display().with_str(|s| err.push_str(s)); self.span_fatal(id_sp, err); } None => () diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 63f4f97889c6d..870c1bd74b1b0 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -169,9 +169,9 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { /* Literals */ LIT_CHAR(c) => { let mut res = ~"'"; - do char::from_u32(c).unwrap().escape_default |c| { + char::from_u32(c).unwrap().escape_default(|c| { res.push_char(c); - } + }); res.push_char('\''); res } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c41460485da67..a8f82221fa199 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -704,7 +704,7 @@ pub fn print_struct(s: @ps, if ast_util::struct_def_is_tuple_like(struct_def) { if !struct_def.fields.is_empty() { popen(s); - do commasep(s, inconsistent, struct_def.fields) |s, field| { + commasep(s, inconsistent, struct_def.fields, |s, field| { match field.node.kind { ast::named_field(*) => fail!("unexpected named field"), ast::unnamed_field => { @@ -712,7 +712,7 @@ pub fn print_struct(s: @ps, print_type(s, &field.node.ty); } } - } + }); pclose(s); } word(s.s, ";"); @@ -1699,9 +1699,7 @@ pub fn print_pat(s: @ps, pat: &ast::Pat) { } ast::PatVec(ref before, slice, ref after) => { word(s.s, "["); - do commasep(s, inconsistent, *before) |s, &p| { - print_pat(s, p); - } + commasep(s, inconsistent, *before, |s, &p| print_pat(s, p)); for &p in slice.iter() { if !before.is_empty() { word_space(s, ","); } match p { @@ -1713,9 +1711,7 @@ pub fn print_pat(s: @ps, pat: &ast::Pat) { print_pat(s, p); if !after.is_empty() { word_space(s, ","); } } - do commasep(s, inconsistent, *after) |s, &p| { - print_pat(s, p); - } + commasep(s, inconsistent, *after, |s, &p| print_pat(s, p)); word(s.s, "]"); } } @@ -1937,9 +1933,9 @@ pub fn print_view_path(s: @ps, vp: &ast::view_path) { ast::view_path_list(ref path, ref idents, _) => { print_path(s, path, false); word(s.s, "::{"); - do commasep(s, inconsistent, (*idents)) |s, w| { + commasep(s, inconsistent, (*idents), |s, w| { print_ident(s, w.node.name); - } + }); word(s.s, "}"); } } @@ -2053,9 +2049,7 @@ pub fn print_ty_fn(s: @ps, match id { Some(id) => { word(s.s, " "); print_ident(s, id); } _ => () } if opt_sigil != Some(ast::BorrowedSigil) { - do opt_bounds.as_ref().map |bounds| { - print_bounds(s, bounds, true); - }; + opt_bounds.as_ref().map(|bounds| print_bounds(s, bounds, true)); } match generics { Some(g) => print_generics(s, g), _ => () } @@ -2157,9 +2151,7 @@ pub fn print_literal(s: @ps, lit: &ast::lit) { ast::lit_str(st, style) => print_string(s, st, style), ast::lit_char(ch) => { let mut res = ~"'"; - do char::from_u32(ch).unwrap().escape_default |c| { - res.push_char(c); - } + char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); res.push_char('\''); word(s.s, res); } From 8ceb374ab783c6417b60867e7f34bebe997936ac Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Nov 2013 15:42:55 -0800 Subject: [PATCH 07/12] librustc: Remove non-procedure uses of `do` from librustc, librustdoc, and librustpkg. --- src/librustc/back/link.rs | 52 ++-- src/librustc/driver/driver.rs | 4 +- src/librustc/front/config.rs | 32 +-- src/librustc/front/test.rs | 12 +- src/librustc/lib.rs | 15 +- src/librustc/lib/llvm.rs | 4 +- src/librustc/metadata/cstore.rs | 4 +- src/librustc/metadata/decoder.rs | 191 ++++++------ src/librustc/metadata/encoder.rs | 12 +- src/librustc/metadata/filesearch.rs | 4 +- src/librustc/metadata/loader.rs | 16 +- src/librustc/metadata/tyencode.rs | 6 +- src/librustc/middle/astencode.rs | 264 +++++++++-------- src/librustc/middle/borrowck/check_loans.rs | 48 ++-- .../middle/borrowck/gather_loans/mod.rs | 14 +- src/librustc/middle/borrowck/mod.rs | 8 +- src/librustc/middle/borrowck/move_data.rs | 28 +- src/librustc/middle/check_match.rs | 20 +- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/dataflow.rs | 12 +- src/librustc/middle/graph.rs | 16 +- src/librustc/middle/kind.rs | 23 +- src/librustc/middle/lang_items.rs | 9 +- src/librustc/middle/lint.rs | 56 ++-- src/librustc/middle/liveness.rs | 86 +++--- src/librustc/middle/moves.rs | 4 +- src/librustc/middle/pat_util.rs | 12 +- src/librustc/middle/resolve.rs | 144 +++++----- src/librustc/middle/trans/_match.rs | 110 +++---- src/librustc/middle/trans/adt.rs | 20 +- src/librustc/middle/trans/asm.rs | 17 +- src/librustc/middle/trans/base.rs | 162 ++++++----- src/librustc/middle/trans/builder.rs | 26 +- src/librustc/middle/trans/callee.rs | 4 +- src/librustc/middle/trans/closure.rs | 8 +- src/librustc/middle/trans/common.rs | 60 ++-- src/librustc/middle/trans/consts.rs | 21 +- src/librustc/middle/trans/context.rs | 12 +- src/librustc/middle/trans/controlflow.rs | 11 +- src/librustc/middle/trans/datum.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 271 ++++++++++-------- src/librustc/middle/trans/expr.rs | 53 ++-- src/librustc/middle/trans/foreign.rs | 4 +- src/librustc/middle/trans/glue.rs | 20 +- src/librustc/middle/trans/meth.rs | 12 +- src/librustc/middle/trans/reflect.rs | 16 +- src/librustc/middle/trans/uniq.rs | 4 +- src/librustc/middle/trans/value.rs | 8 +- src/librustc/middle/ty.rs | 88 +++--- src/librustc/middle/typeck/astconv.rs | 12 +- src/librustc/middle/typeck/check/method.rs | 17 +- src/librustc/middle/typeck/check/mod.rs | 48 ++-- src/librustc/middle/typeck/check/regionck.rs | 8 +- src/librustc/middle/typeck/check/vtable.rs | 16 +- src/librustc/middle/typeck/check/writeback.rs | 4 +- src/librustc/middle/typeck/coherence.rs | 24 +- src/librustc/middle/typeck/collect.rs | 8 +- src/librustc/middle/typeck/infer/coercion.rs | 32 +-- src/librustc/middle/typeck/infer/combine.rs | 86 +++--- src/librustc/middle/typeck/infer/lattice.rs | 12 +- src/librustc/middle/typeck/infer/mod.rs | 73 +++-- .../typeck/infer/region_inference/mod.rs | 12 +- src/librustc/middle/typeck/infer/sub.rs | 4 +- src/librustc/middle/typeck/mod.rs | 4 +- src/librustdoc/clean.rs | 4 +- src/librustdoc/html/format.rs | 20 +- src/librustdoc/html/markdown.rs | 8 +- src/librustdoc/html/render.rs | 72 +++-- src/librustdoc/passes.rs | 16 +- src/librustpkg/installed_packages.rs | 14 +- src/librustpkg/lib.rs | 32 +-- src/librustpkg/package_id.rs | 4 +- src/librustpkg/package_source.rs | 14 +- src/librustpkg/path_util.rs | 23 +- src/librustpkg/sha1.rs | 16 +- src/librustpkg/tests.rs | 22 +- .../testsuite/pass/src/c-dependencies/pkg.rs | 8 +- src/librustpkg/util.rs | 14 +- 78 files changed, 1311 insertions(+), 1347 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 35e8c6fde3c8d..adc3712bf0f97 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -72,13 +72,13 @@ pub fn WriteOutputFile( Output: &Path, FileType: lib::llvm::FileType) { unsafe { - do Output.with_c_str |Output| { + Output.with_c_str(|Output| { let result = llvm::LLVMRustWriteOutputFile( Target, PM, M, Output, FileType); if !result { llvm_err(sess, ~"Could not write output"); } - } + }) } } @@ -130,12 +130,12 @@ pub mod jit { for cratepath in r.iter() { debug!("linking: {}", cratepath.display()); - do cratepath.with_c_str |buf_t| { + cratepath.with_c_str(|buf_t| { if !llvm::LLVMRustLoadCrate(manager, buf_t) { llvm_err(sess, ~"Could not link"); } debug!("linked: {}", cratepath.display()); - } + }) } // We custom-build a JIT execution engine via some rust wrappers @@ -149,9 +149,9 @@ pub mod jit { // Next, we need to get a handle on the _rust_main function by // looking up it's corresponding ValueRef and then requesting that // the execution engine compiles the function. - let fun = do "_rust_main".with_c_str |entry| { + let fun = "_rust_main".with_c_str(|entry| { llvm::LLVMGetNamedFunction(m, entry) - }; + }); if fun.is_null() { llvm::LLVMDisposeExecutionEngine(ee); llvm::LLVMContextDispose(c); @@ -248,9 +248,9 @@ pub mod write { llvm::LLVMInitializeMipsAsmParser(); if sess.opts.save_temps { - do output.with_extension("no-opt.bc").with_c_str |buf| { + output.with_extension("no-opt.bc").with_c_str(|buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf); - } + }) } configure_llvm(sess); @@ -263,9 +263,9 @@ pub mod write { }; let use_softfp = sess.opts.debugging_opts & session::use_softfp != 0; - let tm = do sess.targ_cfg.target_strs.target_triple.with_c_str |T| { - do sess.opts.target_cpu.with_c_str |CPU| { - do sess.opts.target_feature.with_c_str |Features| { + let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|T| { + sess.opts.target_cpu.with_c_str(|CPU| { + sess.opts.target_feature.with_c_str(|Features| { llvm::LLVMRustCreateTargetMachine( T, CPU, Features, lib::llvm::CodeModelDefault, @@ -274,9 +274,9 @@ pub mod write { true, use_softfp ) - } - } - }; + }) + }) + }); // Create the two optimizing pass managers. These mirror what clang // does, and are by populated by LLVM's default PassManagerBuilder. @@ -288,7 +288,7 @@ pub mod write { // If we're verifying or linting, add them to the function pass // manager. let addpass = |pass: &str| { - do pass.with_c_str |s| { llvm::LLVMRustAddPass(fpm, s) } + pass.with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) }; if !sess.no_verify() { assert!(addpass("verify")); } if sess.lint_llvm() { assert!(addpass("lint")); } @@ -300,11 +300,11 @@ pub mod write { } for pass in sess.opts.custom_passes.iter() { - do pass.with_c_str |s| { + pass.with_c_str(|s| { if !llvm::LLVMRustAddPass(mpm, s) { sess.warn(format!("Unknown pass {}, ignoring", *pass)); } - } + }) } // Finally, run the actual optimization passes @@ -316,9 +316,9 @@ pub mod write { llvm::LLVMDisposePassManager(mpm); if sess.opts.save_temps { - do output.with_extension("bc").with_c_str |buf| { + output.with_extension("bc").with_c_str(|buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf); - } + }) } if sess.opts.jit { @@ -337,14 +337,14 @@ pub mod write { match output_type { output_type_none => {} output_type_bitcode => { - do output.with_c_str |buf| { + output.with_c_str(|buf| { llvm::LLVMWriteBitcodeToFile(llmod, buf); - } + }) } output_type_llvm_assembly => { - do output.with_c_str |output| { + output.with_c_str(|output| { llvm::LLVMRustPrintModule(cpm, llmod, output) - } + }) } output_type_assembly => { WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::AssemblyFile); @@ -415,9 +415,9 @@ pub mod write { add(*arg); } - do llvm_args.as_imm_buf |p, len| { + llvm_args.as_imm_buf(|p, len| { llvm::LLVMRustSetLLVMOptions(len as c_int, p); - } + }) } unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef, @@ -736,7 +736,7 @@ pub fn sanitize(s: &str) -> ~str { _ => { let mut tstr = ~""; - do char::escape_unicode(c) |c| { tstr.push_char(c); } + char::escape_unicode(c, |c| tstr.push_char(c)); result.push_char('$'); result.push_str(tstr.slice_from(1)); } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index bdc3e2658a5e1..d8d868d847325 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -123,10 +123,10 @@ pub fn build_configuration(sess: Session) -> // Convert strings provided as --cfg [cfgspec] into a crate_cfg fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter) -> ast::CrateConfig { - do cfgspecs.move_iter().map |s| { + cfgspecs.move_iter().map(|s| { let sess = parse::new_parse_sess(Some(demitter)); parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess) - }.collect::() + }).collect::() } pub enum input { diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index 460f1ff1262ff..1602cbb6a9baf 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -20,9 +20,7 @@ struct Context<'self> { // any items that do not belong in the current configuration pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate { let config = crate.config.clone(); - do strip_items(crate) |attrs| { - in_cfg(config, attrs) - } + strip_items(crate, |attrs| in_cfg(config, attrs)) } impl<'self> fold::ast_fold for Context<'self> { @@ -68,14 +66,12 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::view_item) } fn fold_mod(cx: &Context, m: &ast::_mod) -> ast::_mod { - let filtered_items = do m.items.iter().filter_map |a| { + let filtered_items = m.items.iter().filter_map(|a| { filter_item(cx, *a).and_then(|x| cx.fold_item(x)) - }.collect(); - let filtered_view_items = do m.view_items.iter().filter_map |a| { - do filter_view_item(cx, a).map |x| { - cx.fold_view_item(x) - } - }.collect(); + }).collect(); + let filtered_view_items = m.view_items.iter().filter_map(|a| { + filter_view_item(cx, a).map(|x| cx.fold_view_item(x)) + }).collect(); ast::_mod { view_items: filtered_view_items, items: filtered_items @@ -96,11 +92,9 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod { .iter() .filter_map(|a| filter_foreign_item(cx, *a)) .collect(); - let filtered_view_items = do nm.view_items.iter().filter_map |a| { - do filter_view_item(cx, a).map |x| { - cx.fold_view_item(x) - } - }.collect(); + let filtered_view_items = nm.view_items.iter().filter_map(|a| { + filter_view_item(cx, a).map(|x| cx.fold_view_item(x)) + }).collect(); ast::foreign_mod { abis: nm.abis, view_items: filtered_view_items, @@ -147,12 +141,12 @@ fn filter_stmt(cx: &Context, stmt: @ast::Stmt) -> Option<@ast::Stmt> { } fn fold_block(cx: &Context, b: &ast::Block) -> ast::Block { - let resulting_stmts = do b.stmts.iter().filter_map |a| { + let resulting_stmts = b.stmts.iter().filter_map(|a| { filter_stmt(cx, *a).and_then(|stmt| cx.fold_stmt(stmt)) - }.collect(); - let filtered_view_items = do b.view_items.iter().filter_map |a| { + }).collect(); + let filtered_view_items = b.view_items.iter().filter_map(|a| { filter_view_item(cx, a).map(|x| cx.fold_view_item(x)) - }.collect(); + }).collect(); ast::Block { view_items: filtered_view_items, stmts: resulting_stmts, diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index b6ae41833777a..4d1998c8fd722 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -118,13 +118,13 @@ impl fold::ast_fold for TestHarnessGenerator { fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item { if !*cx.sess.building_library { @ast::item { - attrs: do item.attrs.iter().filter_map |attr| { + attrs: item.attrs.iter().filter_map(|attr| { if "main" != attr.name() { Some(*attr) } else { None } - }.collect(), + }).collect(), .. (*item).clone() } } else { @@ -172,10 +172,10 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate) fn strip_test_functions(crate: ast::Crate) -> ast::Crate { // When not compiling with --test we should not compile the // #[test] functions - do config::strip_items(crate) |attrs| { + config::strip_items(crate, |attrs| { !attr::contains_name(attrs, "test") && !attr::contains_name(attrs, "bench") - } + }) } fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool { @@ -232,13 +232,13 @@ fn is_bench_fn(i: @ast::item) -> bool { } fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool { - do i.attrs.iter().any |attr| { + i.attrs.iter().any(|attr| { // check ignore(cfg(foo, bar)) "ignore" == attr.name() && match attr.meta_item_list() { Some(ref cfgs) => attr::test_cfg(cx.config, cfgs.iter().map(|x| *x)), None => true } - } + }) } fn should_fail(i: @ast::item) -> bool { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index f6c3d5fa4ad7f..b82bc38fbd964 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -261,9 +261,9 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { let odir = matches.opt_str("out-dir").map(|o| Path::new(o)); let ofile = matches.opt_str("o").map(|o| Path::new(o)); let cfg = build_configuration(sess); - let pretty = do matches.opt_default("pretty", "normal").map |a| { + let pretty = matches.opt_default("pretty", "normal").map(|a| { parse_pretty(sess, a) - }; + }); match pretty { Some::(ppm) => { pretty_print_input(sess, cfg, &input, ppm); @@ -345,7 +345,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) { task_builder.opts.stack_size = Some(STACK_SIZE); } - match do task_builder.try { + match task_builder.try(|| { let ch = ch_capture.clone(); // The 'diagnostics emitter'. Every error, warning, etc. should // go through this function. @@ -368,7 +368,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) { // Due reasons explain in #7732, if there was a jit execution context it // must be consumed and passed along to our parent task. back::link::jit::consume_engine() - } { + }) { result::Ok(_) => { /* fallthrough */ } result::Err(_) => { // Task failed without emitting a fatal diagnostic @@ -403,9 +403,6 @@ pub fn main() { pub fn main_args(args: &[~str]) -> int { let owned_args = args.to_owned(); - do monitor |demitter| { - run_compiler(owned_args, demitter); - } - - return 0; + monitor(|demitter| run_compiler(owned_args, demitter)); + 0 } diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 160bc5111688a..5de9a3894215c 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1844,9 +1844,9 @@ pub struct TargetData { } pub fn mk_target_data(string_rep: &str) -> TargetData { - let lltd = do string_rep.with_c_str |buf| { + let lltd = string_rep.with_c_str(|buf| { unsafe { llvm::LLVMCreateTargetData(buf) } - }; + }); TargetData { lltd: lltd, diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 0f6fcf819b00a..bc15312d98e18 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -159,9 +159,9 @@ pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] { }); } - let sorted = do extra::sort::merge_sort(result) |a, b| { + let sorted = extra::sort::merge_sort(result, |a, b| { (a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash) - }; + }); debug!("sorted:"); for x in sorted.iter() { diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index dd70d29ec5b2d..cd4afdff91ef5 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -62,7 +62,7 @@ fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) -> let belt = tag_index_buckets_bucket_elt; let mut ret = None; - do reader::tagged_docs(tagged_doc.doc, belt) |elt| { + reader::tagged_docs(tagged_doc.doc, belt, |elt| { let pos = u64_from_be_bytes(*elt.data, elt.start, 4) as uint; if eq_fn(elt.data.slice(elt.start + 4, elt.end)) { ret = Some(reader::doc_at(d.data, pos).doc); @@ -70,7 +70,7 @@ fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) -> } else { true } - }; + }); ret } @@ -168,10 +168,10 @@ fn item_visibility(item: ebml::Doc) -> ast::visibility { fn item_method_sort(item: ebml::Doc) -> char { let mut ret = 'r'; - do reader::tagged_docs(item, tag_item_trait_method_sort) |doc| { + reader::tagged_docs(item, tag_item_trait_method_sort, |doc| { ret = doc.as_str_slice()[0] as char; false - }; + }); ret } @@ -181,10 +181,10 @@ fn item_symbol(item: ebml::Doc) -> ~str { fn item_parent_item(d: ebml::Doc) -> Option { let mut ret = None; - do reader::tagged_docs(d, tag_items_data_parent_item) |did| { + reader::tagged_docs(d, tag_items_data_parent_item, |did| { ret = Some(reader::with_doc_data(did, parse_def_id)); false - }; + }); ret } @@ -200,9 +200,9 @@ fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId { } fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option { - do reader::maybe_get_doc(d, tag_item_method_provided_source).map |doc| { + reader::maybe_get_doc(d, tag_item_method_provided_source).map(|doc| { translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id)) - } + }) } fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool { @@ -210,9 +210,9 @@ fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool { } fn variant_disr_val(d: ebml::Doc) -> Option { - do reader::maybe_get_doc(d, tag_disr_val).and_then |val_doc| { - do reader::with_doc_data(val_doc) |data| { u64::parse_bytes(data, 10u) } - } + reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| { + reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u)) + }) } fn doc_type(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::t { @@ -231,10 +231,10 @@ fn doc_transformed_self_ty(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> Option { - do reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map |tp| { + reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map(|tp| { parse_ty_data(*tp.data, cdata.cnum, tp.start, tcx, |_, did| translate_def_id(cdata, did)) - } + }) } pub fn item_type(_item_id: ast::DefId, item: ebml::Doc, @@ -258,13 +258,13 @@ fn item_ty_param_defs(item: ebml::Doc, tag: uint) -> @~[ty::TypeParameterDef] { let mut bounds = ~[]; - do reader::tagged_docs(item, tag) |p| { + reader::tagged_docs(item, tag, |p| { let bd = parse_type_param_def_data( *p.data, p.start, cdata.cnum, tcx, |_, did| translate_def_id(cdata, did)); bounds.push(bd); true - }; + }); @bounds } @@ -272,8 +272,8 @@ fn item_region_param_defs(item_doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> @[ty::RegionParameterDef] { - do at_vec::build(None) |push| { - do reader::tagged_docs(item_doc, tag_region_param_def) |rp_doc| { + at_vec::build(None, |push| { + reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| { let ident_str_doc = reader::get_doc(rp_doc, tag_region_param_def_ident); let ident = item_name(tcx.sess.intr(), ident_str_doc); @@ -284,8 +284,8 @@ fn item_region_param_defs(item_doc: ebml::Doc, push(ty::RegionParameterDef { ident: ident, def_id: def_id }); true - }; - } + }); + }) } fn item_ty_param_count(item: ebml::Doc) -> uint { @@ -298,11 +298,11 @@ fn item_ty_param_count(item: ebml::Doc) -> uint { fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] { let mut ids: ~[ast::DefId] = ~[]; let v = tag_items_data_item_variant; - do reader::tagged_docs(item, v) |p| { + reader::tagged_docs(item, v, |p| { let ext = reader::with_doc_data(p, parse_def_id); ids.push(ast::DefId { crate: cdata.cnum, node: ext.node }); true - }; + }); return ids; } @@ -313,7 +313,7 @@ pub fn item_path(item_doc: ebml::Doc) -> ast_map::path { let len = reader::doc_as_u32(len_doc) as uint; let mut result = vec::with_capacity(len); - do reader::docs(path_doc) |tag, elt_doc| { + reader::docs(path_doc, |tag, elt_doc| { if tag == tag_path_elt_mod { let str = elt_doc.as_str_slice(); result.push(ast_map::path_mod(token::str_to_ident(str))); @@ -333,7 +333,7 @@ pub fn item_path(item_doc: ebml::Doc) -> ast_map::path { // ignore tag_path_len element } true - }; + }); return result; } @@ -412,14 +412,14 @@ pub fn get_trait_def(cdata: Cmd, let mut bounds = ty::EmptyBuiltinBounds(); // Collect the builtin bounds from the encoded supertraits. // FIXME(#8559): They should be encoded directly. - do reader::tagged_docs(item_doc, tag_item_super_trait_ref) |trait_doc| { + reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| { // NB. Bypasses real supertraits. See get_supertraits() if you wanted them. let trait_ref = doc_trait_ref(trait_doc, tcx, cdata); - do tcx.lang_items.to_builtin_kind(trait_ref.def_id).map |bound| { + tcx.lang_items.to_builtin_kind(trait_ref.def_id).map(|bound| { bounds.add(bound); - }; + }); true - }; + }); ty::TraitDef { generics: ty::Generics {type_param_defs: tp_defs, region_param_defs: rp_defs}, @@ -455,9 +455,9 @@ pub fn get_impl_trait(cdata: Cmd, tcx: ty::ctxt) -> Option<@ty::TraitRef> { let item_doc = lookup_item(id, cdata.data); - do reader::maybe_get_doc(item_doc, tag_item_trait_ref).map |tp| { + reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| { @doc_trait_ref(tp, tcx, cdata) - } + }) } pub fn get_impl_vtables(cdata: Cmd, @@ -479,13 +479,13 @@ pub fn get_impl_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId, name: ast::Ident) -> Option { let items = reader::get_doc(reader::Doc(cdata.data), tag_items); let mut found = None; - do reader::tagged_docs(find_item(id, items), tag_item_impl_method) |mid| { + reader::tagged_docs(find_item(id, items), tag_item_impl_method, |mid| { let m_did = reader::with_doc_data(mid, parse_def_id); if item_name(intr, find_item(m_did.node, items)) == name { found = Some(translate_def_id(cdata, m_did)); } true - }; + }); found } @@ -512,7 +512,7 @@ pub fn def_like_to_def(def_like: DefLike) -> ast::Def { pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { let root = reader::Doc(cdata.data); let lang_items = reader::get_doc(root, tag_lang_items); - do reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| { + reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| { let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id); let id = reader::doc_as_u32(id_doc) as uint; let node_id_doc = reader::get_doc(item_doc, @@ -520,7 +520,7 @@ pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { let node_id = reader::doc_as_u32(node_id_doc) as ast::NodeId; f(node_id, id) - } + }) } struct EachItemContext<'self> { @@ -624,7 +624,7 @@ impl<'self> EachItemContext<'self> { let mut continue_ = true; // Iterate over all children. - do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| { + reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| { let child_def_id = reader::with_doc_data(child_info_doc, parse_def_id); let child_def_id = translate_def_id(self.cdata, child_def_id); @@ -670,14 +670,14 @@ impl<'self> EachItemContext<'self> { } } continue_ - }; + }); if !continue_ { return false } // Iterate over reexports. - do each_reexport(item_doc) |reexport_doc| { + each_reexport(item_doc, |reexport_doc| { let def_id_doc = reader::get_doc( reexport_doc, tag_items_data_item_reexport_def_id); @@ -723,7 +723,7 @@ impl<'self> EachItemContext<'self> { } continue_ - }; + }); continue_ } @@ -737,7 +737,7 @@ fn each_child_of_item_or_crate(intr: @ident_interner, ast::Ident, ast::visibility|) { // Iterate over all children. - let _ = do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| { + let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| { let child_def_id = reader::with_doc_data(child_info_doc, parse_def_id); let child_def_id = translate_def_id(cdata, child_def_id); @@ -767,23 +767,23 @@ fn each_child_of_item_or_crate(intr: @ident_interner, } true - }; + }); // As a special case, iterate over all static methods of // associated implementations too. This is a bit of a botch. // --pcwalton - let _ = do reader::tagged_docs(item_doc, - tag_items_data_item_inherent_impl) - |inherent_impl_def_id_doc| { + let _ = reader::tagged_docs(item_doc, + tag_items_data_item_inherent_impl, + |inherent_impl_def_id_doc| { let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc, cdata); let items = reader::get_doc(reader::Doc(cdata.data), tag_items); match maybe_find_item(inherent_impl_def_id.node, items) { None => {} Some(inherent_impl_doc) => { - let _ = do reader::tagged_docs(inherent_impl_doc, - tag_item_impl_method) - |impl_method_def_id_doc| { + let _ = reader::tagged_docs(inherent_impl_doc, + tag_item_impl_method, + |impl_method_def_id_doc| { let impl_method_def_id = reader::with_doc_data(impl_method_def_id_doc, parse_def_id); @@ -812,15 +812,15 @@ fn each_child_of_item_or_crate(intr: @ident_interner, } true - }; + }); } } true - }; + }); // Iterate over all reexports. - let _ = do each_reexport(item_doc) |reexport_doc| { + let _ = each_reexport(item_doc, |reexport_doc| { let def_id_doc = reader::get_doc(reexport_doc, tag_items_data_item_reexport_def_id); let child_def_id = reader::with_doc_data(def_id_doc, @@ -854,7 +854,7 @@ fn each_child_of_item_or_crate(intr: @ident_interner, } true - }; + }); } /// Iterates over each child of the given item. @@ -1002,11 +1002,11 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ { fn item_impl_methods(intr: @ident_interner, cdata: Cmd, item: ebml::Doc, tcx: ty::ctxt) -> ~[@ty::Method] { let mut rslt = ~[]; - do reader::tagged_docs(item, tag_item_impl_method) |doc| { + reader::tagged_docs(item, tag_item_impl_method, |doc| { let m_did = reader::with_doc_data(doc, parse_def_id); rslt.push(@get_method(intr, cdata, m_did.node, tcx)); true - }; + }); rslt } @@ -1083,10 +1083,10 @@ pub fn get_trait_method_def_ids(cdata: Cmd, let data = cdata.data; let item = lookup_item(id, data); let mut result = ~[]; - do reader::tagged_docs(item, tag_item_trait_method) |mth| { + reader::tagged_docs(item, tag_item_trait_method, |mth| { result.push(item_def_id(mth, cdata)); true - }; + }); result } @@ -1105,7 +1105,7 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd, let item = lookup_item(id, data); let mut result = ~[]; - do reader::tagged_docs(item, tag_item_trait_method) |mth_id| { + reader::tagged_docs(item, tag_item_trait_method, |mth_id| { let did = item_def_id(mth_id, cdata); let mth = lookup_item(did.node, data); @@ -1113,7 +1113,7 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd, result.push(@get_method(intr, cdata, did.node, tcx)); } true - }; + }); return result; } @@ -1123,7 +1123,7 @@ pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt) -> ~[@ty::TraitRef] { let mut results = ~[]; let item_doc = lookup_item(id, cdata.data); - do reader::tagged_docs(item_doc, tag_item_super_trait_ref) |trait_doc| { + reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| { // NB. Only reads the ones that *aren't* builtin-bounds. See also // get_trait_def() for collecting the builtin bounds. // FIXME(#8559): The builtin bounds shouldn't be encoded in the first place. @@ -1132,7 +1132,7 @@ pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt) results.push(@trait_ref); } true - }; + }); return results; } @@ -1144,10 +1144,10 @@ pub fn get_type_name_if_impl(cdata: Cmd, } let mut ret = None; - do reader::tagged_docs(item, tag_item_impl_type_basename) |doc| { + reader::tagged_docs(item, tag_item_impl_type_basename, |doc| { ret = Some(token::str_to_ident(doc.as_str_slice())); false - }; + }); ret } @@ -1162,17 +1162,17 @@ pub fn get_static_methods_if_impl(intr: @ident_interner, } // If this impl implements a trait, don't consider it. - let ret = do reader::tagged_docs(item, tag_item_trait_ref) |_doc| { + let ret = reader::tagged_docs(item, tag_item_trait_ref, |_doc| { false - }; + }); if !ret { return None } let mut impl_method_ids = ~[]; - do reader::tagged_docs(item, tag_item_impl_method) |impl_method_doc| { + reader::tagged_docs(item, tag_item_impl_method, |impl_method_doc| { impl_method_ids.push(reader::with_doc_data(impl_method_doc, parse_def_id)); true - }; + }); let mut static_impl_methods = ~[]; for impl_method_id in impl_method_ids.iter() { @@ -1205,13 +1205,13 @@ pub fn get_item_attrs(cdata: Cmd, node_id: ast::NodeId, f: |~[@ast::MetaItem]|) { let item = lookup_item(node_id, cdata.data); - do reader::tagged_docs(item, tag_attributes) |attributes| { - do reader::tagged_docs(attributes, tag_attribute) |attribute| { + reader::tagged_docs(item, tag_attributes, |attributes| { + reader::tagged_docs(attributes, tag_attribute, |attribute| { f(get_meta_items(attribute)); true - }; + }); true - }; + }); } fn struct_field_family_to_visibility(family: Family) -> ast::visibility { @@ -1228,7 +1228,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId) let data = cdata.data; let item = lookup_item(id, data); let mut result = ~[]; - do reader::tagged_docs(item, tag_item_field) |an_item| { + reader::tagged_docs(item, tag_item_field, |an_item| { let f = item_family(an_item); if f == PublicField || f == PrivateField || f == InheritedField { // FIXME #6993: name should be of type Name, not Ident @@ -1241,8 +1241,8 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId) }); } true - }; - do reader::tagged_docs(item, tag_item_unnamed_field) |an_item| { + }); + reader::tagged_docs(item, tag_item_unnamed_field, |an_item| { let did = item_def_id(an_item, cdata); result.push(ty::field_ty { name: special_idents::unnamed_field.name, @@ -1250,7 +1250,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId) vis: ast::inherited, }); true - }; + }); result } @@ -1272,13 +1272,13 @@ fn family_names_type(fam: Family) -> bool { } fn read_path(d: ebml::Doc) -> (~str, uint) { - do reader::with_doc_data(d) |desc| { + reader::with_doc_data(d, |desc| { let pos = u64_from_be_bytes(desc, 0u, 4u) as uint; let pathbytes = desc.slice(4u, desc.len()); let path = str::from_utf8(pathbytes); (path, pos) - } + }) } fn describe_def(items: ebml::Doc, id: ast::DefId) -> ~str { @@ -1317,13 +1317,13 @@ fn item_family_to_str(fam: Family) -> ~str { fn get_meta_items(md: ebml::Doc) -> ~[@ast::MetaItem] { let mut items: ~[@ast::MetaItem] = ~[]; - do reader::tagged_docs(md, tag_meta_item_word) |meta_item_doc| { + reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); let n = nd.as_str_slice().to_managed(); items.push(attr::mk_word_item(n)); true - }; - do reader::tagged_docs(md, tag_meta_item_name_value) |meta_item_doc| { + }); + reader::tagged_docs(md, tag_meta_item_name_value, |meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); let vd = reader::get_doc(meta_item_doc, tag_meta_item_value); let n = nd.as_str_slice().to_managed(); @@ -1332,14 +1332,14 @@ fn get_meta_items(md: ebml::Doc) -> ~[@ast::MetaItem] { // but currently the encoder just drops them items.push(attr::mk_name_value_item_str(n, v)); true - }; - do reader::tagged_docs(md, tag_meta_item_list) |meta_item_doc| { + }); + reader::tagged_docs(md, tag_meta_item_list, |meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); let n = nd.as_str_slice().to_managed(); let subitems = get_meta_items(meta_item_doc); items.push(attr::mk_list_item(n, subitems)); true - }; + }); return items; } @@ -1347,7 +1347,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] { let mut attrs: ~[ast::Attribute] = ~[]; match reader::maybe_get_doc(md, tag_attributes) { option::Some(attrs_d) => { - do reader::tagged_docs(attrs_d, tag_attribute) |attr_doc| { + reader::tagged_docs(attrs_d, tag_attribute, |attr_doc| { let meta_items = get_meta_items(attr_doc); // Currently it's only possible to have a single meta item on // an attribute @@ -1363,7 +1363,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] { span: codemap::dummy_sp() }); true - }; + }); } option::None => () } @@ -1412,14 +1412,14 @@ pub fn get_crate_deps(data: @~[u8]) -> ~[CrateDep] { let d = reader::get_doc(doc, tag_); d.as_str_slice().to_managed() } - do reader::tagged_docs(depsdoc, tag_crate_dep) |depdoc| { + reader::tagged_docs(depsdoc, tag_crate_dep, |depdoc| { deps.push(CrateDep {cnum: crate_num, name: token::str_to_ident(docstr(depdoc, tag_crate_dep_name)), vers: docstr(depdoc, tag_crate_dep_vers), hash: docstr(depdoc, tag_crate_dep_hash)}); crate_num += 1; true - }; + }); return deps; } @@ -1477,22 +1477,23 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) { let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls); - let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| { + let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| { callback(item_def_id(impl_doc, cdata)); true - }; + }); } pub fn each_implementation_for_type(cdata: Cmd, id: ast::NodeId, callback: |ast::DefId|) { let item_doc = lookup_item(id, cdata.data); - do reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl) - |impl_doc| { + reader::tagged_docs(item_doc, + tag_items_data_item_inherent_impl, + |impl_doc| { let implementation_def_id = item_def_id(impl_doc, cdata); callback(implementation_def_id); true - }; + }); } pub fn each_implementation_for_trait(cdata: Cmd, @@ -1500,13 +1501,13 @@ pub fn each_implementation_for_trait(cdata: Cmd, callback: |ast::DefId|) { let item_doc = lookup_item(id, cdata.data); - let _ = do reader::tagged_docs(item_doc, - tag_items_data_item_extension_impl) - |impl_doc| { + let _ = reader::tagged_docs(item_doc, + tag_items_data_item_extension_impl, + |impl_doc| { let implementation_def_id = item_def_id(impl_doc, cdata); callback(implementation_def_id); true - }; + }); } pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt) @@ -1521,10 +1522,8 @@ pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt) match item_family(parent_item_doc) { Trait => Some(item_def_id(parent_item_doc, cdata)), Impl => { - do reader::maybe_get_doc(parent_item_doc, tag_item_trait_ref).map - |_| { - item_trait_ref(parent_item_doc, tcx, cdata).def_id - } + reader::maybe_get_doc(parent_item_doc, tag_item_trait_ref) + .map(|_| item_trait_ref(parent_item_doc, tcx, cdata).def_id) } _ => None } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index c22f05d249cde..8f09353796b7e 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -615,12 +615,12 @@ fn encode_info_for_mod(ecx: &EncodeContext, ebml_w.wr_str(def_to_str(local_def(item.id))); ebml_w.end_tag(); - do each_auxiliary_node_id(*item) |auxiliary_node_id| { + each_auxiliary_node_id(*item, |auxiliary_node_id| { ebml_w.start_tag(tag_mod_child); ebml_w.wr_str(def_to_str(local_def(auxiliary_node_id))); ebml_w.end_tag(); true - }; + }); match item.node { item_impl(*) => { @@ -1570,13 +1570,13 @@ fn encode_crate_deps(ecx: &EncodeContext, // Pull the cnums and name,vers,hash out of cstore let mut deps = ~[]; - do cstore::iter_crate_data(cstore) |key, val| { + cstore::iter_crate_data(cstore, |key, val| { let dep = decoder::CrateDep {cnum: key, name: ecx.tcx.sess.ident_of(val.name), vers: decoder::get_crate_vers(val.data), hash: decoder::get_crate_hash(val.data)}; deps.push(dep); - }; + }); // Sort by cnum extra::sort::quick_sort(deps, |kv1, kv2| kv1.cnum <= kv2.cnum); @@ -1697,12 +1697,12 @@ fn encode_misc_info(ecx: &EncodeContext, ebml_w.wr_str(def_to_str(local_def(item.id))); ebml_w.end_tag(); - do each_auxiliary_node_id(item) |auxiliary_node_id| { + each_auxiliary_node_id(item, |auxiliary_node_id| { ebml_w.start_tag(tag_mod_child); ebml_w.wr_str(def_to_str(local_def(auxiliary_node_id))); ebml_w.end_tag(); true - }; + }); } // Encode reexports for the root module. diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 4a27450bb43d8..b2e5888eee1a5 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -118,7 +118,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>, } pub fn search(filesearch: @FileSearch, pick: pick) { - do filesearch.for_each_lib_search_path() |lib_search_path| { + filesearch.for_each_lib_search_path(|lib_search_path| { debug!("searching {}", lib_search_path.display()); match io::result(|| fs::readdir(lib_search_path)) { Ok(files) => { @@ -140,7 +140,7 @@ pub fn search(filesearch: @FileSearch, pick: pick) { } Err(*) => FileDoesntMatch, } - }; + }); } pub fn relative_target_lib_path(target_triple: &str) -> Path { diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 391b894460034..ecd1c8985bd00 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -193,17 +193,15 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem], debug!("matching {} metadata requirements against {} items", local_metas.len(), extern_metas.len()); - do local_metas.iter().all |needed| { - attr::contains(extern_metas, *needed) - } + local_metas.iter().all(|needed| attr::contains(extern_metas, *needed)) } fn get_metadata_section(os: Os, filename: &Path) -> Option<@~[u8]> { unsafe { - let mb = do filename.with_c_str |buf| { + let mb = filename.with_c_str(|buf| { llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) - }; + }); if mb as int == 0 { return option::None::<@~[u8]>; } let of = match mk_object_file(mb) { option::Some(of) => of, @@ -224,19 +222,19 @@ fn get_metadata_section(os: Os, vlen); let minsz = num::min(vlen, csz); let mut version_ok = false; - do vec::raw::buf_as_slice(cvbuf, minsz) |buf0| { + vec::raw::buf_as_slice(cvbuf, minsz, |buf0| { version_ok = (buf0 == encoder::metadata_encoding_version); - } + }); if !version_ok { return None; } let cvbuf1 = ptr::offset(cvbuf, vlen as int); debug!("inflating {} bytes of compressed metadata", csz - vlen); - do vec::raw::buf_as_slice(cvbuf1, csz-vlen) |bytes| { + vec::raw::buf_as_slice(cvbuf1, csz-vlen, |bytes| { let inflated = flate::inflate_bytes(bytes); found = Some(@(inflated)); - } + }); if found != None { return found; } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index f1207b07ada89..19a9a7efc578a 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -132,7 +132,7 @@ fn enc_opt(w: @mut MemWriter, t: Option, enc_f: |T|) { fn enc_substs(w: @mut MemWriter, cx: @ctxt, substs: &ty::substs) { enc_region_substs(w, cx, &substs.regions); - do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) } + enc_opt(w, substs.self_ty, |t| enc_ty(w, cx, t)); mywrite!(w, "["); for t in substs.tps.iter() { enc_ty(w, cx, *t); } mywrite!(w, "]"); @@ -350,10 +350,10 @@ fn enc_purity(w: @mut MemWriter, p: purity) { fn enc_abi_set(w: @mut MemWriter, abis: AbiSet) { mywrite!(w, "["); - do abis.each |abi| { + abis.each(|abi| { mywrite!(w, "{},", abi.name()); true - }; + }); mywrite!(w, "]") } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 7f8816bd6137d..c0dc904b9a376 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -303,7 +303,7 @@ struct NestedItemsDropper { impl fold::ast_fold for NestedItemsDropper { fn fold_block(&self, blk: &ast::Block) -> ast::Block { - let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| { + let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| { match stmt.node { ast::StmtExpr(_, _) | ast::StmtSemi(_, _) | ast::StmtDecl(@codemap::Spanned { @@ -316,7 +316,7 @@ impl fold::ast_fold for NestedItemsDropper { }, _) => None, ast::StmtMac(*) => fail!("unexpanded macro in astencode") } - }.collect(); + }).collect(); let blk_sans_items = ast::Block { view_items: ~[], // I don't know if we need the view_items here, // but it doesn't break tests! @@ -568,26 +568,26 @@ trait read_method_map_entry_helper { fn encode_method_map_entry(ecx: &e::EncodeContext, ebml_w: &mut writer::Encoder, mme: method_map_entry) { - do ebml_w.emit_struct("method_map_entry", 3) |ebml_w| { - do ebml_w.emit_struct_field("self_ty", 0u) |ebml_w| { + ebml_w.emit_struct("method_map_entry", 3, |ebml_w| { + ebml_w.emit_struct_field("self_ty", 0u, |ebml_w| { ebml_w.emit_ty(ecx, mme.self_ty); - } - do ebml_w.emit_struct_field("explicit_self", 2u) |ebml_w| { + }); + ebml_w.emit_struct_field("explicit_self", 2u, |ebml_w| { mme.explicit_self.encode(ebml_w); - } - do ebml_w.emit_struct_field("origin", 1u) |ebml_w| { + }); + ebml_w.emit_struct_field("origin", 1u, |ebml_w| { mme.origin.encode(ebml_w); - } - do ebml_w.emit_struct_field("self_mode", 3) |ebml_w| { + }); + ebml_w.emit_struct_field("self_mode", 3, |ebml_w| { mme.self_mode.encode(ebml_w); - } - } + }); + }) } impl read_method_map_entry_helper for reader::Decoder { fn read_method_map_entry(&mut self, xcx: @ExtendedDecodeContext) -> method_map_entry { - do self.read_struct("method_map_entry", 3) |this| { + self.read_struct("method_map_entry", 3, |this| { method_map_entry { self_ty: this.read_struct_field("self_ty", 0u, |this| { this.read_ty(xcx) @@ -608,7 +608,7 @@ impl read_method_map_entry_helper for reader::Decoder { self_mode }), } - } + }) } } @@ -648,50 +648,50 @@ pub fn encode_vtable_res(ecx: &e::EncodeContext, // ty::t doesn't work, and there is no way (atm) to have // hand-written encoding routines combine with auto-generated // ones. perhaps we should fix this. - do ebml_w.emit_from_vec(*dr) |ebml_w, param_tables| { + ebml_w.emit_from_vec(*dr, |ebml_w, param_tables| { encode_vtable_param_res(ecx, ebml_w, *param_tables); - } + }) } pub fn encode_vtable_param_res(ecx: &e::EncodeContext, ebml_w: &mut writer::Encoder, param_tables: typeck::vtable_param_res) { - do ebml_w.emit_from_vec(*param_tables) |ebml_w, vtable_origin| { + ebml_w.emit_from_vec(*param_tables, |ebml_w, vtable_origin| { encode_vtable_origin(ecx, ebml_w, vtable_origin) - } + }) } pub fn encode_vtable_origin(ecx: &e::EncodeContext, ebml_w: &mut writer::Encoder, vtable_origin: &typeck::vtable_origin) { - do ebml_w.emit_enum("vtable_origin") |ebml_w| { + ebml_w.emit_enum("vtable_origin", |ebml_w| { match *vtable_origin { typeck::vtable_static(def_id, ref tys, vtable_res) => { - do ebml_w.emit_enum_variant("vtable_static", 0u, 3u) |ebml_w| { - do ebml_w.emit_enum_variant_arg(0u) |ebml_w| { + ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| { + ebml_w.emit_enum_variant_arg(0u, |ebml_w| { ebml_w.emit_def_id(def_id) - } - do ebml_w.emit_enum_variant_arg(1u) |ebml_w| { + }); + ebml_w.emit_enum_variant_arg(1u, |ebml_w| { ebml_w.emit_tys(ecx, *tys); - } - do ebml_w.emit_enum_variant_arg(2u) |ebml_w| { + }); + ebml_w.emit_enum_variant_arg(2u, |ebml_w| { encode_vtable_res(ecx, ebml_w, vtable_res); - } - } + }) + }) } typeck::vtable_param(pn, bn) => { - do ebml_w.emit_enum_variant("vtable_param", 1u, 2u) |ebml_w| { - do ebml_w.emit_enum_variant_arg(0u) |ebml_w| { + ebml_w.emit_enum_variant("vtable_param", 1u, 2u, |ebml_w| { + ebml_w.emit_enum_variant_arg(0u, |ebml_w| { pn.encode(ebml_w); - } - do ebml_w.emit_enum_variant_arg(1u) |ebml_w| { + }); + ebml_w.emit_enum_variant_arg(1u, |ebml_w| { ebml_w.emit_uint(bn); - } - } + }) + }) } } - } + }) } pub trait vtable_decoder_helpers { @@ -724,40 +724,40 @@ impl vtable_decoder_helpers for reader::Decoder { fn read_vtable_origin(&mut self, tcx: ty::ctxt, cdata: @cstore::crate_metadata) -> typeck::vtable_origin { - do self.read_enum("vtable_origin") |this| { - do this.read_enum_variant(["vtable_static", - "vtable_param", - "vtable_self"]) - |this, i| { + self.read_enum("vtable_origin", |this| { + this.read_enum_variant(["vtable_static", + "vtable_param", + "vtable_self"], + |this, i| { match i { 0 => { typeck::vtable_static( - do this.read_enum_variant_arg(0u) |this| { + this.read_enum_variant_arg(0u, |this| { this.read_def_id_noxcx(cdata) - }, - do this.read_enum_variant_arg(1u) |this| { + }), + this.read_enum_variant_arg(1u, |this| { this.read_tys_noxcx(tcx, cdata) - }, - do this.read_enum_variant_arg(2u) |this| { + }), + this.read_enum_variant_arg(2u, |this| { this.read_vtable_res(tcx, cdata) - } + }) ) } 1 => { typeck::vtable_param( - do this.read_enum_variant_arg(0u) |this| { + this.read_enum_variant_arg(0u, |this| { Decodable::decode(this) - }, - do this.read_enum_variant_arg(1u) |this| { + }), + this.read_enum_variant_arg(1u, |this| { this.read_uint() - } + }) ) } // hard to avoid - user input _ => fail!("bad enum variant") } - } - } + }) + }) } } @@ -793,54 +793,48 @@ trait ebml_writer_helpers { impl ebml_writer_helpers for writer::Encoder { fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) { - do self.emit_opaque |this| { - e::write_type(ecx, this, ty) - } + self.emit_opaque(|this| e::write_type(ecx, this, ty)) } fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) { - do self.emit_opaque |this| { - e::write_vstore(ecx, this, vstore) - } + self.emit_opaque(|this| e::write_vstore(ecx, this, vstore)) } fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) { - do self.emit_from_vec(tys) |this, ty| { - this.emit_ty(ecx, *ty) - } + self.emit_from_vec(tys, |this, ty| this.emit_ty(ecx, *ty)) } fn emit_type_param_def(&mut self, ecx: &e::EncodeContext, type_param_def: &ty::TypeParameterDef) { - do self.emit_opaque |this| { + self.emit_opaque(|this| { tyencode::enc_type_param_def(this.writer, ecx.ty_str_ctxt(), type_param_def) - } + }) } fn emit_tpbt(&mut self, ecx: &e::EncodeContext, tpbt: ty::ty_param_bounds_and_ty) { - do self.emit_struct("ty_param_bounds_and_ty", 2) |this| { - do this.emit_struct_field("generics", 0) |this| { - do this.emit_struct("Generics", 2) |this| { - do this.emit_struct_field("type_param_defs", 0) |this| { - do this.emit_from_vec(*tpbt.generics.type_param_defs) - |this, type_param_def| { + self.emit_struct("ty_param_bounds_and_ty", 2, |this| { + this.emit_struct_field("generics", 0, |this| { + this.emit_struct("Generics", 2, |this| { + this.emit_struct_field("type_param_defs", 0, |this| { + this.emit_from_vec(*tpbt.generics.type_param_defs, + |this, type_param_def| { this.emit_type_param_def(ecx, type_param_def); - } - } - do this.emit_struct_field("region_param_defs", 1) |this| { + }) + }); + this.emit_struct_field("region_param_defs", 1, |this| { tpbt.generics.region_param_defs.encode(this); - } - } - } - do this.emit_struct_field("ty", 1) |this| { + }) + }) + }); + this.emit_struct_field("ty", 1, |this| { this.emit_ty(ecx, tpbt.ty); - } - } + }) + }) } } @@ -912,50 +906,48 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, { let r = tcx.def_map.find(&id); for def in r.iter() { - do ebml_w.tag(c::tag_table_def) |ebml_w| { + ebml_w.tag(c::tag_table_def, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { - (*def).encode(ebml_w) - } - } + ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w)); + }) } } { let r = tcx.node_types.find(&(id as uint)); for &ty in r.iter() { - do ebml_w.tag(c::tag_table_node_type) |ebml_w| { + ebml_w.tag(c::tag_table_node_type, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.emit_ty(ecx, *ty); - } - } + }) + }) } } { let r = tcx.node_type_substs.find(&id); for tys in r.iter() { - do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| { + ebml_w.tag(c::tag_table_node_type_subst, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.emit_tys(ecx, **tys) - } - } + }) + }) } } { let r = tcx.freevars.find(&id); for &fv in r.iter() { - do ebml_w.tag(c::tag_table_freevars) |ebml_w| { + ebml_w.tag(c::tag_table_freevars, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { - do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| { + ebml_w.tag(c::tag_table_val, |ebml_w| { + ebml_w.emit_from_vec(**fv, |ebml_w, fv_entry| { encode_freevar_entry(ebml_w, *fv_entry) - } - } - } + }) + }) + }) } } @@ -963,74 +955,74 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, { let r = tcx.tcache.find(&lid); for &tpbt in r.iter() { - do ebml_w.tag(c::tag_table_tcache) |ebml_w| { + ebml_w.tag(c::tag_table_tcache, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.emit_tpbt(ecx, *tpbt); - } - } + }) + }) } } { let r = tcx.ty_param_defs.find(&id); for &type_param_def in r.iter() { - do ebml_w.tag(c::tag_table_param_defs) |ebml_w| { + ebml_w.tag(c::tag_table_param_defs, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { ebml_w.emit_type_param_def(ecx, type_param_def) - } - } + }) + }) } } { let r = maps.method_map.find(&id); for &mme in r.iter() { - do ebml_w.tag(c::tag_table_method_map) |ebml_w| { + ebml_w.tag(c::tag_table_method_map, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { encode_method_map_entry(ecx, ebml_w, *mme) - } - } + }) + }) } } { let r = maps.vtable_map.find(&id); for &dr in r.iter() { - do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| { + ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { encode_vtable_res(ecx, ebml_w, *dr); - } - } + }) + }) } } { let r = tcx.adjustments.find(&id); for adj in r.iter() { - do ebml_w.tag(c::tag_table_adjustments) |ebml_w| { + ebml_w.tag(c::tag_table_adjustments, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { + ebml_w.tag(c::tag_table_val, |ebml_w| { (**adj).encode(ebml_w) - } - } + }) + }) } } { let r = maps.capture_map.find(&id); for &cap_vars in r.iter() { - do ebml_w.tag(c::tag_table_capture_map) |ebml_w| { + ebml_w.tag(c::tag_table_capture_map, |ebml_w| { ebml_w.id(id); - do ebml_w.tag(c::tag_table_val) |ebml_w| { - do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| { + ebml_w.tag(c::tag_table_val, |ebml_w| { + ebml_w.emit_from_vec(*cap_vars, |ebml_w, cap_var| { cap_var.encode(ebml_w); - } - } - } + }) + }) + }) } } } @@ -1072,14 +1064,14 @@ trait ebml_decoder_decoder_helpers { impl ebml_decoder_decoder_helpers for reader::Decoder { fn read_ty_noxcx(&mut self, tcx: ty::ctxt, cdata: @cstore::crate_metadata) -> ty::t { - do self.read_opaque |_, doc| { + self.read_opaque(|_, doc| { tydecode::parse_ty_data( *doc.data, cdata.cnum, doc.start, tcx, |_, id| decoder::translate_def_id(cdata, id)) - } + }) } fn read_tys_noxcx(&mut self, @@ -1094,7 +1086,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder { // context. However, we do not bother, because region types // are not used during trans. - return do self.read_opaque |this, doc| { + return self.read_opaque(|this, doc| { debug!("read_ty({})", type_string(doc)); let ty = tydecode::parse_ty_data( @@ -1105,7 +1097,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder { |s, a| this.convert_def_id(xcx, s, a)); ty - }; + }); fn type_string(doc: ebml::Doc) -> ~str { let mut str = ~""; @@ -1122,22 +1114,22 @@ impl ebml_decoder_decoder_helpers for reader::Decoder { fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext) -> ty::TypeParameterDef { - do self.read_opaque |this, doc| { + self.read_opaque(|this, doc| { tydecode::parse_type_param_def_data( *doc.data, doc.start, xcx.dcx.cdata.cnum, xcx.dcx.tcx, |s, a| this.convert_def_id(xcx, s, a)) - } + }) } fn read_ty_param_bounds_and_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::ty_param_bounds_and_ty { - do self.read_struct("ty_param_bounds_and_ty", 2) |this| { + self.read_struct("ty_param_bounds_and_ty", 2, |this| { ty::ty_param_bounds_and_ty { - generics: do this.read_struct_field("generics", 0) |this| { - do this.read_struct("Generics", 2) |this| { + generics: this.read_struct_field("generics", 0, |this| { + this.read_struct("Generics", 2, |this| { ty::Generics { type_param_defs: this.read_struct_field("type_param_defs", @@ -1153,13 +1145,13 @@ impl ebml_decoder_decoder_helpers for reader::Decoder { Decodable::decode(this) }) } - } - }, + }) + }), ty: this.read_struct_field("ty", 1, |this| { this.read_ty(xcx) }) } - } + }) } fn convert_def_id(&mut self, @@ -1208,7 +1200,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, ast_doc: ebml::Doc) { let dcx = xcx.dcx; let tbl_doc = ast_doc.get(c::tag_table as uint); - do reader::docs(tbl_doc) |tag, entry_doc| { + reader::docs(tbl_doc, |tag, entry_doc| { let id0 = entry_doc.get(c::tag_table_id as uint).as_int(); let id = xcx.tr_id(id0); @@ -1288,7 +1280,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, debug!(">< Side table doc loaded"); true - }; + }); } // ______________________________________________________________________ diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 781aaa5c6163b..774509ab0da58 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -132,10 +132,10 @@ impl<'self> CheckLoanCtxt<'self> { //! are issued for future scopes and thus they may have been //! *issued* but not yet be in effect. - do self.dfcx_loans.each_bit_on_entry_frozen(scope_id) |loan_index| { + self.dfcx_loans.each_bit_on_entry_frozen(scope_id, |loan_index| { let loan = &self.all_loans[loan_index]; op(loan) - } + }) } pub fn each_in_scope_loan(&self, @@ -146,13 +146,13 @@ impl<'self> CheckLoanCtxt<'self> { //! currently in scope. let region_maps = self.tcx().region_maps; - do self.each_issued_loan(scope_id) |loan| { + self.each_issued_loan(scope_id, |loan| { if region_maps.is_subscope_of(scope_id, loan.kill_scope) { op(loan) } else { true } - } + }) } pub fn each_in_scope_restriction(&self, @@ -163,7 +163,7 @@ impl<'self> CheckLoanCtxt<'self> { //! Iterates through all the in-scope restrictions for the //! given `loan_path` - do self.each_in_scope_loan(scope_id) |loan| { + self.each_in_scope_loan(scope_id, |loan| { let mut ret = true; for restr in loan.restrictions.iter() { if restr.loan_path == loan_path { @@ -174,7 +174,7 @@ impl<'self> CheckLoanCtxt<'self> { } } ret - } + }) } pub fn loans_generated_by(&self, scope_id: ast::NodeId) -> ~[uint] { @@ -182,10 +182,10 @@ impl<'self> CheckLoanCtxt<'self> { //! we encounter `scope_id`. let mut result = ~[]; - do self.dfcx_loans.each_gen_bit_frozen(scope_id) |loan_index| { + self.dfcx_loans.each_gen_bit_frozen(scope_id, |loan_index| { result.push(loan_index); true - }; + }); return result; } @@ -200,13 +200,13 @@ impl<'self> CheckLoanCtxt<'self> { let new_loan_indices = self.loans_generated_by(scope_id); debug!("new_loan_indices = {:?}", new_loan_indices); - do self.each_issued_loan(scope_id) |issued_loan| { + self.each_issued_loan(scope_id, |issued_loan| { for &new_loan_index in new_loan_indices.iter() { let new_loan = &self.all_loans[new_loan_index]; self.report_error_if_loans_conflict(issued_loan, new_loan); } true - }; + }); for (i, &x) in new_loan_indices.iter().enumerate() { let old_loan = &self.all_loans[x]; @@ -317,7 +317,7 @@ impl<'self> CheckLoanCtxt<'self> { debug!("check_if_path_is_moved(id={:?}, use_kind={:?}, lp={})", id, use_kind, lp.repr(self.bccx.tcx)); - do self.move_data.each_move_of(id, lp) |move, moved_lp| { + self.move_data.each_move_of(id, lp, |move, moved_lp| { self.bccx.report_use_of_moved_value( span, use_kind, @@ -325,7 +325,7 @@ impl<'self> CheckLoanCtxt<'self> { move, moved_lp); false - }; + }); } pub fn check_assignment(&self, expr: @ast::Expr) { @@ -357,13 +357,13 @@ impl<'self> CheckLoanCtxt<'self> { if self.is_local_variable(cmt) { assert!(cmt.mutbl.is_immutable()); // no "const" locals let lp = opt_loan_path(cmt).unwrap(); - do self.move_data.each_assignment_of(expr.id, lp) |assign| { + self.move_data.each_assignment_of(expr.id, lp, |assign| { self.bccx.report_reassigned_immutable_variable( expr.span, lp, assign); false - }; + }); return; } @@ -546,16 +546,16 @@ impl<'self> CheckLoanCtxt<'self> { // `RESTR_MUTATE` restriction whenever the contents of an // owned pointer are borrowed, and hence while `v[*]` is not // restricted from being written, `v` is. - let cont = do this.each_in_scope_restriction(expr.id, loan_path) - |loan, restr| - { + let cont = this.each_in_scope_restriction(expr.id, + loan_path, + |loan, restr| { if restr.set.intersects(RESTR_MUTATE) { this.report_illegal_mutation(expr, loan_path, loan); false } else { true } - }; + }); if !cont { return false } @@ -621,7 +621,7 @@ impl<'self> CheckLoanCtxt<'self> { } // Check for a non-const loan of `loan_path` - let cont = do this.each_in_scope_loan(expr.id) |loan| { + let cont = this.each_in_scope_loan(expr.id, |loan| { if loan.loan_path == loan_path && loan.mutbl != ConstMutability { this.report_illegal_mutation(expr, @@ -631,7 +631,7 @@ impl<'self> CheckLoanCtxt<'self> { } else { true } - }; + }); if !cont { return false } } @@ -666,7 +666,7 @@ impl<'self> CheckLoanCtxt<'self> { } fn check_move_out_from_id(&self, id: ast::NodeId, span: Span) { - do self.move_data.each_path_moved_by(id) |_, move_path| { + self.move_data.each_path_moved_by(id, |_, move_path| { match self.analyze_move_out_from(id, move_path) { MoveOk => {} MoveWhileBorrowed(loan_path, loan_span) => { @@ -682,7 +682,7 @@ impl<'self> CheckLoanCtxt<'self> { } } true - }; + }); } pub fn analyze_move_out_from(&self, @@ -696,11 +696,11 @@ impl<'self> CheckLoanCtxt<'self> { let mut ret = MoveOk; // check for a conflicting loan: - do self.each_in_scope_restriction(expr_id, move_path) |loan, _| { + self.each_in_scope_restriction(expr_id, move_path, |loan, _| { // Any restriction prevents moves. ret = MoveWhileBorrowed(loan.loan_path, loan.span); false - }; + }); ret } diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 239890415329f..410cf658a9851 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -161,27 +161,25 @@ fn gather_loans_in_local(this: &mut GatherLoanCtxt, None => { // Variable declarations without initializers are considered "moves": let tcx = this.bccx.tcx; - do pat_util::pat_bindings(tcx.def_map, local.pat) - |_, id, span, _| { + pat_util::pat_bindings(tcx.def_map, local.pat, |_, id, span, _| { gather_moves::gather_decl(this.bccx, this.move_data, id, span, id); - } + }) } Some(init) => { // Variable declarations with initializers are considered "assigns": let tcx = this.bccx.tcx; - do pat_util::pat_bindings(tcx.def_map, local.pat) - |_, id, span, _| { + pat_util::pat_bindings(tcx.def_map, local.pat, |_, id, span, _| { gather_moves::gather_assignment(this.bccx, this.move_data, id, span, @LpVar(id), id); - } + }); let init_cmt = this.bccx.cat_expr(init); this.gather_pat(init_cmt, local.pat, None); } @@ -692,7 +690,7 @@ impl<'self> GatherLoanCtxt<'self> { * moves (non-`ref` bindings with linear type). */ - do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| { + self.bccx.cat_pattern(discr_cmt, root_pat, |cmt, pat| { match pat.node { ast::PatIdent(bm, _, _) if self.pat_is_binding(pat) => { match bm { @@ -781,7 +779,7 @@ impl<'self> GatherLoanCtxt<'self> { _ => {} } - } + }) } pub fn vec_slice_info(&self, pat: @ast::Pat, slice_ty: ty::t) diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index ef2c172acdf22..abeaef0543141 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -318,15 +318,15 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> { } mc::cat_deref(cmt_base, _, pk) => { - do opt_loan_path(cmt_base).map |lp| { + opt_loan_path(cmt_base).map(|lp| { @LpExtend(lp, cmt.mutbl, LpDeref(pk)) - } + }) } mc::cat_interior(cmt_base, ik) => { - do opt_loan_path(cmt_base).map |lp| { + opt_loan_path(cmt_base).map(|lp| { @LpExtend(lp, cmt.mutbl, LpInterior(ik)) - } + }) } mc::cat_downcast(cmt_base) | diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index a0a9ba11db2f0..7b060e6ac7db8 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -277,10 +277,10 @@ impl MoveData { match self.path_map.find_copy(&lp) { Some(index) => { - do self.each_base_path(index) |p| { + self.each_base_path(index, |p| { result.push(p); true - }; + }); } None => { match *lp { @@ -448,7 +448,7 @@ impl MoveData { f: |MoveIndex| -> bool) -> bool { let mut ret = true; - do self.each_extending_path(index0) |index| { + self.each_extending_path(index0, |index| { let mut p = self.path(index).first_move; while p != InvalidMoveIndex { if !f(p) { @@ -458,7 +458,7 @@ impl MoveData { p = self.move(p).next_move; } ret - }; + }); ret } @@ -466,10 +466,10 @@ impl MoveData { path: MovePathIndex, kill_id: ast::NodeId, dfcx_moves: &mut MoveDataFlow) { - do self.each_applicable_move(path) |move_index| { + self.each_applicable_move(path, |move_index| { dfcx_moves.add_kill(kill_id, *move_index); true - }; + }); } } @@ -511,11 +511,11 @@ impl FlowedMoveData { * Iterates through each path moved by `id` */ - do self.dfcx_moves.each_gen_bit_frozen(id) |index| { + self.dfcx_moves.each_gen_bit_frozen(id, |index| { let move = &self.move_data.moves[index]; let moved_path = move.path; f(move, self.move_data.path(moved_path).loan_path) - } + }) } pub fn each_move_of(&self, @@ -549,7 +549,7 @@ impl FlowedMoveData { let mut ret = true; - do self.dfcx_moves.each_bit_on_entry_frozen(id) |index| { + self.dfcx_moves.each_bit_on_entry_frozen(id, |index| { let move = &self.move_data.moves[index]; let moved_path = move.path; if base_indices.iter().any(|x| x == &moved_path) { @@ -560,7 +560,7 @@ impl FlowedMoveData { } } else { for &loan_path_index in opt_loan_path_index.iter() { - let cont = do self.move_data.each_base_path(moved_path) |p| { + let cont = self.move_data.each_base_path(moved_path, |p| { if p == loan_path_index { // Scenario 3: some extension of `loan_path` // was moved @@ -568,12 +568,12 @@ impl FlowedMoveData { } else { true } - }; + }); if !cont { ret = false; break } } } ret - } + }) } pub fn is_assignee(&self, @@ -605,14 +605,14 @@ impl FlowedMoveData { } }; - do self.dfcx_assign.each_bit_on_entry_frozen(id) |index| { + self.dfcx_assign.each_bit_on_entry_frozen(id, |index| { let assignment = &self.move_data.var_assignments[index]; if assignment.path == loan_path_index && !f(assignment) { false } else { true } - } + }) } } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 04d6266d405f0..a65dc88ce9984 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -134,13 +134,13 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) { } }; - do walk_pat(*pat) |p| { + walk_pat(*pat, |p| { if pat_matches_nan(p) { cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \ use the is_nan method in a guard instead"); } true - }; + }); let v = ~[*pat]; match is_useful(cx, &seen, v) { @@ -275,14 +275,14 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful { is_useful_specialized(cx, m, v, vec(n), n, left_ty) } ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { - let max_len = do m.rev_iter().fold(0) |max_len, r| { + let max_len = m.rev_iter().fold(0, |max_len, r| { match r[0].node { PatVec(ref before, _, ref after) => { num::max(before.len() + after.len(), max_len) } _ => max_len } - }; + }); for n in iter::range(0u, max_len + 1) { match is_useful_specialized(cx, m, v, vec(n), n, left_ty) { not_useful => (), @@ -454,14 +454,14 @@ fn missing_ctor(cx: &MatchCheckCtxt, ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { // Find the lengths and slices of all vector patterns. - let vec_pat_lens = do m.iter().filter_map |r| { + let vec_pat_lens = m.iter().filter_map(|r| { match r[0].node { PatVec(ref before, ref slice, ref after) => { Some((before.len() + after.len(), slice.is_some())) } _ => None } - }.collect::<~[(uint, bool)]>(); + }).collect::<~[(uint, bool)]>(); // Sort them by length such that for patterns of the same length, // those with a destructured slice come first. @@ -886,7 +886,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, let mut by_ref_span = None; let mut any_by_move = false; for pat in pats.iter() { - do pat_bindings(def_map, *pat) |bm, id, span, _path| { + pat_bindings(def_map, *pat, |bm, id, span, _path| { match bm { BindByRef(_) => { by_ref_span = Some(span); @@ -897,7 +897,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, } } } - } + }) } let check_move: |&Pat, Option<@Pat>| = |p, sub| { @@ -925,7 +925,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, if !any_by_move { return; } // pointless micro-optimization for pat in pats.iter() { - do walk_pat(*pat) |p| { + walk_pat(*pat, |p| { if pat_is_binding(def_map, p) { match p.node { PatIdent(_, _, sub) => { @@ -943,6 +943,6 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, } } true - }; + }); } } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 3b1f409fb1861..28d6f9515a836 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -219,9 +219,7 @@ impl ConstEvalVisitor { } ast::ExprStruct(_, ref fs, None) => { - let cs = do fs.iter().map |f| { - self.classify(f.expr) - }; + let cs = fs.iter().map(|f| self.classify(f.expr)); join_all(cs) } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 96970e13fcbc3..e10e53d257598 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -208,17 +208,17 @@ impl DataFlowContext { fn compute_id_range(&mut self, id: ast::NodeId) -> (uint, uint) { let mut expanded = false; let len = self.nodeid_to_bitset.len(); - let n = do self.nodeid_to_bitset.find_or_insert_with(id) |_| { + let n = self.nodeid_to_bitset.find_or_insert_with(id, |_| { expanded = true; len - }; + }); if expanded { let entry = if self.oper.initial_value() { uint::max_value } else {0}; - do self.words_per_id.times { + self.words_per_id.times(|| { self.gens.push(0); self.kills.push(0); self.on_entry.push(entry); - } + }) } let start = *n * self.words_per_id; let end = start + self.words_per_id; @@ -835,12 +835,12 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> { debug!("DataFlowContext::walk_pat(pat={}, in_out={})", pat.repr(self.dfcx.tcx), bits_to_str(reslice(in_out))); - do ast_util::walk_pat(pat) |p| { + ast_util::walk_pat(pat, |p| { debug!(" p.id={:?} in_out={}", p.id, bits_to_str(reslice(in_out))); self.merge_with_entry_set(p.id, in_out); self.dfcx.apply_gen_kill(p.id, in_out); true - }; + }); } fn walk_pat_alternatives(&mut self, diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 7a842364d1e33..ce2aae3e36bcf 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -318,22 +318,22 @@ mod test { fn each_node() { let graph = create_graph(); let expected = ["A", "B", "C", "D", "E", "F"]; - do graph.each_node |idx, node| { + graph.each_node(|idx, node| { assert_eq!(&expected[*idx], graph.node_data(idx)); assert_eq!(expected[*idx], node.data); true - }; + }); } #[test] fn each_edge() { let graph = create_graph(); let expected = ["AB", "BC", "BD", "DE", "EC", "FB"]; - do graph.each_edge |idx, edge| { + graph.each_edge(|idx, edge| { assert_eq!(&expected[*idx], graph.edge_data(idx)); assert_eq!(expected[*idx], edge.data); true - }; + }); } fn test_adjacent_edges(graph: &Graph, @@ -344,7 +344,7 @@ mod test { assert_eq!(graph.node_data(start_index), &start_data); let mut counter = 0; - do graph.each_incoming_edge(start_index) |edge_index, edge| { + graph.each_incoming_edge(start_index, |edge_index, edge| { assert_eq!(graph.edge_data(edge_index), &edge.data); assert!(counter < expected_incoming.len()); debug!("counter={:?} expected={:?} edge_index={:?} edge={:?}", @@ -358,11 +358,11 @@ mod test { } counter += 1; true - }; + }); assert_eq!(counter, expected_incoming.len()); let mut counter = 0; - do graph.each_outgoing_edge(start_index) |edge_index, edge| { + graph.each_outgoing_edge(start_index, |edge_index, edge| { assert_eq!(graph.edge_data(edge_index), &edge.data); assert!(counter < expected_outgoing.len()); debug!("counter={:?} expected={:?} edge_index={:?} edge={:?}", @@ -376,7 +376,7 @@ mod test { } counter += 1; true - }; + }); assert_eq!(counter, expected_outgoing.len()); } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index b6b1516d05a02..3bc103519dac9 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -125,14 +125,14 @@ fn check_impl_of_trait(cx: &mut Context, it: @item, trait_ref: &trait_ref, self_ // If this trait has builtin-kind supertraits, meet them. let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id); debug!("checking impl with self type {:?}", ty::get(self_ty).sty); - do check_builtin_bounds(cx, self_ty, trait_def.bounds) |missing| { + check_builtin_bounds(cx, self_ty, trait_def.bounds, |missing| { cx.tcx.sess.span_err(self_type.span, format!("the type `{}', which does not fulfill `{}`, cannot implement this \ trait", ty_to_str(cx.tcx, self_ty), missing.user_string(cx.tcx))); cx.tcx.sess.span_note(self_type.span, format!("types implementing this trait must fulfill `{}`", trait_def.bounds.user_string(cx.tcx))); - } + }); // If this is a destructor, check kinds. if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) { @@ -255,12 +255,12 @@ fn check_fn( fn_id: NodeId) { // Check kinds on free variables: - do with_appropriate_checker(cx, fn_id) |chk| { + with_appropriate_checker(cx, fn_id, |chk| { let r = freevars::get_freevars(cx.tcx, fn_id); for fv in r.iter() { chk(cx, *fv); } - } + }); visit::walk_fn(cx, fk, decl, body, sp, fn_id, ()); } @@ -374,20 +374,23 @@ pub fn check_typaram_bounds(cx: &Context, ty: ty::t, type_param_def: &ty::TypeParameterDef) { - do check_builtin_bounds(cx, ty, type_param_def.bounds.builtin_bounds) |missing| { + check_builtin_bounds(cx, + ty, + type_param_def.bounds.builtin_bounds, + |missing| { cx.tcx.sess.span_err( sp, format!("instantiating a type parameter with an incompatible type \ `{}`, which does not fulfill `{}`", ty_to_str(cx.tcx, ty), missing.user_string(cx.tcx))); - } + }); } pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t, bounds: ty::BuiltinBounds, referenced_ty: Option) { - do check_builtin_bounds(cx, ty, bounds) |missing| { + check_builtin_bounds(cx, ty, bounds, |missing| { // Will be Some if the freevar is implicitly borrowed (stack closure). // Emit a less mysterious error message in this case. match referenced_ty { @@ -404,18 +407,18 @@ pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t, sp, format!("this closure's environment must satisfy `{}`", bounds.user_string(cx.tcx))); - } + }); } pub fn check_trait_cast_bounds(cx: &Context, sp: Span, ty: ty::t, bounds: ty::BuiltinBounds) { - do check_builtin_bounds(cx, ty, bounds) |missing| { + check_builtin_bounds(cx, ty, bounds, |missing| { cx.tcx.sess.span_err(sp, format!("cannot pack type `{}`, which does not fulfill \ `{}`, as a trait bounded by {}", ty_to_str(cx.tcx, ty), missing.user_string(cx.tcx), bounds.user_string(cx.tcx))); - } + }); } fn is_nullary_variant(cx: &Context, ex: @Expr) -> bool { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index e8d6a7267dfb6..5babebef2f662 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -413,14 +413,13 @@ impl LanguageItemCollector { pub fn collect_external_language_items(&mut self) { let crate_store = self.session.cstore; - do iter_crate_data(crate_store) |crate_number, _crate_metadata| { - do each_lang_item(crate_store, crate_number) - |node_id, item_index| { + iter_crate_data(crate_store, |crate_number, _crate_metadata| { + each_lang_item(crate_store, crate_number, |node_id, item_index| { let def_id = ast::DefId { crate: crate_number, node: node_id }; self.collect_item(item_index, def_id); true - }; - } + }); + }) } pub fn collect(&mut self, crate: &ast::Crate) { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 2b2c2aa74c709..29e28204bd98f 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -441,7 +441,7 @@ impl<'self> Context<'self> { // of what we changed so we can roll everything back after invoking the // specified closure let mut pushed = 0u; - do each_lint(self.tcx.sess, attrs) |meta, level, lintname| { + each_lint(self.tcx.sess, attrs, |meta, level, lintname| { match self.dict.find_equiv(&lintname) { None => { self.span_lint( @@ -467,7 +467,7 @@ impl<'self> Context<'self> { } } true - }; + }); let old_is_doc_hidden = self.is_doc_hidden; self.is_doc_hidden = self.is_doc_hidden || @@ -479,10 +479,10 @@ impl<'self> Context<'self> { // rollback self.is_doc_hidden = old_is_doc_hidden; - do pushed.times { + pushed.times(|| { let (lint, lvl, src) = self.lint_stack.pop(); self.set_level(lint, lvl, src); - } + }) } fn visit_ids(&self, f: |&mut ast_util::IdVisitor|) { @@ -1135,11 +1135,11 @@ fn check_stability(cx: &Context, e: &ast::Expr) { // this crate match cx.tcx.items.find(&id.node) { Some(ast_node) => { - let s = do ast_node.with_attrs |attrs| { - do attrs.map |a| { + let s = ast_node.with_attrs(|attrs| { + attrs.map(|a| { attr::find_stability(a.iter().map(|a| a.meta())) - } - }; + }) + }); match s { Some(s) => s, @@ -1157,11 +1157,11 @@ fn check_stability(cx: &Context, e: &ast::Expr) { let mut s = None; // run through all the attributes and take the first // stability one. - do csearch::get_item_attrs(cx.tcx.cstore, id) |meta_items| { + csearch::get_item_attrs(cx.tcx.cstore, id, |meta_items| { if s.is_none() { s = attr::find_stability(meta_items.move_iter()) } - } + }); s }; @@ -1189,7 +1189,7 @@ fn check_stability(cx: &Context, e: &ast::Expr) { impl<'self> Visitor<()> for Context<'self> { fn visit_item(&mut self, it: @ast::item, _: ()) { - do self.with_lint_attrs(it.attrs) |cx| { + self.with_lint_attrs(it.attrs, |cx| { check_item_ctypes(cx, it); check_item_non_camel_case_types(cx, it); check_item_non_uppercase_statics(cx, it); @@ -1197,12 +1197,10 @@ impl<'self> Visitor<()> for Context<'self> { check_missing_doc_item(cx, it); check_attrs_usage(cx, it.attrs); - do cx.visit_ids |v| { - v.visit_item(it, ()); - } + cx.visit_ids(|v| v.visit_item(it, ())); visit::walk_item(cx, it, ()); - } + }) } fn visit_foreign_item(&mut self, it: @ast::foreign_item, _: ()) { @@ -1266,15 +1264,15 @@ impl<'self> Visitor<()> for Context<'self> { match *fk { visit::fk_method(_, _, m) => { - do self.with_lint_attrs(m.attrs) |cx| { + self.with_lint_attrs(m.attrs, |cx| { check_missing_doc_method(cx, m); check_attrs_usage(cx, m.attrs); - do cx.visit_ids |v| { + cx.visit_ids(|v| { v.visit_fn(fk, decl, body, span, id, ()); - } + }); recurse(cx); - } + }) } _ => recurse(self), } @@ -1282,12 +1280,12 @@ impl<'self> Visitor<()> for Context<'self> { fn visit_ty_method(&mut self, t: &ast::TypeMethod, _: ()) { - do self.with_lint_attrs(t.attrs) |cx| { + self.with_lint_attrs(t.attrs, |cx| { check_missing_doc_ty_method(cx, t); check_attrs_usage(cx, t.attrs); visit::walk_ty_method(cx, t, ()); - } + }) } fn visit_struct_def(&mut self, @@ -1303,21 +1301,21 @@ impl<'self> Visitor<()> for Context<'self> { } fn visit_struct_field(&mut self, s: @ast::struct_field, _: ()) { - do self.with_lint_attrs(s.node.attrs) |cx| { + self.with_lint_attrs(s.node.attrs, |cx| { check_missing_doc_struct_field(cx, s); check_attrs_usage(cx, s.node.attrs); visit::walk_struct_field(cx, s, ()); - } + }) } fn visit_variant(&mut self, v: &ast::variant, g: &ast::Generics, _: ()) { - do self.with_lint_attrs(v.node.attrs) |cx| { + self.with_lint_attrs(v.node.attrs, |cx| { check_missing_doc_variant(cx, v); check_attrs_usage(cx, v.node.attrs); visit::walk_variant(cx, v, g, ()); - } + }) } } @@ -1356,16 +1354,16 @@ pub fn check_crate(tcx: ty::ctxt, for &(lint, level) in tcx.sess.opts.lint_opts.iter() { cx.set_level(lint, level, CommandLine); } - do cx.with_lint_attrs(crate.attrs) |cx| { - do cx.visit_ids |v| { + cx.with_lint_attrs(crate.attrs, |cx| { + cx.visit_ids(|v| { v.visited_outermost = true; visit::walk_crate(v, crate, ()); - } + }); check_crate_attrs_usage(cx, crate.attrs); visit::walk_crate(cx, crate, ()); - } + }); // If we missed any lints added to the session, then there's a bug somewhere // in the iteration code. diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 3220ab08ede44..4f137f1f5c45d 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -381,12 +381,13 @@ fn visit_fn(v: &mut LivenessVisitor, } for arg in decl.inputs.iter() { - do pat_util::pat_bindings(this.tcx.def_map, arg.pat) - |_bm, arg_id, _x, path| { + pat_util::pat_bindings(this.tcx.def_map, + arg.pat, + |_bm, arg_id, _x, path| { debug!("adding argument {}", arg_id); let ident = ast_util::path_to_ident(path); fn_maps.add_variable(Arg(arg_id, ident)); - } + }) }; // Add `this`, whether explicit or implicit. @@ -429,7 +430,7 @@ fn visit_fn(v: &mut LivenessVisitor, fn visit_local(v: &mut LivenessVisitor, local: @Local, this: @mut IrMaps) { let def_map = this.tcx.def_map; - do pat_util::pat_bindings(def_map, local.pat) |bm, p_id, sp, path| { + pat_util::pat_bindings(def_map, local.pat, |bm, p_id, sp, path| { debug!("adding local variable {}", p_id); let name = ast_util::path_to_ident(path); this.add_live_node_for_node(p_id, VarDefNode(sp)); @@ -447,14 +448,14 @@ fn visit_local(v: &mut LivenessVisitor, local: @Local, this: @mut IrMaps) { is_mutbl: mutbl, kind: kind })); - } + }); visit::walk_local(v, local, this); } fn visit_arm(v: &mut LivenessVisitor, arm: &Arm, this: @mut IrMaps) { let def_map = this.tcx.def_map; for pat in arm.pats.iter() { - do pat_util::pat_bindings(def_map, *pat) |bm, p_id, sp, path| { + pat_util::pat_bindings(def_map, *pat, |bm, p_id, sp, path| { debug!("adding local variable {} from match with bm {:?}", p_id, bm); let name = ast_util::path_to_ident(path); @@ -469,7 +470,7 @@ fn visit_arm(v: &mut LivenessVisitor, arm: &Arm, this: @mut IrMaps) { is_mutbl: mutbl, kind: FromMatch(bm) })); - } + }) } visit::walk_arm(v, arm, this); } @@ -628,9 +629,9 @@ impl Liveness { match expr.node { ExprPath(_) => { let def = self.tcx.def_map.get_copy(&expr.id); - do moves::moved_variable_node_id_from_def(def).map |rdef| { + moves::moved_variable_node_id_from_def(def).map(|rdef| { self.variable(rdef, expr.span) - } + }) } _ => None } @@ -644,9 +645,9 @@ impl Liveness { -> Option { match self.tcx.def_map.find(&node_id) { Some(&def) => { - do moves::moved_variable_node_id_from_def(def).map |rdef| { + moves::moved_variable_node_id_from_def(def).map(|rdef| { self.variable(rdef, span) - } + }) } None => { self.tcx.sess.span_bug( @@ -659,11 +660,11 @@ impl Liveness { pat: @Pat, f: |LiveNode, Variable, Span, NodeId|) { let def_map = self.tcx.def_map; - do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| { + pat_util::pat_bindings(def_map, pat, |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); let var = self.variable(p_id, sp); f(ln, var, sp, p_id); - } + }) } pub fn arm_pats_bindings(&self, @@ -685,11 +686,11 @@ impl Liveness { pub fn define_bindings_in_arm_pats(&self, pats: &[@Pat], succ: LiveNode) -> LiveNode { let mut succ = succ; - do self.arm_pats_bindings(pats) |ln, var, _sp, _id| { + self.arm_pats_bindings(pats, |ln, var, _sp, _id| { self.init_from_succ(ln, succ); self.define(ln, var); succ = ln; - } + }); succ } @@ -792,14 +793,14 @@ impl Liveness { } pub fn ln_str(&self, ln: LiveNode) -> ~str { - str::from_utf8_owned(do io::mem::with_mem_writer |wr| { + str::from_utf8_owned(io::mem::with_mem_writer(|wr| { let wr = wr as &mut io::Writer; write!(wr, "[ln({}) of kind {:?} reads", *ln, self.ir.lnks[*ln]); self.write_vars(wr, ln, |idx| self.users[idx].reader ); write!(wr, " writes"); self.write_vars(wr, ln, |idx| self.users[idx].writer ); write!(wr, " precedes {}]", self.successors[*ln].to_str()); - }) + })) } pub fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) { @@ -833,7 +834,7 @@ impl Liveness { if ln == succ_ln { return false; } let mut changed = false; - do self.indices2(ln, succ_ln) |idx, succ_idx| { + self.indices2(ln, succ_ln, |idx, succ_idx| { let users = &mut *self.users; changed |= copy_if_invalid(users[succ_idx].reader, &mut users[idx].reader); @@ -843,7 +844,7 @@ impl Liveness { users[idx].used = true; changed = true; } - } + }); debug!("merge_from_succ(ln={}, succ={}, first_merge={}, changed={})", ln.to_str(), self.ln_str(succ_ln), first_merge, changed); @@ -939,9 +940,9 @@ impl Liveness { pub fn propagate_through_block(&self, blk: &Block, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.expr, succ); - do blk.stmts.rev_iter().fold(succ) |succ, stmt| { + blk.stmts.rev_iter().fold(succ, |succ, stmt| { self.propagate_through_stmt(*stmt, succ) - } + }) } pub fn propagate_through_stmt(&self, stmt: &Stmt, succ: LiveNode) @@ -993,18 +994,18 @@ impl Liveness { pub fn propagate_through_exprs(&self, exprs: &[@Expr], succ: LiveNode) -> LiveNode { - do exprs.rev_iter().fold(succ) |succ, expr| { + exprs.rev_iter().fold(succ, |succ, expr| { self.propagate_through_expr(*expr, succ) - } + }) } pub fn propagate_through_opt_expr(&self, opt_expr: Option<@Expr>, succ: LiveNode) -> LiveNode { - do opt_expr.iter().fold(succ) |succ, expr| { + opt_expr.iter().fold(succ, |succ, expr| { self.propagate_through_expr(*expr, succ) - } + }) } pub fn propagate_through_expr(&self, expr: @Expr, succ: LiveNode) @@ -1037,12 +1038,12 @@ impl Liveness { // the construction of a closure itself is not important, // but we have to consider the closed over variables. let caps = self.ir.captures(expr); - do caps.rev_iter().fold(succ) |succ, cap| { + caps.rev_iter().fold(succ, |succ, cap| { self.init_from_succ(cap.ln, succ); let var = self.variable(cap.var_nid, expr.span); self.acc(cap.ln, var, ACC_READ | ACC_USE); cap.ln - } + }) }) } @@ -1177,9 +1178,9 @@ impl Liveness { ExprStruct(_, ref fields, with_expr) => { let succ = self.propagate_through_opt_expr(with_expr, succ); - do fields.rev_iter().fold(succ) |succ, field| { + fields.rev_iter().fold(succ, |succ, field| { self.propagate_through_expr(field.expr, succ) - } + }) } ExprCall(f, ref args, _) => { @@ -1230,15 +1231,15 @@ impl Liveness { } ExprInlineAsm(ref ia) => { - let succ = do ia.inputs.rev_iter().fold(succ) |succ, &(_, expr)| { + let succ = ia.inputs.rev_iter().fold(succ, |succ, &(_, expr)| { self.propagate_through_expr(expr, succ) - }; - do ia.outputs.rev_iter().fold(succ) |succ, &(_, expr)| { + }); + ia.outputs.rev_iter().fold(succ, |succ, &(_, expr)| { // see comment on lvalues in // propagate_through_lvalue_components() let succ = self.write_lvalue(expr, succ, ACC_WRITE); self.propagate_through_lvalue_components(expr, succ) - } + }) } ExprLogLevel | @@ -1437,7 +1438,7 @@ fn check_local(this: &mut Liveness, local: @Local) { // should not be live at this point. debug!("check_local() with no initializer"); - do this.pat_bindings(local.pat) |ln, var, sp, id| { + this.pat_bindings(local.pat, |ln, var, sp, id| { if !this.warn_about_unused(sp, id, ln, var) { match this.live_on_exit(ln, var) { None => { /* not live: good */ } @@ -1448,7 +1449,7 @@ fn check_local(this: &mut Liveness, local: @Local) { } } } - } + }) } } @@ -1456,9 +1457,9 @@ fn check_local(this: &mut Liveness, local: @Local) { } fn check_arm(this: &mut Liveness, arm: &Arm) { - do this.arm_pats_bindings(arm.pats) |ln, var, sp, id| { + this.arm_pats_bindings(arm.pats, |ln, var, sp, id| { this.warn_about_unused(sp, id, ln, var); - } + }); visit::walk_arm(this, arm, ()); } @@ -1620,20 +1621,21 @@ impl Liveness { pub fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { for arg in decl.inputs.iter() { - do pat_util::pat_bindings(self.tcx.def_map, arg.pat) - |_bm, p_id, sp, _n| { + pat_util::pat_bindings(self.tcx.def_map, + arg.pat, + |_bm, p_id, sp, _n| { let var = self.variable(p_id, sp); self.warn_about_unused(sp, p_id, entry_ln, var); - } + }) } } pub fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @Pat) { - do self.pat_bindings(pat) |ln, var, sp, id| { + self.pat_bindings(pat, |ln, var, sp, id| { if !self.warn_about_unused(sp, id, ln, var) { self.warn_about_dead_assign(sp, id, ln, var); } - } + }) } pub fn warn_about_unused(&self, diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 9e84b32ae8ffb..93465dc9bac91 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -614,7 +614,7 @@ impl VisitContext { * into itself or not based on its type and annotation. */ - do pat_bindings(self.tcx.def_map, pat) |bm, id, _span, path| { + pat_bindings(self.tcx.def_map, pat, |bm, id, _span, path| { let binding_moves = match bm { BindByRef(_) => false, BindByValue(_) => { @@ -633,7 +633,7 @@ impl VisitContext { if binding_moves { self.move_maps.moves_map.insert(id); } - } + }) } pub fn use_receiver(&mut self, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 0f3d54e295f3e..69e9e4d880df0 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -22,9 +22,9 @@ pub type PatIdMap = HashMap; // use the NodeId of their namesake in the first pattern. pub fn pat_id_map(dm: resolve::DefMap, pat: &Pat) -> PatIdMap { let mut map = HashMap::new(); - do pat_bindings(dm, pat) |_bm, p_id, _s, n| { + pat_bindings(dm, pat, |_bm, p_id, _s, n| { map.insert(path_to_ident(n), p_id); - }; + }); map } @@ -75,7 +75,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: &Pat) -> bool { pub fn pat_bindings(dm: resolve::DefMap, pat: &Pat, it: |BindingMode, NodeId, Span, &Path|) { - do walk_pat(pat) |p| { + walk_pat(pat, |p| { match p.node { PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => { it(binding_mode, p.id, p.span, pth); @@ -83,7 +83,7 @@ pub fn pat_bindings(dm: resolve::DefMap, _ => {} } true - }; + }); } pub fn pat_binding_ids(dm: resolve::DefMap, pat: &Pat) -> ~[NodeId] { @@ -96,13 +96,13 @@ pub fn pat_binding_ids(dm: resolve::DefMap, pat: &Pat) -> ~[NodeId] { /// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(*)`. pub fn pat_contains_bindings(dm: resolve::DefMap, pat: &Pat) -> bool { let mut contains_bindings = false; - do walk_pat(pat) |p| { + walk_pat(pat, |p| { if pat_is_binding(dm, p) { contains_bindings = true; false // there's at least one binding, can short circuit now. } else { true } - }; + }); contains_bindings } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 1d74db959a294..49f26568d3726 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -909,11 +909,12 @@ impl<'self> Visitor for BuildReducedGraphVisitor<'self> { fn visit_foreign_item(&mut self, foreign_item: @foreign_item, context:ReducedGraphParent) { - do self.resolver.build_reduced_graph_for_foreign_item(foreign_item, - context) |r, c| { + self.resolver.build_reduced_graph_for_foreign_item(foreign_item, + context, + |r, c| { let mut v = BuildReducedGraphVisitor{ resolver: r }; visit::walk_foreign_item(&mut v, foreign_item, c); - } + }) } fn visit_view_item(&mut self, view_item:&view_item, context:ReducedGraphParent) { @@ -1227,11 +1228,11 @@ impl Resolver { // If this is a newtype or unit-like struct, define a name // in the value namespace as well - do ctor_id.while_some |cid| { + ctor_id.while_some(|cid| { name_bindings.define_value(DefStruct(local_def(cid)), sp, is_public); None - } + }); // Record the def ID of this struct. self.structs.insert(local_def(item.id)); @@ -1553,12 +1554,12 @@ impl Resolver { let def = DefFn(local_def(foreign_item.id), unsafe_fn); name_bindings.define_value(def, foreign_item.span, is_public); - do self.with_type_parameter_rib( - HasTypeParameters( - generics, foreign_item.id, 0, NormalRibKind)) |this| - { - f(this, new_parent) - } + self.with_type_parameter_rib( + HasTypeParameters(generics, + foreign_item.id, + 0, + NormalRibKind), + |this| f(this, new_parent)); } foreign_item_static(_, m) => { let def = DefStatic(local_def(foreign_item.id), m); @@ -1758,15 +1759,17 @@ impl Resolver { DefForeignMod(def_id) => { // Foreign modules have no names. Recur and populate // eagerly. - do csearch::each_child_of_item(self.session.cstore, - def_id) - |def_like, child_ident, vis| { + csearch::each_child_of_item(self.session.cstore, + def_id, + |def_like, + child_ident, + vis| { self.build_reduced_graph_for_external_crate_def( root, def_like, child_ident, vis) - } + }); } _ => { let (child_name_bindings, new_parent) = @@ -1893,15 +1896,16 @@ impl Resolver { Some(def_id) => def_id, }; - do csearch::each_child_of_item(self.session.cstore, def_id) - |def_like, child_ident, visibility| { + csearch::each_child_of_item(self.session.cstore, + def_id, + |def_like, child_ident, visibility| { debug!("(populating external module) ... found ident: {}", token::ident_to_str(&child_ident)); self.build_reduced_graph_for_external_crate_def(module, def_like, child_ident, visibility) - } + }); module.populated = true } @@ -1918,14 +1922,14 @@ impl Resolver { /// crate. fn build_reduced_graph_for_external_crate(&mut self, root: @mut Module) { - do csearch::each_top_level_item_of_crate(self.session.cstore, - root.def_id.unwrap().crate) - |def_like, ident, visibility| { + csearch::each_top_level_item_of_crate(self.session.cstore, + root.def_id.unwrap().crate, + |def_like, ident, visibility| { self.build_reduced_graph_for_external_crate_def(root, def_like, ident, visibility) - } + }); } /// Creates and adds an import directive to the given module. @@ -3544,20 +3548,23 @@ impl Resolver { // n.b. the discr expr gets visted twice. // but maybe it's okay since the first time will signal an // error if there is one? -- tjc - do self.with_type_parameter_rib( - HasTypeParameters( - generics, item.id, 0, NormalRibKind)) |this| { + self.with_type_parameter_rib(HasTypeParameters(generics, + item.id, + 0, + NormalRibKind), + |this| { visit::walk_item(this, item, ()); - } + }); } item_ty(_, ref generics) => { - do self.with_type_parameter_rib - (HasTypeParameters(generics, item.id, 0, - NormalRibKind)) - |this| { + self.with_type_parameter_rib(HasTypeParameters(generics, + item.id, + 0, + NormalRibKind), + |this| { visit::walk_item(this, item, ()); - } + }); } item_impl(ref generics, @@ -3581,10 +3588,11 @@ impl Resolver { DlDef(DefSelfTy(item.id))); // Create a new rib for the trait-wide type parameters. - do self.with_type_parameter_rib - (HasTypeParameters(generics, item.id, 0, - NormalRibKind)) |this| { - + self.with_type_parameter_rib(HasTypeParameters(generics, + item.id, + 0, + NormalRibKind), + |this| { this.resolve_type_parameters(&generics.ty_params); // Resolve derived traits. @@ -3600,11 +3608,12 @@ impl Resolver { match *method { required(ref ty_m) => { - do this.with_type_parameter_rib + this.with_type_parameter_rib (HasTypeParameters(&ty_m.generics, item.id, generics.ty_params.len(), - MethodRibKind(item.id, Required))) |this| { + MethodRibKind(item.id, Required)), + |this| { // Resolve the method-specific type // parameters. @@ -3616,7 +3625,7 @@ impl Resolver { } this.resolve_type(&ty_m.decl.output); - } + }); } provided(m) => { this.resolve_method(MethodRibKind(item.id, @@ -3626,7 +3635,7 @@ impl Resolver { } } } - } + }); self.type_ribs.pop(); } @@ -3638,14 +3647,14 @@ impl Resolver { } item_mod(ref module_) => { - do self.with_scope(Some(item.ident)) |this| { + self.with_scope(Some(item.ident), |this| { this.resolve_module(module_, item.span, item.ident, item.id); - } + }); } item_foreign_mod(ref foreign_module) => { - do self.with_scope(Some(item.ident)) |this| { + self.with_scope(Some(item.ident), |this| { for foreign_item in foreign_module.items.iter() { match foreign_item.node { foreign_item_fn(_, ref generics) => { @@ -3664,7 +3673,7 @@ impl Resolver { } } } - } + }); } item_fn(ref fn_decl, _, _, ref generics, ref block) => { @@ -3764,7 +3773,7 @@ impl Resolver { self.label_ribs.push(function_label_rib); // If this function has type parameters, add them now. - do self.with_type_parameter_rib(type_parameters) |this| { + self.with_type_parameter_rib(type_parameters, |this| { // Resolve the type parameters. match type_parameters { NoTypeParameters => { @@ -3815,7 +3824,7 @@ impl Resolver { this.resolve_block(block); debug!("(resolving function) leaving function"); - } + }); self.label_ribs.pop(); self.value_ribs.pop(); @@ -3890,10 +3899,11 @@ impl Resolver { } // If applicable, create a rib for the type parameters. - do self.with_type_parameter_rib(HasTypeParameters - (generics, id, 0, - OpaqueFunctionRibKind)) |this| { - + self.with_type_parameter_rib(HasTypeParameters(generics, + id, + 0, + OpaqueFunctionRibKind), + |this| { // Resolve the type parameters. this.resolve_type_parameters(&generics.ty_params); @@ -3901,7 +3911,7 @@ impl Resolver { for field in fields.iter() { this.resolve_type(&field.node.ty); } - } + }); } // Does this really need to take a RibKind or is it always going @@ -3937,9 +3947,11 @@ impl Resolver { methods: &[@method]) { // If applicable, create a rib for the type parameters. let outer_type_parameter_count = generics.ty_params.len(); - do self.with_type_parameter_rib(HasTypeParameters - (generics, id, 0, - NormalRibKind)) |this| { + self.with_type_parameter_rib(HasTypeParameters(generics, + id, + 0, + NormalRibKind), + |this| { // Resolve the type parameters. this.resolve_type_parameters(&generics.ty_params); @@ -4000,7 +4012,7 @@ impl Resolver { Some(r) => { this.current_trait_refs = r; } None => () } - } + }); } fn resolve_module(&mut self, @@ -4037,12 +4049,12 @@ impl Resolver { // user and one 'x' came from the macro. fn binding_mode_map(&mut self, pat: @Pat) -> BindingMap { let mut result = HashMap::new(); - do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { + pat_bindings(self.def_map, pat, |binding_mode, _id, sp, path| { let name = mtwt_resolve(path_to_ident(path)); result.insert(name, binding_info {span: sp, binding_mode: binding_mode}); - } + }); return result; } @@ -4210,19 +4222,19 @@ impl Resolver { } } - do bounds.as_ref().map |bound_vec| { + bounds.as_ref().map(|bound_vec| { for bound in bound_vec.iter() { self.resolve_type_parameter_bound(ty.id, bound); } - }; + }); } ty_closure(c) => { - do c.bounds.as_ref().map |bounds| { + c.bounds.as_ref().map(|bounds| { for bound in bounds.iter() { self.resolve_type_parameter_bound(ty.id, bound); } - }; + }); visit::walk_ty(self, ty, ()); } @@ -4240,7 +4252,7 @@ impl Resolver { // pattern that binds them bindings_list: Option<@mut HashMap>) { let pat_id = pattern.id; - do walk_pat(pattern) |pattern| { + walk_pat(pattern, |pattern| { match pattern.node { PatIdent(binding_mode, ref path, _) if !path.global && path.segments.len() == 1 => { @@ -4480,7 +4492,7 @@ impl Resolver { } } true - }; + }); } fn resolve_bare_identifier_pattern(&mut self, name: Ident) @@ -5056,14 +5068,14 @@ impl Resolver { } ExprLoop(_, Some(label)) => { - do self.with_label_rib |this| { + self.with_label_rib(|this| { let def_like = DlDef(DefLabel(expr.id)); let rib = this.label_ribs[this.label_ribs.len() - 1]; // plain insert (no renaming) rib.bindings.insert(label.name, def_like); visit::walk_expr(this, expr, ()); - } + }) } ExprForLoop(*) => fail!("non-desugared expr_for_loop"), @@ -5316,7 +5328,7 @@ impl Resolver { debug!("(recording def) recording {:?} for {:?}, last private {:?}", def, node_id, lp); self.last_private.insert(node_id, lp); - do self.def_map.insert_or_update_with(node_id, def) |_, old_value| { + self.def_map.insert_or_update_with(node_id, def, |_, old_value| { // Resolve appears to "resolve" the same ID multiple // times, so here is a sanity check it at least comes to // the same conclusion! - nmatsakis @@ -5324,7 +5336,7 @@ impl Resolver { self.session.bug(format!("node_id {:?} resolved first to {:?} \ and then {:?}", node_id, *old_value, def)); } - }; + }); } fn enforce_default_binding_mode(&mut self, diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 27d1e887bd32f..1162f845ed07a 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -446,7 +446,7 @@ fn expand_nested_bindings<'r>(bcx: @mut Block, bcx.val_to_str(val)); let _indenter = indenter(); - do m.map |br| { + m.map(|br| { match br.pats[col].node { ast::PatIdent(_, ref path, Some(inner)) => { let pats = vec::append( @@ -465,7 +465,7 @@ fn expand_nested_bindings<'r>(bcx: @mut Block, } _ => (*br).clone(), } - } + }) } fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::Pat) { @@ -543,13 +543,13 @@ fn enter_default<'r>(bcx: @mut Block, let _indenter = indenter(); // Collect all of the matches that can match against anything. - let matches = do enter_match(bcx, dm, m, col, val) |p| { + let matches = enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatWild | ast::PatWildMulti | ast::PatTup(_) => Some(~[]), ast::PatIdent(_, _, None) if pat_is_binding(dm, p) => Some(~[]), _ => None } - }; + }); // Ok, now, this is pretty subtle. A "default" match is a match // that needs to be considered if none of the actual checks on the @@ -616,7 +616,7 @@ fn enter_opt<'r>(bcx: @mut Block, let tcx = bcx.tcx(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; let mut i = 0; - do enter_match(bcx, tcx.def_map, m, col, val) |p| { + enter_match(bcx, tcx.def_map, m, col, val, |p| { let answer = match p.node { ast::PatEnum(*) | ast::PatIdent(_, _, None) if pat_is_const(tcx.def_map, p) => { @@ -731,7 +731,7 @@ fn enter_opt<'r>(bcx: @mut Block, }; i += 1; answer - } + }) } fn enter_rec_or_struct<'r>(bcx: @mut Block, @@ -749,7 +749,7 @@ fn enter_rec_or_struct<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatStruct(_, ref fpats, _) => { let mut pats = ~[]; @@ -766,7 +766,7 @@ fn enter_rec_or_struct<'r>(bcx: @mut Block, Some(vec::from_elem(fields.len(), dummy)) } } - } + }) } fn enter_tup<'r>(bcx: @mut Block, @@ -784,7 +784,7 @@ fn enter_tup<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatTup(ref elts) => Some((*elts).clone()), _ => { @@ -792,7 +792,7 @@ fn enter_tup<'r>(bcx: @mut Block, Some(vec::from_elem(n_elts, dummy)) } } - } + }) } fn enter_tuple_struct<'r>(bcx: @mut Block, @@ -810,7 +810,7 @@ fn enter_tuple_struct<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatEnum(_, Some(ref elts)) => Some((*elts).clone()), _ => { @@ -818,7 +818,7 @@ fn enter_tuple_struct<'r>(bcx: @mut Block, Some(vec::from_elem(n_elts, dummy)) } } - } + }) } fn enter_box<'r>(bcx: @mut Block, @@ -835,7 +835,7 @@ fn enter_box<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatBox(sub) => { Some(~[sub]) @@ -845,7 +845,7 @@ fn enter_box<'r>(bcx: @mut Block, Some(~[dummy]) } } - } + }) } fn enter_uniq<'r>(bcx: @mut Block, @@ -862,7 +862,7 @@ fn enter_uniq<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: dummy_sp()}; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatUniq(sub) => { Some(~[sub]) @@ -872,7 +872,7 @@ fn enter_uniq<'r>(bcx: @mut Block, Some(~[dummy]) } } - } + }) } fn enter_region<'r>(bcx: @mut Block, @@ -889,7 +889,7 @@ fn enter_region<'r>(bcx: @mut Block, let _indenter = indenter(); let dummy = @ast::Pat { id: 0, node: ast::PatWild, span: dummy_sp() }; - do enter_match(bcx, dm, m, col, val) |p| { + enter_match(bcx, dm, m, col, val, |p| { match p.node { ast::PatRegion(sub) => { Some(~[sub]) @@ -899,7 +899,7 @@ fn enter_region<'r>(bcx: @mut Block, Some(~[dummy]) } } - } + }) } // Returns the options in one column of matches. An option is something that @@ -998,9 +998,9 @@ fn extract_variant_args(bcx: @mut Block, val: ValueRef) -> ExtractedBlock { let _icx = push_ctxt("match::extract_variant_args"); - let args = do vec::from_fn(adt::num_args(repr, disr_val)) |i| { + let args = vec::from_fn(adt::num_args(repr, disr_val), |i| { adt::trans_field_ptr(bcx, repr, val, disr_val, i) - }; + }); ExtractedBlock { vals: args, bcx: bcx } } @@ -1028,7 +1028,7 @@ fn extract_vec_elems(bcx: @mut Block, let (bcx, base, len) = vec_datum.get_vec_base_and_len(bcx, pat_span, pat_id, 0); let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id)); - let mut elems = do vec::from_fn(elem_count) |i| { + let mut elems = vec::from_fn(elem_count, |i| { match slice { None => GEPi(bcx, base, [i]), Some(n) if i < n => GEPi(bcx, base, [i]), @@ -1039,7 +1039,7 @@ fn extract_vec_elems(bcx: @mut Block, } _ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty.to_ref()) } } - }; + }); if slice.is_some() { let n = slice.unwrap(); let slice_byte_offset = Mul(bcx, vt.llunit_size, C_uint(bcx.ccx(), n)); @@ -1108,11 +1108,11 @@ fn pats_require_rooting(bcx: @mut Block, m: &[Match], col: uint) -> bool { - do m.iter().any |br| { + m.iter().any(|br| { let pat_id = br.pats[col].id; let key = root_map_key {id: pat_id, derefs: 0u }; bcx.ccx().maps.root_map.contains_key(&key) - } + }) } fn root_pats_as_necessary(mut bcx: @mut Block, @@ -1137,12 +1137,12 @@ fn root_pats_as_necessary(mut bcx: @mut Block, // matches may be wildcards like _ or identifiers). macro_rules! any_pat ( ($m:expr, $pattern:pat) => ( - do ($m).iter().any |br| { + ($m).iter().any(|br| { match br.pats[col].node { $pattern => true, _ => false } - } + }) ) ) @@ -1163,7 +1163,7 @@ fn any_tup_pat(m: &[Match], col: uint) -> bool { } fn any_tuple_struct_pat(bcx: @mut Block, m: &[Match], col: uint) -> bool { - do m.iter().any |br| { + m.iter().any(|br| { let pat = br.pats[col]; match pat.node { ast::PatEnum(_, Some(_)) => { @@ -1175,7 +1175,7 @@ fn any_tuple_struct_pat(bcx: @mut Block, m: &[Match], col: uint) -> bool { } _ => false } - } + }) } trait CustomFailureHandler { @@ -1335,11 +1335,11 @@ fn store_non_ref_bindings(bcx: @mut Block, let datum = Datum {val: llval, ty: binding_info.ty, mode: ByRef(ZeroMem)}; bcx = datum.store_to(bcx, INIT, lldest); - do opt_temp_cleanups.mutate |temp_cleanups| { + opt_temp_cleanups.mutate(|temp_cleanups| { add_clean_temp_mem(bcx, lldest, binding_info.ty); temp_cleanups.push(lldest); temp_cleanups - }; + }); } TrByRef => {} } @@ -1412,10 +1412,9 @@ fn compile_guard(bcx: @mut Block, bcx = insert_lllocals(bcx, data.bindings_map, false); let val = unpack_result!(bcx, { - do with_scope_result(bcx, guard_expr.info(), - "guard") |bcx| { + with_scope_result(bcx, guard_expr.info(), "guard", |bcx| { expr::trans_to_datum(bcx, guard_expr).to_result() - } + }) }); let val = bool_to_i1(bcx, val); @@ -1424,13 +1423,13 @@ fn compile_guard(bcx: @mut Block, revoke_clean(bcx, *llval); } - return do with_cond(bcx, Not(bcx, val)) |bcx| { + return with_cond(bcx, Not(bcx, val), |bcx| { // Guard does not match: free the values we copied, // and remove all bindings from the lllocals table let bcx = drop_bindings(bcx, data); compile_submatch(bcx, m, vals, chk); bcx - }; + }); fn drop_bindings(bcx: @mut Block, data: &ArmData) -> @mut Block { let mut bcx = bcx; @@ -1530,7 +1529,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, Some(ref rec_fields) => { let pat_ty = node_id_type(bcx, pat_id); let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); - do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { + expr::with_field_tys(tcx, pat_ty, None, |discr, field_tys| { let rec_vals = rec_fields.map(|field_name| { let ix = ty::field_idx_strict(tcx, field_name.name, field_tys); adt::trans_field_ptr(bcx, pat_repr, val, discr, ix) @@ -1540,7 +1539,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, enter_rec_or_struct(bcx, dm, m, col, *rec_fields, val), vec::append(rec_vals, vals_left), chk); - } + }); return; } None => {} @@ -1553,9 +1552,9 @@ fn compile_submatch_continue(mut bcx: @mut Block, ty::ty_tup(ref elts) => elts.len(), _ => ccx.sess.bug("non-tuple type in tuple pattern") }; - let tup_vals = do vec::from_fn(n_tup_elts) |i| { + let tup_vals = vec::from_fn(n_tup_elts, |i| { adt::trans_field_ptr(bcx, tup_repr, val, 0, i) - }; + }); compile_submatch(bcx, enter_tup(bcx, dm, m, col, val, n_tup_elts), vec::append(tup_vals, vals_left), chk); return; @@ -1575,9 +1574,9 @@ fn compile_submatch_continue(mut bcx: @mut Block, } let struct_repr = adt::represent_type(bcx.ccx(), struct_ty); - let llstructvals = do vec::from_fn(struct_element_count) |i| { + let llstructvals = vec::from_fn(struct_element_count, |i| { adt::trans_field_ptr(bcx, struct_repr, val, 0, i) - }; + }); compile_submatch(bcx, enter_tuple_struct(bcx, dm, m, col, val, struct_element_count), @@ -1696,8 +1695,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, compare => { let t = node_id_type(bcx, pat_id); let Result {bcx: after_cx, val: matches} = { - do with_scope_result(bcx, None, - "compaReScope") |bcx| { + with_scope_result(bcx, None, "compaReScope", |bcx| { match trans_opt(bcx, opt) { single_result( Result {bcx, val}) => { @@ -1723,15 +1721,17 @@ fn compile_submatch_continue(mut bcx: @mut Block, rslt(bcx, And(bcx, llge, llle)) } } - } + }) }; bcx = sub_block(after_cx, "compare_next"); CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb); } compare_vec_len => { let Result {bcx: after_cx, val: matches} = { - do with_scope_result(bcx, None, - "compare_vec_len_scope") |bcx| { + with_scope_result(bcx, + None, + "compare_vec_len_scope", + |bcx| { match trans_opt(bcx, opt) { single_result( Result {bcx, val}) => { @@ -1761,7 +1761,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, rslt(bcx, And(bcx, llge, llle)) } } - } + }) }; bcx = sub_block(after_cx, "compare_vec_len_next"); @@ -1821,9 +1821,9 @@ pub fn trans_match(bcx: @mut Block, arms: &[ast::Arm], dest: Dest) -> @mut Block { let _icx = push_ctxt("match::trans_match"); - do with_scope(bcx, match_expr.info(), "match") |bcx| { + with_scope(bcx, match_expr.info(), "match", |bcx| { trans_match_inner(bcx, discr_expr, arms, dest) - } + }) } fn create_bindings_map(bcx: @mut Block, pat: @ast::Pat) -> BindingsMap { @@ -1834,7 +1834,7 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::Pat) -> BindingsMap { let ccx = bcx.ccx(); let tcx = bcx.tcx(); let mut bindings_map = HashMap::new(); - do pat_bindings(tcx.def_map, pat) |bm, p_id, span, path| { + pat_bindings(tcx.def_map, pat, |bm, p_id, span, path| { let ident = path_to_ident(path); let variable_ty = node_id_type(bcx, p_id); let llvariable_ty = type_of::type_of(ccx, variable_ty); @@ -1862,7 +1862,7 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::Pat) -> BindingsMap { span: span, ty: variable_ty }); - } + }); return bindings_map; } @@ -2009,11 +2009,11 @@ pub fn store_local(bcx: @mut Block, // create dummy memory for the variables if we have no // value to store into them immediately let tcx = bcx.tcx(); - do pat_bindings(tcx.def_map, pat) |_, p_id, _, path| { + pat_bindings(tcx.def_map, pat, |_, p_id, _, path| { bcx = mk_binding_alloca( bcx, p_id, path, BindLocal, |bcx, var_ty, llval| { zero_mem(bcx, llval, var_ty); bcx }); - } + }); bcx } } @@ -2201,14 +2201,14 @@ fn bind_irrefutable_pat(bcx: @mut Block, let tcx = bcx.tcx(); let pat_ty = node_id_type(bcx, pat.id); let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); - do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { + expr::with_field_tys(tcx, pat_ty, None, |discr, field_tys| { for f in fields.iter() { let ix = ty::field_idx_strict(tcx, f.ident.name, field_tys); let fldptr = adt::trans_field_ptr(bcx, pat_repr, val, discr, ix); bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, binding_mode); } - } + }) } ast::PatTup(ref elems) => { let repr = adt::represent_node(bcx, pat.id); diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index d75fa9341bf57..d6631f6d833cd 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -135,9 +135,9 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr { } ty::ty_struct(def_id, ref substs) => { let fields = ty::lookup_struct_fields(cx.tcx, def_id); - let mut ftys = do fields.map |field| { + let mut ftys = fields.map(|field| { ty::lookup_field_type(cx.tcx, def_id, field.id, substs) - }; + }); let packed = ty::lookup_packed(cx.tcx, def_id); let dtor = ty::ty_dtor(cx.tcx, def_id).has_drop_flag(); if dtor { ftys.push(ty::mk_bool()); } @@ -259,12 +259,12 @@ impl Case { } fn get_cases(tcx: ty::ctxt, def_id: ast::DefId, substs: &ty::substs) -> ~[Case] { - do ty::enum_variants(tcx, def_id).map |vi| { - let arg_tys = do vi.args.map |&raw_ty| { + ty::enum_variants(tcx, def_id).map(|vi| { + let arg_tys = vi.args.map(|&raw_ty| { ty::subst(tcx, substs, raw_ty) - }; + }); Case { discr: vi.disr_val, tys: arg_tys } - } + }) } @@ -659,9 +659,7 @@ fn struct_field_ptr(bcx: @mut Block, st: &Struct, val: ValueRef, ix: uint, let ccx = bcx.ccx(); let val = if needs_cast { - let fields = do st.fields.map |&ty| { - type_of::type_of(ccx, ty) - }; + let fields = st.fields.map(|&ty| type_of::type_of(ccx, ty)); let real_ty = Type::struct_(fields, st.packed); PointerCast(bcx, val, real_ty.ptr_to()) } else { @@ -725,10 +723,10 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: Disr, C_struct(build_const_struct(ccx, nonnull, vals), false) } else { assert_eq!(vals.len(), 0); - let vals = do nonnull.fields.iter().enumerate().map |(i, &ty)| { + let vals = nonnull.fields.iter().enumerate().map(|(i, &ty)| { let llty = type_of::sizing_type_of(ccx, ty); if i == ptrfield { C_null(llty) } else { C_undef(llty) } - }.collect::<~[ValueRef]>(); + }).collect::<~[ValueRef]>(); C_struct(build_const_struct(ccx, nonnull, vals), false) } } diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index 7f809451b35f2..7b936b61976bc 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -35,14 +35,14 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block { let mut output_types = ~[]; // Prepare the output operands - let outputs = do ia.outputs.map |&(c, out)| { + let outputs = ia.outputs.map(|&(c, out)| { constraints.push(c); let out_datum = unpack_datum!(bcx, trans_to_datum(bcx, out)); output_types.push(type_of(bcx.ccx(), out_datum.ty)); out_datum.val - }; + }); for c in cleanups.iter() { revoke_clean(bcx, *c); @@ -50,7 +50,7 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block { cleanups.clear(); // Now the input operands - let inputs = do ia.inputs.map |&(c, input)| { + let inputs = ia.inputs.map(|&(c, input)| { constraints.push(c); unpack_result!(bcx, { @@ -61,8 +61,7 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block { &mut cleanups, callee::DontAutorefArg) }) - - }; + }); for c in cleanups.iter() { revoke_clean(bcx, *c); @@ -103,11 +102,11 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block { ast::asm_intel => lib::llvm::AD_Intel }; - let r = do ia.asm.with_c_str |a| { - do constraints.with_c_str |c| { + let r = ia.asm.with_c_str(|a| { + constraints.with_c_str(|c| { InlineAsmCall(bcx, a, c, inputs, output_type, ia.volatile, ia.alignstack, dialect) - } - }; + }) + }); // Again, based on how many outputs we have if numOutputs == 1 { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index ea9690ce40609..de93b08f0859c 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -94,12 +94,12 @@ pub use middle::trans::context::task_llcx; local_data_key!(task_local_insn_key: ~[&'static str]) pub fn with_insn_ctxt(blk: |&[&'static str]|) { - do local_data::get(task_local_insn_key) |c| { + local_data::get(task_local_insn_key, |c| { match c { Some(ctx) => blk(*ctx), None => () } - } + }) } pub fn init_insn_ctxt() { @@ -111,23 +111,23 @@ pub struct _InsnCtxt { _x: () } #[unsafe_destructor] impl Drop for _InsnCtxt { fn drop(&mut self) { - do local_data::modify(task_local_insn_key) |c| { - do c.map |mut ctx| { + local_data::modify(task_local_insn_key, |c| { + c.map(|mut ctx| { ctx.pop(); ctx - } - } + }) + }) } } pub fn push_ctxt(s: &'static str) -> _InsnCtxt { debug!("new InsnCtxt: {}", s); - do local_data::modify(task_local_insn_key) |c| { - do c.map |mut ctx| { + local_data::modify(task_local_insn_key, |c| { + c.map(|mut ctx| { ctx.push(s); ctx - } - } + }) + }); _InsnCtxt { _x: () } } @@ -175,11 +175,11 @@ impl<'self> Drop for StatRecorder<'self> { // only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, ty: Type) -> ValueRef { - let llfn: ValueRef = do name.with_c_str |buf| { + let llfn: ValueRef = name.with_c_str(|buf| { unsafe { llvm::LLVMGetOrInsertFunction(llmod, buf, ty.to_ref()) } - }; + }); lib::llvm::SetFunctionCallConv(llfn, cc); // Function addresses in Rust are never significant, allowing functions to be merged. @@ -211,9 +211,9 @@ fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t, None => () } let f = decl_rust_fn(ccx, inputs, output, name); - do csearch::get_item_attrs(ccx.tcx.cstore, did) |meta_items| { + csearch::get_item_attrs(ccx.tcx.cstore, did, |meta_items| { set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f) - } + }); ccx.externs.insert(name.to_owned(), f); f } @@ -285,9 +285,9 @@ pub fn get_extern_const(externs: &mut ExternMap, llmod: ModuleRef, None => () } unsafe { - let c = do name.with_c_str |buf| { + let c = name.with_c_str(|buf| { llvm::LLVMAddGlobal(llmod, ty.to_ref(), buf) - }; + }); externs.insert(name.to_owned(), c); return c; } @@ -496,9 +496,9 @@ pub fn set_always_inline(f: ValueRef) { } pub fn set_no_split_stack(f: ValueRef) { - do "no-split-stack".with_c_str |buf| { + "no-split-stack".with_c_str(|buf| { unsafe { llvm::LLVMAddFunctionAttrString(f, buf); } - } + }) } // Double-check that we never ask LLVM to declare the same symbol twice. It @@ -563,11 +563,11 @@ pub fn get_res_dtor(ccx: @mut CrateContext, // Structural comparison: a rather involved form of glue. pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) { if cx.sess.opts.save_temps { - do s.with_c_str |buf| { + s.with_c_str(|buf| { unsafe { llvm::LLVMSetValueName(v, buf) } - } + }) } } @@ -704,12 +704,12 @@ pub fn iter_structural_ty(cx: @mut Block, av: ValueRef, t: ty::t, match ty::get(t).sty { ty::ty_struct(*) => { let repr = adt::represent_type(cx.ccx(), t); - do expr::with_field_tys(cx.tcx(), t, None) |discr, field_tys| { + expr::with_field_tys(cx.tcx(), t, None, |discr, field_tys| { for (i, field_ty) in field_tys.iter().enumerate() { let llfld_a = adt::trans_field_ptr(cx, repr, av, discr, i); cx = f(cx, llfld_a, field_ty.mt.ty); } - } + }) } ty::ty_estr(ty::vstore_fixed(_)) | ty::ty_evec(_, ty::vstore_fixed(_)) => { @@ -836,9 +836,9 @@ pub fn fail_if_zero(cx: @mut Block, span: Span, divrem: ast::BinOp, ty_to_str(cx.ccx().tcx, rhs_t)); } }; - do with_cond(cx, is_zero) |bcx| { + with_cond(cx, is_zero, |bcx| { controlflow::trans_fail(bcx, Some(span), text) - } + }) } pub fn null_env_ptr(ccx: &CrateContext) -> ValueRef { @@ -959,12 +959,12 @@ pub fn need_invoke(bcx: @mut Block) -> bool { pub fn have_cached_lpad(bcx: @mut Block) -> bool { let mut res = false; - do in_lpad_scope_cx(bcx) |inf| { + in_lpad_scope_cx(bcx, |inf| { match inf.landing_pad { Some(_) => res = true, None => res = false } - } + }); return res; } @@ -993,7 +993,7 @@ pub fn get_landing_pad(bcx: @mut Block) -> BasicBlockRef { let mut cached = None; let mut pad_bcx = bcx; // Guaranteed to be set below - do in_lpad_scope_cx(bcx) |inf| { + in_lpad_scope_cx(bcx, |inf| { // If there is a valid landing pad still around, use it match inf.landing_pad { Some(target) => cached = Some(target), @@ -1002,7 +1002,7 @@ pub fn get_landing_pad(bcx: @mut Block) -> BasicBlockRef { inf.landing_pad = Some(pad_bcx.llbb); } } - } + }); // Can't return from block above match cached { Some(b) => return b, None => () } // The landing pad return type (the type being propagated). Not sure what @@ -1187,9 +1187,9 @@ pub fn new_block(cx: @mut FunctionContext, opt_node_info: Option) -> @mut Block { unsafe { - let llbb = do name.with_c_str |buf| { + let llbb = name.with_c_str(|buf| { llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf) - }; + }); let bcx = @mut Block::new(llbb, parent, is_lpad, @@ -1614,18 +1614,18 @@ pub struct BasicBlocks { pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef { unsafe { let cx = task_llcx(); - do "static_allocas".with_c_str | buf| { + "static_allocas".with_c_str(|buf| { llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf) - } + }) } } pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef { unsafe { let cx = task_llcx(); - do "return".with_c_str |buf| { + "return".with_c_str(|buf| { llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf) - } + }) } } @@ -1765,9 +1765,9 @@ pub fn create_llargs_for_fn_args(cx: @mut FunctionContext, // Return an array containing the ValueRefs that we get from // llvm::LLVMGetParam for each argument. - do vec::from_fn(args.len()) |i| { + vec::from_fn(args.len(), |i| { unsafe { llvm::LLVMGetParam(cx.llfn, cx.arg_pos(i) as c_uint) } - } + }) } pub fn copy_args_to_allocas(fcx: @mut FunctionContext, @@ -2076,7 +2076,7 @@ pub fn trans_enum_variant_or_tuple_like_struct( llfndecl: ValueRef) { // Translate variant arguments to function arguments. - let fn_args = do args.map |varg| { + let fn_args = args.map(|varg| { ast::arg { ty: (*varg.ty()).clone(), pat: ast_util::ident_to_pat( @@ -2085,7 +2085,7 @@ pub fn trans_enum_variant_or_tuple_like_struct( special_idents::arg), id: varg.id(), } - }; + }); let no_substs: &[ty::t] = []; let ty_param_substs = match param_substs { @@ -2386,11 +2386,11 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext, "main" }; let llfn = decl_cdecl_fn(ccx.llmod, main_name, llfty); - let llbb = do "top".with_c_str |buf| { + let llbb = "top".with_c_str(|buf| { unsafe { llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf) } - }; + }); let bld = ccx.builder.B; unsafe { llvm::LLVMPositionBuilderAtEnd(bld, llbb); @@ -2409,9 +2409,9 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext, }; let args = { - let opaque_rust_main = do "rust_main".with_c_str |buf| { + let opaque_rust_main = "rust_main".with_c_str(|buf| { llvm::LLVMBuildPointerCast(bld, rust_main, Type::i8p().to_ref(), buf) - }; + }); ~[ C_null(Type::opaque_box(ccx).ptr_to()), @@ -2432,9 +2432,9 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext, (rust_main, args) }; - let result = do args.as_imm_buf |buf, len| { + let result = args.as_imm_buf(|buf, len| { llvm::LLVMBuildCall(bld, start_fn, buf, len as c_uint, noname()) - }; + }); llvm::LLVMBuildRet(bld, result); } @@ -2509,9 +2509,9 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { unsafe { let llty = llvm::LLVMTypeOf(v); - let g = do sym.with_c_str |buf| { + let g = sym.with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, llty, buf) - }; + }); if !ccx.reachable.contains(&id) { lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); @@ -2571,9 +2571,9 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { match (attr::first_attr_value_str_by_name(i.attrs, "link_section")) { Some(sect) => unsafe { - do sect.with_c_str |buf| { + sect.with_c_str(|buf| { llvm::LLVMSetSection(v, buf); - } + }) }, None => () } @@ -2618,11 +2618,14 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { if attr::contains_name(ni.attrs, "crate_map") { if *ccx.sess.building_library { let s = "_rust_crate_map_toplevel"; - let g = unsafe { do s.with_c_str |buf| { - let ty = type_of(ccx, ty); - llvm::LLVMAddGlobal(ccx.llmod, - ty.to_ref(), buf) - } }; + let g = unsafe { + s.with_c_str(|buf| { + let ty = type_of(ccx, ty); + llvm::LLVMAddGlobal(ccx.llmod, + ty.to_ref(), + buf) + }) + }; lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage); g @@ -2632,11 +2635,11 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { } else { let ident = foreign::link_name(ccx, ni); unsafe { - do ident.with_c_str |buf| { + ident.with_c_str(|buf| { let ty = type_of(ccx, ty); llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf) - } + }) } } } @@ -2904,11 +2907,11 @@ pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) { } let gc_metadata_name = ~"_gc_module_metadata_" + llmod_id; - let gc_metadata = do gc_metadata_name.with_c_str |buf| { + let gc_metadata = gc_metadata_name.with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf) } - }; + }); unsafe { llvm::LLVMSetGlobalConstant(gc_metadata, True); lib::llvm::SetLinkage(gc_metadata, lib::llvm::ExternalLinkage); @@ -2920,11 +2923,11 @@ pub fn create_module_map(ccx: &mut CrateContext) -> (ValueRef, uint) { let str_slice_type = Type::struct_([Type::i8p(), ccx.int_type], false); let elttype = Type::struct_([str_slice_type, ccx.int_type], false); let maptype = Type::array(&elttype, ccx.module_data.len() as u64); - let map = do "_rust_mod_map".with_c_str |buf| { + let map = "_rust_mod_map".with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf) } - }; + }); lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage); let mut elts: ~[ValueRef] = ~[]; @@ -2973,11 +2976,11 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta, slicetype, // sub crate-maps int_type.ptr_to(), // event loop factory ], false); - let map = do sym_name.with_c_str |buf| { + let map = sym_name.with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf) } - }; + }); // On windows we'd like to export the toplevel cratemap // such that we can find it from libstd. if targ_cfg.os == OsWin32 && "toplevel" == mapname { @@ -2999,11 +3002,11 @@ pub fn fill_crate_map(ccx: &mut CrateContext, map: ValueRef) { cdata.name, cstore::get_crate_vers(cstore, i), cstore::get_crate_hash(cstore, i)); - let cr = do nm.with_c_str |buf| { + let cr = nm.with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf) } - }; + }); subcrates.push(p2i(ccx, cr)); i += 1; } @@ -3011,9 +3014,9 @@ pub fn fill_crate_map(ccx: &mut CrateContext, map: ValueRef) { match ccx.tcx.lang_items.event_loop_factory() { Some(did) => unsafe { let name = csearch::get_symbol(ccx.sess.cstore, did); - let global = do name.with_c_str |buf| { + let global = name.with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf) - }; + }); global }, None => C_null(ccx.int_type.ptr_to()) @@ -3023,9 +3026,9 @@ pub fn fill_crate_map(ccx: &mut CrateContext, map: ValueRef) { }; unsafe { let maptype = Type::array(&ccx.int_type, subcrates.len() as u64); - let vec_elements = do "_crate_map_child_vectors".with_c_str |buf| { + let vec_elements = "_crate_map_child_vectors".with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf) - }; + }); lib::llvm::SetLinkage(vec_elements, lib::llvm::InternalLinkage); llvm::LLVMSetInitializer(vec_elements, C_array(ccx.int_type, subcrates)); @@ -3077,23 +3080,23 @@ pub fn write_metadata(cx: &CrateContext, crate: &ast::Crate) { let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item); let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate)); let llconst = C_struct([llmeta], false); - let mut llglobal = do "rust_metadata".with_c_str |buf| { + let mut llglobal = "rust_metadata".with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst).to_ref(), buf) } - }; + }); unsafe { llvm::LLVMSetInitializer(llglobal, llconst); - do cx.sess.targ_cfg.target_strs.meta_sect_name.with_c_str |buf| { + cx.sess.targ_cfg.target_strs.meta_sect_name.with_c_str(|buf| { llvm::LLVMSetSection(llglobal, buf) - }; + }); lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage); let t_ptr_i8 = Type::i8p(); llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8.to_ref()); - let llvm_used = do "llvm.used".with_c_str |buf| { + let llvm_used = "llvm.used".with_c_str(|buf| { llvm::LLVMAddGlobal(cx.llmod, Type::array(&t_ptr_i8, 1).to_ref(), buf) - }; + }); lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage); llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal])); } @@ -3103,9 +3106,9 @@ pub fn write_metadata(cx: &CrateContext, crate: &ast::Crate) { pub fn write_abi_version(ccx: &mut CrateContext) { unsafe { let llval = C_uint(ccx, abi::abi_version); - let llglobal = do "rust_abi_version".with_c_str |buf| { + let llglobal = "rust_abi_version".with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval).to_ref(), buf) - }; + }); llvm::LLVMSetInitializer(llglobal, llval); llvm::LLVMSetGlobalConstant(llglobal, True); } @@ -3161,12 +3164,12 @@ pub fn trans_crate(sess: session::Session, let maptype = val_ty(ccx.crate_map).to_ref(); - do "__rust_crate_map_toplevel".with_c_str |buf| { + "__rust_crate_map_toplevel".with_c_str(|buf| { unsafe { llvm::LLVMAddAlias(ccx.llmod, maptype, ccx.crate_map, buf); } - } + }) } glue::emit_tydescs(ccx); @@ -3189,9 +3192,10 @@ pub fn trans_crate(sess: session::Session, println!("n_inlines: {}", ccx.stats.n_inlines); println!("n_closures: {}", ccx.stats.n_closures); println("fn stats:"); - do sort::quick_sort(ccx.stats.fn_stats) |&(_, _, insns_a), &(_, _, insns_b)| { + sort::quick_sort(ccx.stats.fn_stats, + |&(_, _, insns_a), &(_, _, insns_b)| { insns_a > insns_b - } + }); for tuple in ccx.stats.fn_stats.iter() { match *tuple { (ref name, ms, insns) => { diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 27b1e6b39dc16..7541a14fc720c 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -51,7 +51,7 @@ impl Builder { self.ccx.stats.n_llvm_insns += 1; } if self.ccx.sess.count_llvm_insns() { - do base::with_insn_ctxt |v| { + base::with_insn_ctxt(|v| { let h = &mut self.ccx.stats.llvm_insns; // Build version of path with cycles removed. @@ -85,7 +85,7 @@ impl Builder { _ => 0u }; h.insert(s, n+1u); - } + }) } } @@ -419,9 +419,9 @@ impl Builder { if name.is_empty() { llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), noname()) } else { - do name.with_c_str |c| { + name.with_c_str(|c| { llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), c) - } + }) } } } @@ -465,11 +465,11 @@ impl Builder { let min = llvm::LLVMConstInt(t, lo, signed); let max = llvm::LLVMConstInt(t, hi, signed); - do [min, max].as_imm_buf |ptr, len| { + [min, max].as_imm_buf(|ptr, len| { llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint, llvm::LLVMMDNodeInContext(self.ccx.llcx, ptr, len as c_uint)); - } + }) } value @@ -518,7 +518,7 @@ impl Builder { } self.inbounds_gep(base, small_vec.slice(0, ixs.len())) } else { - let v = do ixs.iter().map |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>(); + let v = ixs.iter().map(|i| C_i32(*i as i32)).collect::<~[ValueRef]>(); self.count_insn("gepi"); self.inbounds_gep(base, v) } @@ -736,12 +736,12 @@ impl Builder { let sanitized = text.replace("$", ""); let comment_text = format!("\\# {}", sanitized.replace("\n", "\n\t# ")); self.count_insn("inlineasm"); - let asm = do comment_text.with_c_str |c| { + let asm = comment_text.with_c_str(|c| { unsafe { llvm::LLVMConstInlineAsm(Type::func([], &Type::void()).to_ref(), c, noname(), False, False) } - }; + }); self.call(asm, [], []); } } @@ -757,10 +757,10 @@ impl Builder { let alignstack = if alignstack { lib::llvm::True } else { lib::llvm::False }; - let argtys = do inputs.map |v| { + let argtys = inputs.map(|v| { debug!("Asm Input Type: {:?}", self.ccx.tn.val_to_str(*v)); val_ty(*v) - }; + }); debug!("Asm Output Type: {:?}", self.ccx.tn.type_to_str(output)); let fty = Type::func(argtys, &output); @@ -878,9 +878,9 @@ impl Builder { let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(self.llbuilder); let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB); let M: ModuleRef = llvm::LLVMGetGlobalParent(FN); - let T: ValueRef = do "llvm.trap".with_c_str |buf| { + let T: ValueRef = "llvm.trap".with_c_str(|buf| { llvm::LLVMGetNamedFunction(M, buf) - }; + }); assert!((T as int != 0)); let args: &[ValueRef] = []; self.count_insn("trap"); diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index d78311c8a398a..10c34b0b92888 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -616,7 +616,7 @@ pub fn trans_call_inner(in_cx: @mut Block, */ - do base::with_scope_result(in_cx, call_info, "call") |cx| { + base::with_scope_result(in_cx, call_info, "call", |cx| { let callee = get_callee(cx); let mut bcx = callee.bcx; let ccx = cx.ccx(); @@ -776,7 +776,7 @@ pub fn trans_call_inner(in_cx: @mut Block, } rslt(bcx, llresult) - } + }) } pub enum CallArgs<'self> { diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index baccd9c7028e3..768d3cbd4b2c8 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -438,10 +438,10 @@ pub fn make_closure_glue(cx: @mut Block, ast::OwnedSigil | ast::ManagedSigil => { let box_cell_v = GEPi(cx, v, [0u, abi::fn_field_box]); let box_ptr_v = Load(cx, box_cell_v); - do with_cond(cx, IsNotNull(cx, box_ptr_v)) |bcx| { + with_cond(cx, IsNotNull(cx, box_ptr_v), |bcx| { let closure_ty = ty::mk_opaque_closure_ptr(tcx, sigil); glue_fn(bcx, box_cell_v, closure_ty) - } + }) } } } @@ -481,7 +481,7 @@ pub fn make_opaque_cbox_free_glue( } let ccx = bcx.ccx(); - do with_cond(bcx, IsNotNull(bcx, cbox)) |bcx| { + with_cond(bcx, IsNotNull(bcx, cbox), |bcx| { // Load the type descr found in the cbox let lltydescty = ccx.tydesc_type.ptr_to(); let cbox = Load(bcx, cbox); @@ -498,5 +498,5 @@ pub fn make_opaque_cbox_free_glue( glue::trans_exchange_free(bcx, cbox); bcx - } + }) } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 48602534a3d89..7b2e439f2d253 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -453,14 +453,14 @@ pub fn add_clean(bcx: @mut Block, val: ValueRef, t: ty::t) { debug!("add_clean({}, {}, {})", bcx.to_str(), bcx.val_to_str(val), t.repr(bcx.tcx())); let cleanup_type = cleanup_type(bcx.tcx(), t); - do in_scope_cx(bcx, None) |scope_info| { + in_scope_cx(bcx, None, |scope_info| { scope_info.cleanups.push(clean(@TypeDroppingCleanupFunction { val: val, t: t, } as @CleanupFunction, cleanup_type)); grow_scope_clean(scope_info); - } + }) } pub fn add_clean_temp_immediate(cx: @mut Block, val: ValueRef, ty: ty::t) { @@ -469,7 +469,7 @@ pub fn add_clean_temp_immediate(cx: @mut Block, val: ValueRef, ty: ty::t) { cx.to_str(), cx.val_to_str(val), ty.repr(cx.tcx())); let cleanup_type = cleanup_type(cx.tcx(), ty); - do in_scope_cx(cx, None) |scope_info| { + in_scope_cx(cx, None, |scope_info| { scope_info.cleanups.push(clean_temp(val, @ImmediateTypeDroppingCleanupFunction { val: val, @@ -477,7 +477,7 @@ pub fn add_clean_temp_immediate(cx: @mut Block, val: ValueRef, ty: ty::t) { } as @CleanupFunction, cleanup_type)); grow_scope_clean(scope_info); - } + }) } pub fn add_clean_temp_mem(bcx: @mut Block, val: ValueRef, t: ty::t) { @@ -498,7 +498,7 @@ pub fn add_clean_temp_mem_in_scope_(bcx: @mut Block, scope_id: Option true, @@ -580,7 +580,7 @@ pub fn revoke_clean(cx: @mut Block, val: ValueRef) { scope_info.cleanups.len())); shrink_scope_clean(scope_info, *i); } - } + }) } pub fn block_cleanups(bcx: &mut Block) -> ~[cleanup] { @@ -844,9 +844,7 @@ pub fn C_integral(t: Type, u: u64, sign_extend: bool) -> ValueRef { pub fn C_floating(s: &str, t: Type) -> ValueRef { unsafe { - do s.with_c_str |buf| { - llvm::LLVMConstRealOfString(t.to_ref(), buf) - } + s.with_c_str(|buf| llvm::LLVMConstRealOfString(t.to_ref(), buf)) } } @@ -896,14 +894,14 @@ pub fn C_cstr(cx: &mut CrateContext, s: @str) -> ValueRef { None => () } - let sc = do s.as_imm_buf |buf, buflen| { + let sc = s.as_imm_buf(|buf, buflen| { llvm::LLVMConstStringInContext(cx.llcx, buf as *c_char, buflen as c_uint, False) - }; + }); let gsym = token::gensym("str"); - let g = do format!("str{}", gsym).with_c_str |buf| { + let g = format!("str{}", gsym).with_c_str(|buf| { llvm::LLVMAddGlobal(cx.llmod, val_ty(sc).to_ref(), buf) - }; + }); llvm::LLVMSetInitializer(g, sc); llvm::LLVMSetGlobalConstant(g, True); lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); @@ -930,9 +928,9 @@ pub fn C_binary_slice(cx: &mut CrateContext, data: &[u8]) -> ValueRef { let lldata = C_bytes(data); let gsym = token::gensym("binary"); - let g = do format!("binary{}", gsym).with_c_str |buf| { + let g = format!("binary{}", gsym).with_c_str(|buf| { llvm::LLVMAddGlobal(cx.llmod, val_ty(lldata).to_ref(), buf) - }; + }); llvm::LLVMSetInitializer(g, lldata); llvm::LLVMSetGlobalConstant(g, True); lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); @@ -954,17 +952,17 @@ pub fn C_zero_byte_arr(size: uint) -> ValueRef { pub fn C_struct(elts: &[ValueRef], packed: bool) -> ValueRef { unsafe { - do elts.as_imm_buf |ptr, len| { + elts.as_imm_buf(|ptr, len| { llvm::LLVMConstStructInContext(base::task_llcx(), ptr, len as c_uint, packed as Bool) - } + }) } } pub fn C_named_struct(T: Type, elts: &[ValueRef]) -> ValueRef { unsafe { - do elts.as_imm_buf |ptr, len| { + elts.as_imm_buf(|ptr, len| { llvm::LLVMConstNamedStruct(T.to_ref(), ptr, len as c_uint) - } + }) } } @@ -990,9 +988,9 @@ pub fn get_param(fndecl: ValueRef, param: uint) -> ValueRef { pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint]) -> ValueRef { unsafe { - let r = do us.as_imm_buf |p, len| { + let r = us.as_imm_buf(|p, len| { llvm::LLVMConstExtractValue(v, p, len as c_uint) - }; + }); debug!("const_get_elt(v={}, us={:?}, r={})", cx.tn.val_to_str(v), us, cx.tn.val_to_str(r)); @@ -1151,9 +1149,9 @@ pub fn node_id_type_params(bcx: &mut Block, id: ast::NodeId) -> ~[ty::t] { match bcx.fcx.param_substs { Some(substs) => { - do params.iter().map |t| { + params.iter().map(|t| { ty::subst_tps(tcx, substs.tys, substs.self_ty, *t) - }.collect() + }).collect() } _ => params } @@ -1207,9 +1205,9 @@ pub fn resolve_vtable_under_param_substs(tcx: ty::ctxt, typeck::vtable_static(trait_id, ref tys, sub) => { let tys = match param_substs { Some(substs) => { - do tys.iter().map |t| { + tys.iter().map(|t| { ty::subst_tps(tcx, substs.tys, substs.self_ty, *t) - }.collect() + }).collect() } _ => tys.to_owned() }; diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 06fe4717f58e1..04da76cec9e5a 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -100,9 +100,9 @@ fn const_vec(cx: @mut CrateContext, e: &ast::Expr, es: &[@ast::Expr]) -> (ValueR fn const_addr_of(cx: &mut CrateContext, cv: ValueRef) -> ValueRef { unsafe { - let gv = do "const".with_c_str |name| { + let gv = "const".with_c_str(|name| { llvm::LLVMAddGlobal(cx.llmod, val_ty(cv).to_ref(), name) - }; + }); llvm::LLVMSetInitializer(gv, cv); llvm::LLVMSetGlobalConstant(gv, True); SetLinkage(gv, PrivateLinkage); @@ -191,12 +191,12 @@ pub fn const_expr(cx: @mut CrateContext, e: &ast::Expr) -> (ValueRef, bool) { Some(@ty::AutoDerefRef(ref adj)) => { let mut ty = ety; let mut maybe_ptr = None; - do adj.autoderefs.times { + adj.autoderefs.times(|| { let (dv, dt) = const_deref(cx, llconst, ty, false); maybe_ptr = Some(llconst); llconst = dv; ty = dt; - } + }); match adj.autoref { None => { } @@ -385,10 +385,10 @@ fn const_expr_unadjusted(cx: @mut CrateContext, let bt = ty::expr_ty_adjusted(cx.tcx, base); let brepr = adt::represent_type(cx, bt); let (bv, inlineable) = const_expr(cx, base); - do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| { + expr::with_field_tys(cx.tcx, bt, None, |discr, field_tys| { let ix = ty::field_idx_strict(cx.tcx, field.name, field_tys); (adt::const_get_field(cx, brepr, bv, discr, ix), inlineable) - } + }) } ast::ExprIndex(_, base, index) => { @@ -504,8 +504,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, None => None }; - do expr::with_field_tys(tcx, ety, Some(e.id)) - |discr, field_tys| { + expr::with_field_tys(tcx, ety, Some(e.id), |discr, field_tys| { let cs = field_tys.iter().enumerate() .map(|(ix, &field_ty)| { match fs.iter().find(|f| field_ty.ident.name == f.ident.node.name) { @@ -524,7 +523,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, let (cs, inlineable) = vec::unzip(cs.move_iter()); (adt::trans_const(cx, repr, discr, cs), inlineable.iter().fold(true, |a, &b| a && b)) - } + }) } ast::ExprVec(ref es, ast::MutImmutable) => { let (v, _, inlineable) = const_vec(cx, e, *es); @@ -541,9 +540,9 @@ fn const_expr_unadjusted(cx: @mut CrateContext, ast::ExprVec(ref es, ast::MutImmutable) => { let (cv, llunitty, _) = const_vec(cx, e, *es); let llty = val_ty(cv); - let gv = do "const".with_c_str |name| { + let gv = "const".with_c_str(|name| { llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name) - }; + }); llvm::LLVMSetInitializer(gv, cv); llvm::LLVMSetGlobalConstant(gv, True); SetLinkage(gv, PrivateLinkage); diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 219307786568d..851a1233dcca7 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -131,17 +131,15 @@ impl CrateContext { unsafe { let llcx = llvm::LLVMContextCreate(); set_task_llcx(llcx); - let llmod = do name.with_c_str |buf| { + let llmod = name.with_c_str(|buf| { llvm::LLVMModuleCreateWithNameInContext(buf, llcx) - }; + }); let data_layout: &str = sess.targ_cfg.target_strs.data_layout; let targ_triple: &str = sess.targ_cfg.target_strs.target_triple; - do data_layout.with_c_str |buf| { - llvm::LLVMSetDataLayout(llmod, buf) - }; - do targ_triple.with_c_str |buf| { + data_layout.with_c_str(|buf| llvm::LLVMSetDataLayout(llmod, buf)); + targ_triple.with_c_str(|buf| { llvm::LLVMRustSetNormalizedTarget(llmod, buf) - }; + }); let targ_cfg = sess.targ_cfg; let td = mk_target_data(sess.targ_cfg.target_strs.data_layout); diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index a43b1f41a377f..1360c9c7c9ba9 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -74,11 +74,11 @@ pub fn trans_if(bcx: @mut Block, None => {} } // if true { .. } [else { .. }] - return do with_scope(bcx, thn.info(), "if_true_then") |bcx| { + return with_scope(bcx, thn.info(), "if_true_then", |bcx| { let bcx_out = trans_block(bcx, thn, dest); debuginfo::clear_source_location(bcx.fcx); trans_block_cleanups(bcx_out, block_cleanups(bcx)) - } + }) } else { let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ; trans.visit_block(thn, ()); @@ -86,11 +86,14 @@ pub fn trans_if(bcx: @mut Block, match els { // if false { .. } else { .. } Some(elexpr) => { - return do with_scope(bcx, elexpr.info(), "if_false_then") |bcx| { + return with_scope(bcx, + elexpr.info(), + "if_false_then", + |bcx| { let bcx_out = trans_if_else(bcx, elexpr, dest); debuginfo::clear_source_location(bcx.fcx); trans_block_cleanups(bcx_out, block_cleanups(bcx)) - } + }) } // if false { .. } None => return bcx, diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 1806dee6c8f20..4fd6e08c8b584 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -290,9 +290,9 @@ impl Datum { ByRef(_) => { let cast = PointerCast(bcx, dst, val_ty(self.val)); let cmp = ICmp(bcx, lib::llvm::IntNE, cast, self.val); - do with_cond(bcx, cmp) |bcx| { + with_cond(bcx, cmp, |bcx| { self.copy_to_no_check(bcx, action, dst) - } + }) } ByValue => { self.copy_to_no_check(bcx, action, dst) diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 676af30b2eeba..caed9fb8e9c74 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -254,8 +254,7 @@ pub fn create_local_var_metadata(bcx: @mut Block, let cx = bcx.ccx(); let def_map = cx.tcx.def_map; - do pat_util::pat_bindings(def_map, local.pat) |_, node_id, span, path_ref| { - + pat_util::pat_bindings(def_map, local.pat, |_, node_id, span, path_ref| { let var_ident = ast_util::path_to_ident(path_ref); let var_type = node_id_type(bcx, node_id); @@ -276,7 +275,7 @@ pub fn create_local_var_metadata(bcx: @mut Block, DirectVariable { alloca: llptr }, LocalVariable, span); - } + }) } /// Creates debug information for a variable captured in a closure. @@ -449,8 +448,7 @@ pub fn create_argument_metadata(bcx: @mut Block, let def_map = cx.tcx.def_map; let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata; - do pat_util::pat_bindings(def_map, arg.pat) |_, node_id, span, path_ref| { - + pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| { let llptr = match bcx.fcx.llargs.find_copy(&node_id) { Some(v) => v, None => { @@ -481,7 +479,7 @@ pub fn create_argument_metadata(bcx: @mut Block, DirectVariable { alloca: llptr }, ArgumentVariable(argument_index), span); - } + }) } /// Sets the current debug location at the beginning of the span. @@ -655,27 +653,28 @@ pub fn create_function_debug_context(cx: &mut CrateContext, let scope_line = get_scope_line(cx, top_level_block, loc.line); - let fn_metadata = do function_name.with_c_str |function_name| { - do linkage_name.with_c_str |linkage_name| { - unsafe { - llvm::LLVMDIBuilderCreateFunction( - DIB(cx), - containing_scope, - function_name, - linkage_name, - file_metadata, - loc.line as c_uint, - function_type_metadata, - false, - true, - scope_line as c_uint, - FlagPrototyped as c_uint, - cx.sess.opts.optimize != session::No, - llfn, - template_parameters, - ptr::null()) - } - }}; + let fn_metadata = function_name.with_c_str(|function_name| { + linkage_name.with_c_str(|linkage_name| { + unsafe { + llvm::LLVMDIBuilderCreateFunction( + DIB(cx), + containing_scope, + function_name, + linkage_name, + file_metadata, + loc.line as c_uint, + function_type_metadata, + false, + true, + scope_line as c_uint, + FlagPrototyped as c_uint, + cx.sess.opts.optimize != session::No, + llfn, + template_parameters, + ptr::null()) + } + }) + }); // Initialize fn debug context (including scope map and namespace map) let mut fn_debug_context = ~FunctionDebugContextData { @@ -685,7 +684,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, source_locations_enabled: false, }; - let arg_pats = do fn_decl.inputs.map |arg_ref| { arg_ref.pat }; + let arg_pats = fn_decl.inputs.map(|arg_ref| arg_ref.pat); populate_scope_map(cx, arg_pats, top_level_block, fn_metadata, &mut fn_debug_context.scope_map); return FunctionDebugContext(fn_debug_context); @@ -780,7 +779,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, let ident = special_idents::type_self; - let param_metadata = do token::ident_to_str(&ident).with_c_str |name| { + let param_metadata = token::ident_to_str(&ident).with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreateTemplateTypeParameter( DIB(cx), @@ -791,7 +790,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, 0, 0) } - }; + }); template_params.push(param_metadata); } @@ -818,7 +817,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, // Again, only create type information if extra_debuginfo is enabled if cx.sess.opts.extra_debuginfo { let actual_type_metadata = type_metadata(cx, actual_type, codemap::dummy_sp()); - let param_metadata = do token::ident_to_str(&ident).with_c_str |name| { + let param_metadata = token::ident_to_str(&ident).with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreateTemplateTypeParameter( DIB(cx), @@ -829,7 +828,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, 0, 0) } - }; + }); template_params.push(param_metadata); } } @@ -875,24 +874,28 @@ fn compile_unit_metadata(cx: @mut CrateContext) { let work_dir = cx.sess.working_dir.as_str().unwrap(); let producer = format!("rustc version {}", env!("CFG_VERSION")); - do crate_name.with_c_str |crate_name| { - do work_dir.with_c_str |work_dir| { - do producer.with_c_str |producer| { - do "".with_c_str |flags| { - do "".with_c_str |split_name| { - unsafe { - llvm::LLVMDIBuilderCreateCompileUnit( - dcx.builder, - DW_LANG_RUST, - crate_name, - work_dir, - producer, - cx.sess.opts.optimize != session::No, - flags, - 0, - split_name); - } - }}}}}; + crate_name.with_c_str(|crate_name| { + work_dir.with_c_str(|work_dir| { + producer.with_c_str(|producer| { + "".with_c_str(|flags| { + "".with_c_str(|split_name| { + unsafe { + llvm::LLVMDIBuilderCreateCompileUnit( + dcx.builder, + DW_LANG_RUST, + crate_name, + work_dir, + producer, + cx.sess.opts.optimize != session::No, + flags, + 0, + split_name); + } + }) + }) + }) + }) + }); } fn declare_local(bcx: @mut Block, @@ -917,7 +920,7 @@ fn declare_local(bcx: @mut Block, CapturedVariable => 0 } as c_uint; - let (var_alloca, var_metadata) = do name.with_c_str |name| { + let (var_alloca, var_metadata) = name.with_c_str(|name| { match variable_access { DirectVariable { alloca } => ( alloca, @@ -952,7 +955,7 @@ fn declare_local(bcx: @mut Block, } ) } - }; + }); set_debug_location(cx, DebugLocation::new(scope_metadata, loc.line, *loc.col)); unsafe { @@ -992,12 +995,13 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile { }; let file_metadata = - do file_name.with_c_str |file_name| { - do work_dir.with_c_str |work_dir| { - unsafe { - llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name, work_dir) - } - }}; + file_name.with_c_str(|file_name| { + work_dir.with_c_str(|work_dir| { + unsafe { + llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name, work_dir) + } + }) + }); debug_context(cx).created_files.insert(full_path.to_owned(), file_metadata); return file_metadata; @@ -1053,7 +1057,7 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { let llvm_type = type_of::type_of(cx, t); let (size, align) = size_and_align_of(cx, llvm_type); - let ty_metadata = do name.with_c_str |name| { + let ty_metadata = name.with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreateBasicType( DIB(cx), @@ -1062,7 +1066,7 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { bytes_to_bits(align), encoding) } - }; + }); return ty_metadata; } @@ -1074,7 +1078,7 @@ fn pointer_type_metadata(cx: &mut CrateContext, let pointer_llvm_type = type_of::type_of(cx, pointer_type); let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type); let name = ppaux::ty_to_str(cx.tcx, pointer_type); - let ptr_metadata = do name.with_c_str |name| { + let ptr_metadata = name.with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreatePointerType( DIB(cx), @@ -1083,7 +1087,7 @@ fn pointer_type_metadata(cx: &mut CrateContext, bytes_to_bits(pointer_align), name) } - }; + }); return ptr_metadata; } @@ -1100,7 +1104,7 @@ struct StructMemberDescriptionFactory { impl MemberDescriptionFactory for StructMemberDescriptionFactory { fn create_member_descriptions(&self, cx: &mut CrateContext) -> ~[MemberDescription] { - do self.fields.map |field| { + self.fields.map(|field| { let name = if field.ident.name == special_idents::unnamed_field.name { @"" } else { @@ -1113,7 +1117,7 @@ impl MemberDescriptionFactory for StructMemberDescriptionFactory { type_metadata: type_metadata(cx, field.mt.ty, self.span), offset: ComputedMemberOffset, } - } + }) } } @@ -1210,14 +1214,14 @@ struct TupleMemberDescriptionFactory { impl MemberDescriptionFactory for TupleMemberDescriptionFactory { fn create_member_descriptions(&self, cx: &mut CrateContext) -> ~[MemberDescription] { - do self.component_types.map |&component_type| { + self.component_types.map(|&component_type| { MemberDescription { name: @"", llvm_type: type_of::type_of(cx, component_type), type_metadata: type_metadata(cx, component_type, self.span), offset: ComputedMemberOffset, } - } + }) } } @@ -1267,10 +1271,10 @@ impl MemberDescriptionFactory for GeneralMemberDescriptionFactory { _ => cx.sess.bug("unreachable") }; - do struct_defs + struct_defs .iter() .enumerate() - .map |(i, struct_def)| { + .map(|(i, struct_def)| { let (variant_type_metadata, variant_llvm_type, member_desc_factory) = describe_variant(cx, struct_def, @@ -1295,7 +1299,7 @@ impl MemberDescriptionFactory for GeneralMemberDescriptionFactory { type_metadata: variant_type_metadata, offset: FixedMemberOffset { bytes: 0 }, } - }.collect() + }).collect() } } @@ -1308,7 +1312,7 @@ struct EnumVariantMemberDescriptionFactory { impl MemberDescriptionFactory for EnumVariantMemberDescriptionFactory { fn create_member_descriptions(&self, cx: &mut CrateContext) -> ~[MemberDescription] { - do self.args.iter().enumerate().map |(i, &(name, ty))| { + self.args.iter().enumerate().map(|(i, &(name, ty))| { MemberDescription { name: name, llvm_type: type_of::type_of(cx, ty), @@ -1318,7 +1322,7 @@ impl MemberDescriptionFactory for EnumVariantMemberDescriptionFactory { }, offset: ComputedMemberOffset, } - }.collect() + }).collect() } } @@ -1360,8 +1364,8 @@ fn describe_variant(cx: &mut CrateContext, // Get the argument names from the enum variant info let mut arg_names = match variant_info.arg_names { - Some(ref names) => do names.map |ident| { token::ident_to_str(ident) }, - None => do variant_info.args.map |_| { @"" } + Some(ref names) => names.map(|ident| token::ident_to_str(ident)), + None => variant_info.args.map(|_| @"") }; // If this is not a univariant enum, there is also the (unnamed) discriminant field @@ -1420,14 +1424,14 @@ fn prepare_enum_metadata(cx: &mut CrateContext, let name: &str = token::ident_to_str(&v.name); let discriminant_value = v.disr_val as c_ulonglong; - do name.with_c_str |name| { + name.with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreateEnumerator( DIB(cx), name, discriminant_value) } - } + }) }) .collect(); @@ -1436,7 +1440,7 @@ fn prepare_enum_metadata(cx: &mut CrateContext, let (discriminant_size, discriminant_align) = size_and_align_of(cx, discriminant_llvm_type); let discriminant_base_type_metadata = type_metadata(cx, adt::ty_of_inttype(inttype), codemap::dummy_sp()); - do enum_name.with_c_str |enum_name| { + enum_name.with_c_str(|enum_name| { unsafe { llvm::LLVMDIBuilderCreateEnumerationType( DIB(cx), @@ -1449,7 +1453,7 @@ fn prepare_enum_metadata(cx: &mut CrateContext, create_DIArray(DIB(cx), enumerators_metadata), discriminant_base_type_metadata) } - } + }) }; let type_rep = adt::represent_type(cx, enum_type); @@ -1482,7 +1486,7 @@ fn prepare_enum_metadata(cx: &mut CrateContext, let enum_llvm_type = type_of::type_of(cx, enum_type); let (enum_type_size, enum_type_align) = size_and_align_of(cx, enum_llvm_type); - let enum_metadata = do enum_name.with_c_str |enum_name| { + let enum_metadata = enum_name.with_c_str(|enum_name| { unsafe { llvm::LLVMDIBuilderCreateUnionType( DIB(cx), @@ -1495,7 +1499,8 @@ fn prepare_enum_metadata(cx: &mut CrateContext, 0, // Flags ptr::null(), 0) // RuntimeLang - }}; + } + }); UnfinishedMetadata { cache_id: cache_id_for_type(enum_type), @@ -1605,7 +1610,7 @@ fn set_members_of_composite_type(cx: &mut CrateContext, ComputedMemberOffset => machine::llelement_offset(cx, composite_llvm_type, i) }; - do member_description.name.with_c_str |member_name| { + member_description.name.with_c_str(|member_name| { unsafe { llvm::LLVMDIBuilderCreateMemberType( DIB(cx), @@ -1619,7 +1624,7 @@ fn set_members_of_composite_type(cx: &mut CrateContext, 0, member_description.type_metadata) } - } + }) }) .collect(); @@ -1649,27 +1654,29 @@ fn create_struct_stub(cx: &mut CrateContext, }; return unsafe { - do struct_type_name.with_c_str |name| { - do unique_id.with_c_str |unique_id| { - // LLVMDIBuilderCreateStructType() wants an empty array. A null pointer will lead to - // hard to trace and debug LLVM assertions later on in llvm/lib/IR/Value.cpp - let empty_array = create_DIArray(DIB(cx), []); + struct_type_name.with_c_str(|name| { + unique_id.with_c_str(|unique_id| { + // LLVMDIBuilderCreateStructType() wants an empty array. A null pointer will lead to + // hard to trace and debug LLVM assertions later on in llvm/lib/IR/Value.cpp + let empty_array = create_DIArray(DIB(cx), []); - llvm::LLVMDIBuilderCreateStructType( - DIB(cx), - containing_scope, - name, - file_metadata, - loc.line as c_uint, - bytes_to_bits(struct_size), - bytes_to_bits(struct_align), - 0, - ptr::null(), - empty_array, - 0, - ptr::null(), - unique_id) - }}}; + llvm::LLVMDIBuilderCreateStructType( + DIB(cx), + containing_scope, + name, + file_metadata, + loc.line as c_uint, + bytes_to_bits(struct_size), + bytes_to_bits(struct_align), + 0, + ptr::null(), + empty_array, + 0, + ptr::null(), + unique_id) + }) + }) + }; } fn boxed_type_metadata(cx: &mut CrateContext, @@ -1979,7 +1986,7 @@ fn unimplemented_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { debug!("unimplemented_type_metadata: {:?}", ty::get(t)); let name = ppaux::ty_to_str(cx.tcx, t); - let metadata = do format!("NYI<{}>", name).with_c_str |name| { + let metadata = format!("NYI<{}>", name).with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreateBasicType( DIB(cx), @@ -1988,7 +1995,7 @@ fn unimplemented_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { 8_u64, DW_ATE_unsigned as c_uint) } - }; + }); return metadata; } @@ -2261,10 +2268,10 @@ fn populate_scope_map(cx: &mut CrateContext, // Push argument identifiers onto the stack so arguments integrate nicely with variable // shadowing. for &arg_pat in arg_pats.iter() { - do pat_util::pat_bindings(def_map, arg_pat) |_, _, _, path_ref| { + pat_util::pat_bindings(def_map, arg_pat, |_, _, _, path_ref| { let ident = ast_util::path_to_ident(path_ref); scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata, ident: Some(ident) }); - } + }) } walk_block(cx, fn_entry_block, &mut scope_stack, scope_map); @@ -2550,11 +2557,13 @@ fn populate_scope_map(cx: &mut CrateContext, ast::ExprIf(@ref cond_exp, ref then_block, ref opt_else_exp) => { walk_expr(cx, cond_exp, scope_stack, scope_map); - do with_new_scope(cx, then_block.span, scope_stack, scope_map) |cx, - scope_stack, - scope_map| { + with_new_scope(cx, + then_block.span, + scope_stack, + scope_map, + |cx, scope_stack, scope_map| { walk_block(cx, then_block, scope_stack, scope_map); - } + }); match *opt_else_exp { Some(@ref else_exp) => walk_expr(cx, else_exp, scope_stack, scope_map), @@ -2565,11 +2574,13 @@ fn populate_scope_map(cx: &mut CrateContext, ast::ExprWhile(@ref cond_exp, ref loop_body) => { walk_expr(cx, cond_exp, scope_stack, scope_map); - do with_new_scope(cx, loop_body.span, scope_stack, scope_map) |cx, - scope_stack, - scope_map| { + with_new_scope(cx, + loop_body.span, + scope_stack, + scope_map, + |cx, scope_stack, scope_map| { walk_block(cx, loop_body, scope_stack, scope_map); - } + }) } ast::ExprForLoop(_, _, _, _) => { @@ -2584,24 +2595,28 @@ fn populate_scope_map(cx: &mut CrateContext, ast::ExprLoop(ref block, _) | ast::ExprBlock(ref block) => { - do with_new_scope(cx, block.span, scope_stack, scope_map) |cx, - scope_stack, - scope_map| { + with_new_scope(cx, + block.span, + scope_stack, + scope_map, + |cx, scope_stack, scope_map| { walk_block(cx, block, scope_stack, scope_map); - } + }) } ast::ExprFnBlock(ast::fn_decl { inputs: ref inputs, _ }, ref block) | ast::ExprProc(ast::fn_decl { inputs: ref inputs, _ }, ref block) => { - do with_new_scope(cx, block.span, scope_stack, scope_map) |cx, - scope_stack, - scope_map| { + with_new_scope(cx, + block.span, + scope_stack, + scope_map, + |cx, scope_stack, scope_map| { for &ast::arg { pat: pattern, _ } in inputs.iter() { walk_pattern(cx, pattern, scope_stack, scope_map); } walk_block(cx, block, scope_stack, scope_map); - } + }) } // ast::expr_loop_body(@ref inner_exp) | @@ -2646,9 +2661,11 @@ fn populate_scope_map(cx: &mut CrateContext, for arm_ref in arms.iter() { let arm_span = arm_ref.pats[0].span; - do with_new_scope(cx, arm_span, scope_stack, scope_map) |cx, - scope_stack, - scope_map| { + with_new_scope(cx, + arm_span, + scope_stack, + scope_map, + |cx, scope_stack, scope_map| { for &pat in arm_ref.pats.iter() { walk_pattern(cx, pat, scope_stack, scope_map); } @@ -2658,7 +2675,7 @@ fn populate_scope_map(cx: &mut CrateContext, } walk_block(cx, &arm_ref.body, scope_stack, scope_map); - } + }) } } @@ -2769,14 +2786,14 @@ fn namespace_for_item(cx: &mut CrateContext, let namespace_name = token::ident_to_str(&ident); let namespace_metadata = unsafe { - do namespace_name.with_c_str |namespace_name| { + namespace_name.with_c_str(|namespace_name| { llvm::LLVMDIBuilderCreateNameSpace( DIB(cx), parent_scope, namespace_name, ptr::null(), // cannot reconstruct file ... 0) // ... or line information, but that's not so important. - } + }) }; let node = @NamespaceTreeNode { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 9d8b539bac83b..4d69c95d281b2 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -693,10 +693,12 @@ fn trans_rvalue_dps_unadjusted(bcx: @mut Block, expr: &ast::Expr, return _match::trans_match(bcx, expr, discr, *arms, dest); } ast::ExprBlock(ref blk) => { - return do base::with_scope(bcx, blk.info(), - "block-expr body") |bcx| { + return base::with_scope(bcx, + blk.info(), + "block-expr body", + |bcx| { controlflow::trans_block(bcx, blk, dest) - }; + }); } ast::ExprStruct(_, ref fields, base) => { return trans_rec_or_struct(bcx, (*fields), base, expr.span, expr.id, dest); @@ -930,17 +932,18 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock { let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base)); let repr = adt::represent_type(bcx.ccx(), base_datum.ty); - do with_field_tys(bcx.tcx(), base_datum.ty, None) |discr, field_tys| { + with_field_tys(bcx.tcx(), base_datum.ty, None, |discr, field_tys| { let ix = ty::field_idx_strict(bcx.tcx(), field.name, field_tys); DatumBlock { - datum: do base_datum.get_element(bcx, - field_tys[ix].mt.ty, - ZeroMem) |srcval| { + datum: base_datum.get_element(bcx, + field_tys[ix].mt.ty, + ZeroMem, + |srcval| { adt::trans_field_ptr(bcx, repr, srcval, discr, ix) - }, + }), bcx: bcx } - } + }) } fn trans_index(bcx: @mut Block, @@ -984,9 +987,9 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock { let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len); let expect = ccx.intrinsics.get_copy(&("llvm.expect.i1")); let expected = Call(bcx, expect, [bounds_check, C_i1(false)], []); - let bcx = do with_cond(bcx, expected) |bcx| { + let bcx = with_cond(bcx, expected, |bcx| { controlflow::trans_fail_bounds_check(bcx, index_expr.span, ix_val, len) - }; + }); let elt = InBoundsGEP(bcx, base, [ix_val]); let elt = PointerCast(bcx, elt, vt.llunit_ty.ptr_to()); return DatumBlock { @@ -1044,11 +1047,11 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock { let symbol = csearch::get_symbol( bcx.ccx().sess.cstore, did); - let llval = do symbol.with_c_str |buf| { + let llval = symbol.with_c_str(|buf| { llvm::LLVMAddGlobal(bcx.ccx().llmod, llty.to_ref(), buf) - }; + }); let extern_const_values = &mut bcx.ccx().extern_const_values; extern_const_values.insert(did, llval); llval @@ -1208,10 +1211,10 @@ fn trans_rec_or_struct(bcx: @mut Block, let ty = node_id_type(bcx, id); let tcx = bcx.tcx(); - do with_field_tys(tcx, ty, Some(id)) |discr, field_tys| { + with_field_tys(tcx, ty, Some(id), |discr, field_tys| { let mut need_base = vec::from_elem(field_tys.len(), true); - let numbered_fields = do fields.map |field| { + let numbered_fields = fields.map(|field| { let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident.name == field.ident.node.name); @@ -1225,7 +1228,7 @@ fn trans_rec_or_struct(bcx: @mut Block, "Couldn't find field in struct type") } } - }; + }); let optbase = match base { Some(base_expr) => { let mut leftovers = ~[]; @@ -1247,7 +1250,7 @@ fn trans_rec_or_struct(bcx: @mut Block, let repr = adt::represent_type(bcx.ccx(), ty); trans_adt(bcx, repr, discr, numbered_fields, optbase, dest) - } + }) } /** @@ -1308,9 +1311,9 @@ fn trans_adt(bcx: @mut Block, repr: &adt::Repr, discr: ty::Disr, // And, would it ever be reasonable to be here with discr != 0? let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr)); for &(i, t) in base.fields.iter() { - let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| { + let datum = base_datum.get_element(bcx, t, ZeroMem, |srcval| { adt::trans_field_ptr(bcx, repr, srcval, discr, i) - }; + }); let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i); bcx = datum.store_to(bcx, INIT, dest); } @@ -1541,9 +1544,9 @@ fn trans_lazy_binop(bcx: @mut Block, let bcx = bcx; let Result {bcx: past_lhs, val: lhs} = { - do base::with_scope_result(bcx, a.info(), "lhs") |bcx| { + base::with_scope_result(bcx, a.info(), "lhs", |bcx| { trans_to_datum(bcx, a).to_result() - } + }) }; if past_lhs.unreachable { @@ -1560,9 +1563,9 @@ fn trans_lazy_binop(bcx: @mut Block, } let Result {bcx: past_rhs, val: rhs} = { - do base::with_scope_result(before_rhs, b.info(), "rhs") |bcx| { + base::with_scope_result(before_rhs, b.info(), "rhs", |bcx| { trans_to_datum(bcx, b).to_result() - } + }) }; if past_rhs.unreachable { @@ -1830,9 +1833,9 @@ pub fn trans_log_level(bcx: @mut Block) -> DatumBlock { ccx, modpath, "loglevel"); let global; unsafe { - global = do s.with_c_str |buf| { + global = s.with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf) - }; + }); llvm::LLVMSetGlobalConstant(global, False); llvm::LLVMSetInitializer(global, C_null(Type::i32())); lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage); diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index d73345b84742c..7426833070200 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -647,11 +647,11 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext, } // Perform the call itself - let llrust_ret_val = do llrust_args.as_imm_buf |ptr, len| { + let llrust_ret_val = llrust_args.as_imm_buf(|ptr, len| { debug!("calling llrustfn = {}", ccx.tn.val_to_str(llrustfn)); llvm::LLVMBuildCall(builder, llrustfn, ptr, len as c_uint, noname()) - }; + }); // Get the return value where the foreign fn expects it. let llforeign_ret_ty = match tys.fn_ty.ret_ty.cast { diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 3eef1267429c7..70d983a01fa4f 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -336,7 +336,7 @@ pub fn call_tydesc_glue(cx: @mut Block, v: ValueRef, t: ty::t, field: uint) pub fn make_visit_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block { let _icx = push_ctxt("make_visit_glue"); - do with_scope(bcx, None, "visitor cleanup") |bcx| { + with_scope(bcx, None, "visitor cleanup", |bcx| { let mut bcx = bcx; let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(), ty::ReStatic) { @@ -350,7 +350,7 @@ pub fn make_visit_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block { // The visitor is a boxed object and needs to be dropped add_clean(bcx, v, object_ty); bcx - } + }) } pub fn make_free_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block { @@ -394,9 +394,9 @@ pub fn trans_struct_drop_flag(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: class_did: ast::DefId, substs: &ty::substs) -> @mut Block { let repr = adt::represent_type(bcx.ccx(), t); let drop_flag = adt::trans_drop_flag_ptr(bcx, repr, v0); - do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| { + with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag)), |cx| { trans_struct_drop(cx, t, v0, dtor_did, class_did, substs) - } + }) } pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast::DefId, @@ -420,7 +420,7 @@ pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast: // Be sure to put all of the fields into a scope so we can use an invoke // instruction to call the user destructor but still call the field // destructors if the user destructor fails. - do with_scope(bcx, None, "field drops") |bcx| { + with_scope(bcx, None, "field drops", |bcx| { let self_arg = PointerCast(bcx, v0, params[0]); let args = ~[self_arg]; @@ -434,7 +434,7 @@ pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast: let (_, bcx) = invoke(bcx, dtor_addr, args, []); bcx - } + }) } pub fn make_drop_glue(bcx: @mut Block, v0: ValueRef, t: ty::t) -> @mut Block { @@ -480,7 +480,7 @@ pub fn make_drop_glue(bcx: @mut Block, v0: ValueRef, t: ty::t) -> @mut Block { ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => { let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]); // Only drop the value when it is non-null - do with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue))) |bcx| { + with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| { let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable])); // Cast the vtable to a pointer to a pointer to a tydesc. @@ -493,7 +493,7 @@ pub fn make_drop_glue(bcx: @mut Block, v0: ValueRef, t: ty::t) -> @mut Block { abi::tydesc_field_free_glue, None); bcx - } + }) } ty::ty_opaque_closure_ptr(ck) => { closure::make_opaque_cbox_drop_glue(bcx, ck, v0) @@ -618,11 +618,11 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed(); note_unique_llvm_symbol(ccx, name); debug!("+++ declare_tydesc {} {}", ppaux::ty_to_str(ccx.tcx, t), name); - let gvar = do name.with_c_str |buf| { + let gvar = name.with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf) } - }; + }); let ty_name = C_estr_slice(ccx, ppaux::ty_to_str(ccx.tcx, t).to_managed()); diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 61384c72efa25..71d2204b94f35 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -545,14 +545,14 @@ pub fn get_vtable(bcx: @mut Block, } // Not in the cache. Actually build it. - let methods = do origins.flat_map |origin| { + let methods = origins.flat_map(|origin| { match *origin { typeck::vtable_static(id, ref substs, sub_vtables) => { emit_vtable_methods(bcx, id, *substs, sub_vtables) } _ => ccx.sess.bug("get_vtable: expected a static origin"), } - }; + }); // Generate a type descriptor for the vtable. let tydesc = get_tydesc(ccx, self_ty); @@ -578,9 +578,9 @@ pub fn make_vtable(ccx: &mut CrateContext, let tbl = C_struct(components, false); let sym = token::gensym("vtable"); - let vt_gvar = do format!("vtable{}", sym).with_c_str |buf| { + let vt_gvar = format!("vtable{}", sym).with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf) - }; + }); llvm::LLVMSetInitializer(vt_gvar, tbl); llvm::LLVMSetGlobalConstant(vt_gvar, lib::llvm::True); lib::llvm::SetLinkage(vt_gvar, lib::llvm::InternalLinkage); @@ -605,7 +605,7 @@ fn emit_vtable_methods(bcx: @mut Block, ty::populate_implementations_for_trait_if_necessary(bcx.tcx(), trt_id); let trait_method_def_ids = ty::trait_method_def_ids(tcx, trt_id); - do trait_method_def_ids.map |method_def_id| { + trait_method_def_ids.map(|method_def_id| { let ident = ty::method(tcx, *method_def_id).ident; // The substitutions we have are on the impl, so we grab // the method type from the impl to substitute into. @@ -626,7 +626,7 @@ fn emit_vtable_methods(bcx: @mut Block, trans_fn_ref_with_vtables(bcx, m_id, 0, substs, Some(vtables)).llfn } - } + }) } pub fn trans_trait_cast(bcx: @mut Block, diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index b1dc17a123998..ccfe0d6e97949 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -213,12 +213,12 @@ impl Reflector { ty::ty_tup(ref tys) => { let extra = ~[self.c_uint(tys.len())] + self.c_size_and_align(t); - do self.bracketed("tup", extra) |this| { + self.bracketed("tup", extra, |this| { for (i, t) in tys.iter().enumerate() { let extra = ~[this.c_uint(i), this.c_tydesc(*t)]; this.visit("tup_field", extra); } - } + }) } // FIXME (#2594): fetch constants out of intrinsic @@ -262,7 +262,7 @@ impl Reflector { let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()), self.c_bool(named_fields), self.c_uint(fields.len())] + self.c_size_and_align(t); - do self.bracketed("class", extra) |this| { + self.bracketed("class", extra, |this| { for (i, field) in fields.iter().enumerate() { let extra = ~[this.c_uint(i), this.c_slice(bcx.ccx().sess.str_of(field.ident)), @@ -270,7 +270,7 @@ impl Reflector { + this.c_mt(&field.mt); this.visit("class_field", extra); } - } + }) } // FIXME (#2595): visiting all the variants in turn is probably @@ -320,14 +320,14 @@ impl Reflector { let enum_args = ~[self.c_uint(variants.len()), make_get_disr()] + self.c_size_and_align(t); - do self.bracketed("enum", enum_args) |this| { + self.bracketed("enum", enum_args, |this| { for (i, v) in variants.iter().enumerate() { let name = ccx.sess.str_of(v.name); let variant_args = ~[this.c_uint(i), C_u64(v.disr_val), this.c_uint(v.args.len()), this.c_slice(name)]; - do this.bracketed("enum_variant", variant_args) |this| { + this.bracketed("enum_variant", variant_args, |this| { for (j, a) in v.args.iter().enumerate() { let bcx = this.bcx; let null = C_null(llptrty); @@ -338,9 +338,9 @@ impl Reflector { this.c_tydesc(*a)]; this.visit("enum_variant_field", field_args); } - } + }) } - } + }) } ty::ty_trait(_, _, _, _, _) => { diff --git a/src/librustc/middle/trans/uniq.rs b/src/librustc/middle/trans/uniq.rs index 8ff270e236fa5..18b45fb461381 100644 --- a/src/librustc/middle/trans/uniq.rs +++ b/src/librustc/middle/trans/uniq.rs @@ -23,7 +23,7 @@ pub fn make_free_glue(bcx: @mut Block, vptrptr: ValueRef, box_ty: ty::t) let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty); let not_null = IsNotNull(bcx, box_datum.val); - do with_cond(bcx, not_null) |bcx| { + with_cond(bcx, not_null, |bcx| { let body_datum = box_datum.box_body(bcx); let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx), body_datum.ty); @@ -32,5 +32,5 @@ pub fn make_free_glue(bcx: @mut Block, vptrptr: ValueRef, box_ty: ty::t) } else { glue::trans_exchange_free(bcx, box_datum.val) } - } + }) } diff --git a/src/librustc/middle/trans/value.rs b/src/librustc/middle/trans/value.rs index 7def799742dcd..59bc397a55884 100644 --- a/src/librustc/middle/trans/value.rs +++ b/src/librustc/middle/trans/value.rs @@ -52,7 +52,7 @@ impl Value { pub fn get_dominating_store(self, bcx: &mut Block) -> Option { match self.get_single_user().and_then(|user| user.as_store_inst()) { Some(store) => { - do store.get_parent().and_then |store_bb| { + store.get_parent().and_then(|store_bb| { let mut bb = BasicBlock(bcx.llbb); let mut ret = Some(store); while *bb != *store_bb { @@ -62,7 +62,7 @@ impl Value { } } ret - } + }) } _ => None } @@ -150,8 +150,8 @@ impl Iterator for UserIterator { fn next(&mut self) -> Option { let current = self.next; - self.next = do current.and_then |u| { u.get_next_use() }; + self.next = current.and_then(|u| u.get_next_use()); - do current.map |u| { u.get_user() } + current.map(|u| u.get_user()) } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index fefed79577958..00487830490e7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1684,7 +1684,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, let mut encountered_box = encountered_box; let mut needs_unwind_cleanup = false; - do maybe_walk_ty(ty) |ty| { + maybe_walk_ty(ty, |ty| { let old_encountered_box = encountered_box; let result = match get(ty).sty { ty_box(_) | ty_opaque_box => { @@ -1729,7 +1729,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, encountered_box = old_encountered_box; result - } + }); return needs_unwind_cleanup; } @@ -2207,14 +2207,14 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { -> TypeContents { let _i = indenter(); let mut tc = TC::All; - do each_inherited_builtin_bound(cx, bounds, traits) |bound| { + each_inherited_builtin_bound(cx, bounds, traits, |bound| { tc = tc - match bound { BoundStatic => TC::Nonstatic, BoundSend => TC::Nonsendable, BoundFreeze => TC::Nonfreezable, BoundSized => TC::Nonsized, }; - } + }); return tc; // Iterates over all builtin bounds on the type parameter def, including @@ -2227,13 +2227,13 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { f(bound); } - do each_bound_trait_and_supertraits(cx, traits) |trait_ref| { + each_bound_trait_and_supertraits(cx, traits, |trait_ref| { let trait_def = lookup_trait_def(cx, trait_ref.def_id); for bound in trait_def.bounds.iter() { f(bound); } true - }; + }); } } } @@ -2327,12 +2327,12 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_enum(did, ref substs) => { seen.push(did); let vs = enum_variants(cx, did); - let r = !vs.is_empty() && do vs.iter().all |variant| { - do variant.args.iter().any |aty| { + let r = !vs.is_empty() && vs.iter().all(|variant| { + variant.args.iter().any(|aty| { let sty = subst(cx, substs, *aty); type_requires(cx, seen, r_ty, sty) - } - }; + }) + }); seen.pop(); r } @@ -2490,11 +2490,11 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool { ty_opaque_closure_ptr(_) => result = true, ty_struct(did, ref substs) => { let fields = lookup_struct_fields(cx, did); - result = do fields.iter().all |f| { + result = fields.iter().all(|f| { let fty = ty::lookup_item_type(cx, f.id); let sty = subst(cx, substs, fty.ty); type_is_pod(cx, sty) - }; + }); } ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) => { @@ -3000,7 +3000,7 @@ pub fn method_call_type_param_defs(tcx: ctxt, method_map: typeck::method_map, id: ast::NodeId) -> Option<@~[TypeParameterDef]> { - do method_map.find(&id).map |method| { + method_map.find(&id).map(|method| { match method.origin { typeck::method_static(did) => { // n.b.: When we encode impl methods, the bounds @@ -3026,7 +3026,7 @@ pub fn method_call_type_param_defs(tcx: ctxt, n_mth).generics.type_param_defs) } } - } + }) } pub fn resolve_expr(tcx: ctxt, expr: &ast::Expr) -> ast::Def { @@ -3217,14 +3217,14 @@ pub fn method_idx(id: ast::Ident, meths: &[@Method]) -> Option { /// to a bitset or some other representation. pub fn param_tys_in_type(ty: t) -> ~[param_ty] { let mut rslt = ~[]; - do walk_ty(ty) |ty| { + walk_ty(ty, |ty| { match get(ty).sty { ty_param(p) => { rslt.push(p); } _ => () } - } + }); rslt } @@ -3233,12 +3233,12 @@ pub fn occurs_check(tcx: ctxt, sp: Span, vid: TyVid, rt: t) { // contain duplicates. (Integral type vars aren't counted.) fn vars_in_type(ty: t) -> ~[TyVid] { let mut rslt = ~[]; - do walk_ty(ty) |ty| { + walk_ty(ty, |ty| { match get(ty).sty { ty_infer(TyVar(v)) => rslt.push(v), _ => () } - } + }); rslt } @@ -3644,9 +3644,9 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::DefId) -> Option { Some(&ast_map::node_item(item, _)) => { match item.node { ast::item_struct(struct_def, _) => { - do struct_def.ctor_id.map |ctor_id| { + struct_def.ctor_id.map(|ctor_id| { ast_util::local_def(ctor_id) - } + }) } _ => cx.sess.bug("called struct_ctor_id on non-struct") } @@ -3698,13 +3698,13 @@ impl VariantInfo { assert!(fields.len() > 0); let arg_tys = ty_fn_args(ctor_ty).map(|a| *a); - let arg_names = do fields.map |field| { + let arg_names = fields.map(|field| { match field.node.kind { named_field(ident, _) => ident, unnamed_field => cx.sess.bug( "enum_variants: all fields in struct must have a name") } - }; + }); return VariantInfo { args: arg_tys, @@ -3724,7 +3724,7 @@ pub fn substd_enum_variants(cx: ctxt, id: ast::DefId, substs: &substs) -> ~[@VariantInfo] { - do enum_variants(cx, id).iter().map |variant_info| { + enum_variants(cx, id).iter().map(|variant_info| { let substd_args = variant_info.args.iter() .map(|aty| subst(cx, substs, *aty)).collect(); @@ -3735,7 +3735,7 @@ pub fn substd_enum_variants(cx: ctxt, ctor_ty: substd_ctor_ty, ..(**variant_info).clone() } - }.collect() + }).collect() } pub fn item_path_str(cx: ctxt, id: ast::DefId) -> ~str { @@ -3967,11 +3967,11 @@ pub fn each_attr(tcx: ctxt, did: DefId, f: |@MetaItem| -> bool) -> bool { } } else { let mut cont = true; - do csearch::get_item_attrs(tcx.cstore, did) |meta_items| { + csearch::get_item_attrs(tcx.cstore, did, |meta_items| { if cont { cont = meta_items.iter().advance(|ptrptr| f(*ptrptr)); } - } + }); return cont; } } @@ -4083,7 +4083,7 @@ pub fn lookup_struct_field(cx: ctxt, } fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] { - do fields.map |field| { + fields.map(|field| { match field.node.kind { named_field(ident, visibility) => { field_ty { @@ -4101,14 +4101,14 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] { } } } - } + }) } // Returns a list of fields corresponding to the struct's items. trans uses // this. Takes a list of substs with which to instantiate field types. pub fn struct_fields(cx: ctxt, did: ast::DefId, substs: &substs) -> ~[field] { - do lookup_struct_fields(cx, did).map |f| { + lookup_struct_fields(cx, did).map(|f| { field { // FIXME #6993: change type of field to Name and get rid of new() ident: ast::Ident::new(f.name), @@ -4117,7 +4117,7 @@ pub fn struct_fields(cx: ctxt, did: ast::DefId, substs: &substs) mutbl: MutImmutable } } - } + }) } pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool { @@ -4381,27 +4381,27 @@ pub fn count_traits_and_supertraits(tcx: ctxt, type_param_defs: &[TypeParameterDef]) -> uint { let mut total = 0; for type_param_def in type_param_defs.iter() { - do each_bound_trait_and_supertraits( - tcx, type_param_def.bounds.trait_bounds) |_| { + each_bound_trait_and_supertraits( + tcx, type_param_def.bounds.trait_bounds, |_| { total += 1; true - }; + }); } return total; } pub fn get_tydesc_ty(tcx: ctxt) -> Result { - do tcx.lang_items.require(TyDescStructLangItem).map |tydesc_lang_item| { + tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| { tcx.intrinsic_defs.find_copy(&tydesc_lang_item) .expect("Failed to resolve TyDesc") - } + }) } pub fn get_opaque_ty(tcx: ctxt) -> Result { - do tcx.lang_items.require(OpaqueStructLangItem).map |opaque_lang_item| { + tcx.lang_items.require(OpaqueStructLangItem).map(|opaque_lang_item| { tcx.intrinsic_defs.find_copy(&opaque_lang_item) .expect("Failed to resolve Opaque") - } + }) } pub fn visitor_object_ty(tcx: ctxt, @@ -4460,7 +4460,7 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, return } - do csearch::each_implementation_for_type(tcx.sess.cstore, type_id) + csearch::each_implementation_for_type(tcx.sess.cstore, type_id, |implementation_def_id| { let implementation = @csearch::get_impl(tcx, implementation_def_id); @@ -4498,7 +4498,7 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, // Store the implementation info. tcx.impls.insert(implementation_def_id, implementation); - } + }); tcx.populated_external_types.insert(type_id); } @@ -4515,7 +4515,7 @@ pub fn populate_implementations_for_trait_if_necessary( return } - do csearch::each_implementation_for_trait(tcx.sess.cstore, trait_id) + csearch::each_implementation_for_trait(tcx.sess.cstore, trait_id, |implementation_def_id| { let implementation = @csearch::get_impl(tcx, implementation_def_id); @@ -4532,7 +4532,7 @@ pub fn populate_implementations_for_trait_if_necessary( // Store the implementation info. tcx.impls.insert(implementation_def_id, implementation); - } + }); tcx.populated_external_traits.insert(trait_id); } @@ -4607,9 +4607,9 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 { iter(hash, &mt.mutbl); }; fn iter(hash: &mut SipState, t: &T) { - do t.iter_bytes(true) |bytes| { hash.input(bytes); true }; + t.iter_bytes(true, |bytes| { hash.input(bytes); true }); } - do ty::walk_ty(t) |t| { + ty::walk_ty(t, |t| { match ty::get(t).sty { ty_nil => hash.input([0]), ty_bot => hash.input([1]), @@ -4714,7 +4714,7 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 { mt(&mut hash, m); } } - } + }); hash.result_u64() } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index be6fcb231889f..77dbb66fd7f58 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -635,9 +635,9 @@ fn ty_of_method_or_bare_fn( // that function type let rb = rscope::BindingRscope::new(id); - let opt_transformed_self_ty = do opt_self_info.map |self_info| { + let opt_transformed_self_ty = opt_self_info.map(|self_info| { transform_self_ty(this, &rb, self_info) - }; + }); let input_tys = decl.inputs.map(|a| ty_of_arg(this, &rb, a, None)); @@ -730,14 +730,14 @@ pub fn ty_of_closure( // that function type let rb = rscope::BindingRscope::new(id); - let input_tys = do decl.inputs.iter().enumerate().map |(i, a)| { - let expected_arg_ty = do expected_sig.as_ref().and_then |e| { + let input_tys = decl.inputs.iter().enumerate().map(|(i, a)| { + let expected_arg_ty = expected_sig.as_ref().and_then(|e| { // no guarantee that the correct number of expected args // were supplied if i < e.inputs.len() {Some(e.inputs[i])} else {None} - }; + }); ty_of_arg(this, &rb, a, expected_arg_ty) - }.collect(); + }).collect(); let expected_ret_ty = expected_sig.map(|e| e.output); let output_ty = match decl.output.node { diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 8eaf3824ff408..c7503e25684a1 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -378,14 +378,13 @@ impl<'self> LookupContext<'self> { // we find the trait the method came from, counting up the // methods from them. let mut method_count = 0; - do ty::each_bound_trait_and_supertraits(tcx, &[subtrait]) - |bound_ref| { + ty::each_bound_trait_and_supertraits(tcx, &[subtrait], |bound_ref| { if bound_ref.def_id == trait_ref.def_id { false } else { method_count += ty::trait_methods(tcx, bound_ref.def_id).len(); true } - }; + }); return method_count + n_method; } @@ -412,7 +411,7 @@ impl<'self> LookupContext<'self> { }; let trait_ref = @TraitRef { def_id: did, substs: rcvr_substs.clone() }; - do self.push_inherent_candidates_from_bounds_inner(&[trait_ref]) + self.push_inherent_candidates_from_bounds_inner(&[trait_ref], |new_trait_ref, m, method_num, _bound_num| { let vtable_index = self.get_method_index(new_trait_ref, trait_ref, method_num); @@ -436,7 +435,7 @@ impl<'self> LookupContext<'self> { real_index: vtable_index }) } - }; + }); } fn push_inherent_candidates_from_param(&self, @@ -464,7 +463,7 @@ impl<'self> LookupContext<'self> { self_ty: ty::t, bounds: &[@TraitRef], param: param_index) { - do self.push_inherent_candidates_from_bounds_inner(bounds) + self.push_inherent_candidates_from_bounds_inner(bounds, |trait_ref, m, method_num, bound_num| { Candidate { rcvr_match_condition: RcvrMatchesIfSubtype(self_ty), @@ -478,7 +477,7 @@ impl<'self> LookupContext<'self> { bound_num: bound_num, }) } - } + }) } // Do a search through a list of bounds, using a callback to actually @@ -493,7 +492,7 @@ impl<'self> LookupContext<'self> { let tcx = self.tcx(); let mut next_bound_idx = 0; // count only trait bounds - do ty::each_bound_trait_and_supertraits(tcx, bounds) |bound_trait_ref| { + ty::each_bound_trait_and_supertraits(tcx, bounds, |bound_trait_ref| { let this_bound_idx = next_bound_idx; next_bound_idx += 1; @@ -518,7 +517,7 @@ impl<'self> LookupContext<'self> { } } true - }; + }); } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 857b1455a364e..b9d6744e53b19 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -392,12 +392,10 @@ impl Visitor<()> for GatherLocalsVisitor { } fn visit_block(&mut self, b:&ast::Block, _:()) { - // non-obvious: the `blk` variable maps to region lb, so - // we have to keep this up-to-date. This - // is... unfortunate. It'd be nice to not need this. - do self.fcx.with_region_lb(b.id) { - visit::walk_block(self, b, ()); - } + // non-obvious: the `blk` variable maps to region lb, so + // we have to keep this up-to-date. This + // is... unfortunate. It'd be nice to not need this. + self.fcx.with_region_lb(b.id, || visit::walk_block(self, b, ())); } // Don't descend into fns and items @@ -517,10 +515,11 @@ pub fn check_fn(ccx: @mut CrateCtxt, // Add formal parameters. for (arg_ty, input) in arg_tys.iter().zip(decl.inputs.iter()) { // Create type variables for each argument. - do pat_util::pat_bindings(tcx.def_map, input.pat) - |_bm, pat_id, _sp, _path| { + pat_util::pat_bindings(tcx.def_map, + input.pat, + |_bm, pat_id, _sp, _path| { visit.assign(pat_id, None); - } + }); // Check the pattern. let pcx = pat_ctxt { @@ -1392,17 +1391,17 @@ pub fn valid_range_bounds(ccx: @mut CrateCtxt, pub fn check_expr_has_type( fcx: @mut FnCtxt, expr: @ast::Expr, expected: ty::t) { - do check_expr_with_unifier(fcx, expr, Some(expected)) { + check_expr_with_unifier(fcx, expr, Some(expected), || { demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr)); - } + }); } pub fn check_expr_coercable_to_type( fcx: @mut FnCtxt, expr: @ast::Expr, expected: ty::t) { - do check_expr_with_unifier(fcx, expr, Some(expected)) { + check_expr_with_unifier(fcx, expr, Some(expected), || { demand::coerce(fcx, expr.span, expected, expr) - } + }); } pub fn check_expr_with_hint( @@ -1462,9 +1461,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt, substs: &ty::substs) -> Option { let o_field = items.iter().find(|f| f.name == fieldname); - do o_field.map() |f| { - ty::lookup_field_type(tcx, class_id, f.id, substs) - } + o_field.map(|f| ty::lookup_field_type(tcx, class_id, f.id, substs)) } // Controls whether the arguments are automatically referenced. This is useful @@ -2693,7 +2690,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } } ast::ExprUnary(callee_id, unop, oprnd) => { - let exp_inner = do unpack_expected(fcx, expected) |sty| { + let exp_inner = unpack_expected(fcx, expected, |sty| { match unop { ast::UnBox(_) | ast::UnUniq => match *sty { ty::ty_box(ref mt) | ty::ty_uniq(ref mt) => Some(mt.ty), @@ -2702,7 +2699,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ast::UnNot | ast::UnNeg => expected, ast::UnDeref => None } - }; + }); check_expr_with_opt_hint(fcx, oprnd, exp_inner); let mut oprnd_t = fcx.expr_ty(oprnd); if !ty::type_is_error(oprnd_t) && @@ -2925,12 +2922,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expected, |x| Some((*x).clone())); let inner_ty = match expected_sty { - Some(ty::ty_closure(_)) => expected.unwrap(), + Some(ty::ty_closure(ref closure_ty)) + if closure_ty.sigil == ast::OwnedSigil => { + expected.unwrap() + } _ => match expected { Some(expected_t) => { fcx.type_error_message(expr.span, |actual| { format!("last argument in `do` call \ - has non-closure type: {}", + has non-procedure type: {}", actual) }, expected_t, None); let err_ty = ty::mk_err(); @@ -3137,7 +3137,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let mut bot_field = false; let mut err_field = false; - let elt_ts = do elts.iter().enumerate().map |(i, e)| { + let elt_ts = elts.iter().enumerate().map(|(i, e)| { let opt_hint = match flds { Some(ref fs) if i < fs.len() => Some(fs[i]), _ => None @@ -3147,7 +3147,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, err_field = err_field || ty::type_is_error(t); bot_field = bot_field || ty::type_is_bot(t); t - }.collect(); + }).collect(); if bot_field { fcx.write_bot(id); } else if err_field { @@ -3355,7 +3355,7 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt, let purity_state = fcx.ps.recurse(blk); let prev = replace(&mut fcx.ps, purity_state); - do fcx.with_region_lb(blk.id) { + fcx.with_region_lb(blk.id, || { let mut warned = false; let mut last_was_bot = false; let mut any_bot = false; @@ -3408,7 +3408,7 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt, } } }; - } + }); fcx.ps = prev; } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index c3827037f15ee..98ef129dd208f 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -212,7 +212,7 @@ fn visit_local(rcx: &mut Rcx, l: @ast::Local) { fn constrain_bindings_in_pat(pat: @ast::Pat, rcx: &mut Rcx) { let tcx = rcx.fcx.tcx(); debug!("regionck::visit_pat(pat={})", pat.repr(tcx)); - do pat_util::pat_bindings(tcx.def_map, pat) |_, id, span, _| { + pat_util::pat_bindings(tcx.def_map, pat, |_, id, span, _| { // If we have a variable that contains region'd data, that // data will be accessible from anywhere that the variable is // accessed. We must be wary of loops like this: @@ -240,7 +240,7 @@ fn constrain_bindings_in_pat(pat: @ast::Pat, rcx: &mut Rcx) { constrain_regions_in_type_of_node( rcx, id, encl_region, infer::BindingTypeIsNotValidAtDecl(span)); - } + }) } fn visit_expr(rcx: &mut Rcx, expr: @ast::Expr) { @@ -735,7 +735,7 @@ fn constrain_regions_in_type( region_to_str(tcx, "", false, minimum_lifetime), ty_to_str(tcx, ty)); - do relate_nested_regions(tcx, Some(minimum_lifetime), ty) |r_sub, r_sup| { + relate_nested_regions(tcx, Some(minimum_lifetime), ty, |r_sub, r_sup| { debug!("relate_nested_regions(r_sub={}, r_sup={})", r_sub.repr(tcx), r_sup.repr(tcx)); @@ -754,7 +754,7 @@ fn constrain_regions_in_type( true, infer::ReferenceOutlivesReferent(ty, origin.span()), r_sub, r_sup); } - } + }); return (e == rcx.errors_reported); } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 996157df2e299..782a5276b7470 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -132,7 +132,7 @@ fn lookup_vtables_for_param(vcx: &VtableContext, // ty is the value supplied for the type parameter A... let mut param_result = ~[]; - do ty::each_bound_trait_and_supertraits(tcx, type_param_bounds.trait_bounds) |trait_ref| { + ty::each_bound_trait_and_supertraits(tcx, type_param_bounds.trait_bounds, |trait_ref| { // ...and here trait_ref is each bound that was declared on A, // expressed in terms of the type parameters. @@ -161,7 +161,7 @@ fn lookup_vtables_for_param(vcx: &VtableContext, } } true - }; + }); debug!("lookup_vtables_for_param result(\ location_info={:?}, \ @@ -291,7 +291,7 @@ fn lookup_vtable_from_bounds(vcx: &VtableContext, let mut n_bound = 0; let mut ret = None; - do ty::each_bound_trait_and_supertraits(tcx, bounds) |bound_trait_ref| { + ty::each_bound_trait_and_supertraits(tcx, bounds, |bound_trait_ref| { debug!("checking bounds trait {}", bound_trait_ref.repr(vcx.tcx())); @@ -309,7 +309,7 @@ fn lookup_vtable_from_bounds(vcx: &VtableContext, n_bound += 1; true } - }; + }); ret } @@ -483,12 +483,12 @@ fn fixup_substs(vcx: &VtableContext, ty::RegionTraitStore(ty::ReStatic), ast::MutImmutable, ty::EmptyBuiltinBounds()); - do fixup_ty(vcx, location_info, t, is_early).map |t_f| { + fixup_ty(vcx, location_info, t, is_early).map(|t_f| { match ty::get(t_f).sty { ty::ty_trait(_, ref substs_f, _, _, _) => (*substs_f).clone(), _ => fail!("t_f should be a trait") } - } + }) } fn fixup_ty(vcx: &VtableContext, @@ -560,7 +560,7 @@ pub fn early_resolve_expr(ex: @ast::Expr, let cx = fcx.ccx; match ex.node { ast::ExprPath(*) => { - do fcx.opt_node_ty_substs(ex.id) |substs| { + fcx.opt_node_ty_substs(ex.id, |substs| { debug!("vtable resolution on parameter bounds for expr {}", ex.repr(fcx.tcx())); let def = cx.tcx.def_map.get_copy(&ex.id); @@ -580,7 +580,7 @@ pub fn early_resolve_expr(ex: @ast::Expr, } } true - }; + }); } ast::ExprParen(e) => { diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 93438cacdd602..e2da054527c66 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -180,7 +180,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId) id, ppaux::ty_to_str(tcx, n_ty), ppaux::ty_to_str(tcx, t)); write_ty_to_tcx(tcx, id, t); let mut ret = Some(t); - do fcx.opt_node_ty_substs(id) |substs| { + fcx.opt_node_ty_substs(id, |substs| { let mut new_tps = ~[]; for subst in substs.tps.iter() { match resolve_type_vars_in_type(fcx, sp, *subst) { @@ -190,7 +190,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId) } write_substs_to_tcx(tcx, id, new_tps); ret.is_some() - }; + }); ret } } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 78aa3f8fe4077..115058824c6ff 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -102,7 +102,7 @@ pub fn type_is_defined_in_local_crate(original_type: t) -> bool { */ let mut found_nominal = false; - do ty::walk_ty(original_type) |t| { + ty::walk_ty(original_type, |t| { match get(t).sty { ty_enum(def_id, _) | ty_trait(def_id, _, _, _, _) | @@ -114,7 +114,7 @@ pub fn type_is_defined_in_local_crate(original_type: t) -> bool { _ => { } } - } + }); return found_nominal; } @@ -413,22 +413,22 @@ impl CoherenceChecker { } pub fn check_implementation_coherence(&self) { - do self.crate_context.tcx.trait_impls.each_key |&trait_id| { + self.crate_context.tcx.trait_impls.each_key(|&trait_id| { self.check_implementation_coherence_of(trait_id); true - }; + }); } pub fn check_implementation_coherence_of(&self, trait_def_id: DefId) { // Unify pairs of polytypes. - do self.iter_impls_of_trait(trait_def_id) |a| { + self.iter_impls_of_trait(trait_def_id, |a| { let implementation_a = a; let polytype_a = self.get_self_type_for_implementation(implementation_a); // "We have an impl of trait for type , // and that impl is " - do self.iter_impls_of_trait(trait_def_id) |b| { + self.iter_impls_of_trait(trait_def_id, |b| { let implementation_b = b; // An impl is coherent with itself @@ -447,8 +447,8 @@ impl CoherenceChecker { "note conflicting implementation here"); } } - } - } + }) + }) } pub fn iter_impls_of_trait(&self, trait_def_id: DefId, f: |@Impl|) { @@ -665,12 +665,12 @@ impl CoherenceChecker { let mut impls_seen = HashSet::new(); let crate_store = self.crate_context.tcx.sess.cstore; - do iter_crate_data(crate_store) |crate_number, _crate_metadata| { - do each_impl(crate_store, crate_number) |def_id| { + iter_crate_data(crate_store, |crate_number, _crate_metadata| { + each_impl(crate_store, crate_number, |def_id| { assert_eq!(crate_number, def_id.crate); self.add_external_impl(&mut impls_seen, def_id) - } - } + }) + }) } // diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 36ed9f94fb71a..aa99c2b0f3751 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -264,9 +264,9 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, // Represents [A',B',C'] let num_trait_bounds = trait_ty_generics.type_param_defs.len(); - let non_shifted_trait_tps = do vec::from_fn(num_trait_bounds) |i| { + let non_shifted_trait_tps = vec::from_fn(num_trait_bounds, |i| { ty::mk_param(tcx, i, trait_ty_generics.type_param_defs[i].def_id) - }; + }); // Represents [D'] let self_param = ty::mk_param(tcx, num_trait_bounds, @@ -274,10 +274,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, // Represents [E',F',G'] let num_method_bounds = m.generics.type_param_defs.len(); - let shifted_method_tps = do vec::from_fn(num_method_bounds) |i| { + let shifted_method_tps = vec::from_fn(num_method_bounds, |i| { ty::mk_param(tcx, i + num_trait_bounds + 1, m.generics.type_param_defs[i].def_id) - }; + }); // Convert the regions 'a, 'b, 'c defined on the trait into // bound regions on the fn. diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index e2ea08244006d..e825aca2eec65 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -98,45 +98,45 @@ impl Coerce { // See above for details. match ty::get(b).sty { ty::ty_rptr(_, mt_b) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_pointer(a, sty_a, b, mt_b) - }; + }); } ty::ty_estr(vstore_slice(_)) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_string(a, sty_a, b) - }; + }); } ty::ty_evec(mt_b, vstore_slice(_)) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_vector(a, sty_a, b, mt_b) - }; + }); } ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, _}) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_fn(a, sty_a, b) - }; + }); } ty::ty_trait(_, _, ty::RegionTraitStore(*), m, _) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_object(a, sty_a, b, m) - }; + }); } ty::ty_ptr(mt_b) => { - return do self.unpack_actual_value(a) |sty_a| { + return self.unpack_actual_value(a, |sty_a| { self.coerce_unsafe_ptr(a, sty_a, b, mt_b) - }; + }); } _ => {} } - do self.unpack_actual_value(a) |sty_a| { + self.unpack_actual_value(a, |sty_a| { match *sty_a { ty::ty_bare_fn(ref a_f) => { // Bare functions are coercable to any closure type. @@ -151,7 +151,7 @@ impl Coerce { self.subtype(a, b) } } - } + }) } pub fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult { @@ -342,9 +342,9 @@ impl Coerce { fn_ty_a: &ty::BareFnTy, b: ty::t) -> CoerceResult { - do self.unpack_actual_value(b) |sty_b| { + self.unpack_actual_value(b, |sty_b| { self.coerce_from_bare_fn_post_unpack(a, fn_ty_a, b, sty_b) - } + }) } pub fn coerce_from_bare_fn_post_unpack(&self, diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index c42f74864d249..cdbd70ce3a729 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -232,9 +232,7 @@ pub trait Combine { } fn args(&self, a: ty::t, b: ty::t) -> cres { - do self.contratys(a, b).and_then |t| { - Ok(t) - } + self.contratys(a, b).and_then(|t| Ok(t)) } fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres { @@ -270,9 +268,9 @@ pub trait Combine { match (a, b) { (ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => { - do self.contraregions(a_r, b_r).and_then |r| { + self.contraregions(a_r, b_r).and_then(|r| { Ok(ty::vstore_slice(r)) - } + }) } _ if a == b => { @@ -294,9 +292,9 @@ pub trait Combine { match (a, b) { (ty::RegionTraitStore(a_r), ty::RegionTraitStore(b_r)) => { - do self.contraregions(a_r, b_r).and_then |r| { + self.contraregions(a_r, b_r).and_then(|r| { Ok(ty::RegionTraitStore(r)) - } + }) } _ if a == b => { @@ -346,11 +344,9 @@ pub fn expected_found( pub fn eq_tys(this: &C, a: ty::t, b: ty::t) -> ures { let suber = this.sub(); - do this.infcx().try { - do suber.tys(a, b).and_then |_ok| { - suber.contratys(a, b) - }.to_ures() - } + this.infcx().try(|| { + suber.tys(a, b).and_then(|_ok| suber.contratys(a, b)).to_ures() + }) } pub fn eq_regions(this: &C, a: ty::Region, b: ty::Region) @@ -359,11 +355,9 @@ pub fn eq_regions(this: &C, a: ty::Region, b: ty::Region) a.repr(this.infcx().tcx), b.repr(this.infcx().tcx)); let sub = this.sub(); - do indent { + indent(|| { this.infcx().try(|| { - do sub.regions(a, b).and_then |_r| { - sub.contraregions(a, b) - } + sub.regions(a, b).and_then(|_r| sub.contraregions(a, b)) }).or_else(|e| { // substitute a better error, but use the regions // found in the original error @@ -373,7 +367,7 @@ pub fn eq_regions(this: &C, a: ty::Region, b: ty::Region) _ => Err(e) } }).to_ures() - } + }) } pub fn eq_opt_regions( @@ -382,25 +376,19 @@ pub fn eq_opt_regions( b: Option) -> cres> { match (a, b) { - (None, None) => { - Ok(None) - } - (Some(a), Some(b)) => { - do eq_regions(this, a, b).then { - Ok(Some(a)) + (None, None) => Ok(None), + (Some(a), Some(b)) => eq_regions(this, a, b).then(|| Ok(Some(a))), + (_, _) => { + // If these two substitutions are for the same type (and + // they should be), then the type should either + // consistently have a region parameter or not have a + // region parameter. + this.infcx().tcx.sess.bug( + format!("substitution a had opt_region {} and \ + b had opt_region {}", + a.inf_str(this.infcx()), + b.inf_str(this.infcx()))); } - } - (_, _) => { - // If these two substitutions are for the same type (and - // they should be), then the type should either - // consistently have a region parameter or not have a - // region parameter. - this.infcx().tcx.sess.bug( - format!("substitution a had opt_region {} and \ - b had opt_region {}", - a.inf_str(this.infcx()), - b.inf_str(this.infcx()))); - } } } @@ -528,21 +516,15 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } (&ty::ty_box(ref a_mt), &ty::ty_box(ref b_mt)) => { - do this.mts(a_mt, b_mt).and_then |mt| { - Ok(ty::mk_box(tcx, mt)) - } + this.mts(a_mt, b_mt).and_then(|mt| Ok(ty::mk_box(tcx, mt))) } (&ty::ty_uniq(ref a_mt), &ty::ty_uniq(ref b_mt)) => { - do this.mts(a_mt, b_mt).and_then |mt| { - Ok(ty::mk_uniq(tcx, mt)) - } + this.mts(a_mt, b_mt).and_then(|mt| Ok(ty::mk_uniq(tcx, mt))) } (&ty::ty_ptr(ref a_mt), &ty::ty_ptr(ref b_mt)) => { - do this.mts(a_mt, b_mt).and_then |mt| { - Ok(ty::mk_ptr(tcx, mt)) - } + this.mts(a_mt, b_mt).and_then(|mt| Ok(ty::mk_ptr(tcx, mt))) } (&ty::ty_rptr(a_r, ref a_mt), &ty::ty_rptr(b_r, ref b_mt)) => { @@ -552,11 +534,11 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } (&ty::ty_evec(ref a_mt, vs_a), &ty::ty_evec(ref b_mt, vs_b)) => { - do this.mts(a_mt, b_mt).and_then |mt| { - do this.vstores(ty::terr_vec, vs_a, vs_b).and_then |vs| { + this.mts(a_mt, b_mt).and_then(|mt| { + this.vstores(ty::terr_vec, vs_a, vs_b).and_then(|vs| { Ok(ty::mk_evec(tcx, mt, vs)) - } - } + }) + }) } (&ty::ty_estr(vs_a), &ty::ty_estr(vs_b)) => { @@ -576,15 +558,15 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } (&ty::ty_bare_fn(ref a_fty), &ty::ty_bare_fn(ref b_fty)) => { - do this.bare_fn_tys(a_fty, b_fty).and_then |fty| { + this.bare_fn_tys(a_fty, b_fty).and_then(|fty| { Ok(ty::mk_bare_fn(tcx, fty)) - } + }) } (&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => { - do this.closure_tys(a_fty, b_fty).and_then |fty| { + this.closure_tys(a_fty, b_fty).and_then(|fty| { Ok(ty::mk_closure(tcx, fty)) - } + }) } _ => Err(ty::terr_sorts(expected_found(this, a, b))) diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index dbf11ab68bcae..8f344095aea8c 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -230,9 +230,7 @@ impl CombineFieldsLatticeMethods for CombineFields { (&Some(_), &None) => Ok((*a).clone()), (&None, &Some(_)) => Ok((*b).clone()), (&Some(ref v_a), &Some(ref v_b)) => { - do lattice_op(self, v_a, v_b).and_then |v| { - Ok(Some(v)) - } + lattice_op(self, v_a, v_b).and_then(|v| Ok(Some(v))) } } } @@ -471,9 +469,9 @@ pub fn lattice_vars t, Err(ref err) => { @@ -310,28 +307,28 @@ pub fn mk_subty(cx: @mut InferCtxt, b: ty::t) -> ures { debug!("mk_subty({} <: {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.commit { + indent(|| { + cx.commit(|| { let trace = TypeTrace { origin: origin, values: Types(expected_found(a_is_expected, a, b)) }; cx.sub(a_is_expected, trace).tys(a, b) - } - }.to_ures() + }) + }).to_ures() } pub fn can_mk_subty(cx: @mut InferCtxt, a: ty::t, b: ty::t) -> ures { debug!("can_mk_subty({} <: {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.probe { + indent(|| { + cx.probe(|| { let trace = TypeTrace { origin: Misc(codemap::dummy_sp()), values: Types(expected_found(true, a, b)) }; cx.sub(true, trace).tys(a, b) - } - }.to_ures() + }) + }).to_ures() } pub fn mk_subr(cx: @mut InferCtxt, @@ -352,16 +349,16 @@ pub fn mk_eqty(cx: @mut InferCtxt, b: ty::t) -> ures { debug!("mk_eqty({} <: {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.commit { + indent(|| { + cx.commit(|| { let trace = TypeTrace { origin: origin, values: Types(expected_found(a_is_expected, a, b)) }; let suber = cx.sub(a_is_expected, trace); eq_tys(&suber, a, b) - } - }.to_ures() + }) + }).to_ures() } pub fn mk_sub_trait_refs(cx: @mut InferCtxt, @@ -373,16 +370,16 @@ pub fn mk_sub_trait_refs(cx: @mut InferCtxt, { debug!("mk_sub_trait_refs({} <: {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.commit { + indent(|| { + cx.commit(|| { let trace = TypeTrace { origin: origin, values: TraitRefs(expected_found(a_is_expected, a, b)) }; let suber = cx.sub(a_is_expected, trace); suber.trait_refs(a, b) - } - }.to_ures() + }) + }).to_ures() } fn expected_found(a_is_expected: bool, @@ -402,28 +399,28 @@ pub fn mk_coercety(cx: @mut InferCtxt, b: ty::t) -> CoerceResult { debug!("mk_coercety({} -> {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.commit { + indent(|| { + cx.commit(|| { let trace = TypeTrace { origin: origin, values: Types(expected_found(a_is_expected, a, b)) }; Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b) - } - } + }) + }) } pub fn can_mk_coercety(cx: @mut InferCtxt, a: ty::t, b: ty::t) -> ures { debug!("can_mk_coercety({} -> {})", a.inf_str(cx), b.inf_str(cx)); - do indent { - do cx.probe { + indent(|| { + cx.probe(|| { let trace = TypeTrace { origin: Misc(codemap::dummy_sp()), values: Types(expected_found(true, a, b)) }; Coerce(cx.combine_fields(true, trace)).tys(a, b) - } - }.to_ures() + }) + }).to_ures() } // See comment on the type `resolve_state` below @@ -472,13 +469,13 @@ trait CresCompare { impl CresCompare for cres { fn compare(&self, t: T, f: || -> ty::type_err) -> cres { - do (*self).clone().and_then |s| { + (*self).clone().and_then(|s| { if s == t { (*self).clone() } else { Err(f()) } - } + }) } } @@ -553,14 +550,14 @@ impl InferCtxt { assert!(!self.in_snapshot()); debug!("commit()"); - do indent { + indent(|| { let r = self.try(|| f()); self.ty_var_bindings.bindings.truncate(0); self.int_var_bindings.bindings.truncate(0); self.region_vars.commit(); r - } + }) } /// Execute `f`, unroll bindings on failure @@ -581,12 +578,12 @@ impl InferCtxt { /// Execute `f` then unroll any bindings it creates pub fn probe(@mut self, f: || -> Result) -> Result { debug!("probe()"); - do indent { + indent(|| { let snapshot = self.start_snapshot(); let r = f(); self.rollback_to(&snapshot); r - } + }) } } @@ -737,12 +734,12 @@ impl InferCtxt { err: Option<&ty::type_err>) { debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty); - let error_str = do err.map_default(~"") |t_err| { + let error_str = err.map_default(~"", |t_err| { format!(" ({})", ty::type_err_to_str(self.tcx, t_err)) - }; - let resolved_expected = do expected_ty.map |e_ty| { + }); + let resolved_expected = expected_ty.map(|e_ty| { self.resolve_type_vars_if_possible(e_ty) - }; + }); if !resolved_expected.map_default(false, |e| { ty::type_is_error(e) }) { match resolved_expected { None => self.tcx.sess.span_err(sp, diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index 8af370792aee1..f639139d265e4 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -764,7 +764,7 @@ impl RegionVarBindings { } fn expansion(&self, var_data: &mut [VarData]) { - do self.iterate_until_fixed_point("Expansion") |constraint| { + self.iterate_until_fixed_point("Expansion", |constraint| { match *constraint { ConstrainRegSubVar(a_region, b_vid) => { let b_data = &mut var_data[b_vid.to_uint()]; @@ -788,7 +788,7 @@ impl RegionVarBindings { false } } - } + }) } fn expand_node(&self, @@ -829,7 +829,7 @@ impl RegionVarBindings { fn contraction(&self, var_data: &mut [VarData]) { - do self.iterate_until_fixed_point("Contraction") |constraint| { + self.iterate_until_fixed_point("Contraction", |constraint| { match *constraint { ConstrainRegSubVar(*) => { // This is an expansion constraint. Ignore. @@ -853,7 +853,7 @@ impl RegionVarBindings { false } } - } + }) } fn contract_node(&self, @@ -1225,7 +1225,7 @@ impl RegionVarBindings { debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir); let source_node_index = NodeIndex(source_vid.to_uint()); - do graph.each_adjacent_edge(source_node_index, dir) |_, edge| { + graph.each_adjacent_edge(source_node_index, dir, |_, edge| { match edge.data { ConstrainVarSubVar(from_vid, to_vid) => { let opp_vid = @@ -1246,7 +1246,7 @@ impl RegionVarBindings { ConstrainRegSubReg(*) => {} } true - }; + }); } } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index 117b100005a01..210d7fd7c80b1 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -167,13 +167,13 @@ impl Combine for Sub { // Second, we instantiate each bound region in the supertype with a // fresh concrete region. let (skol_map, _, b_sig) = { - do replace_bound_regions_in_fn_sig(self.infcx.tcx, None, b) |br| { + replace_bound_regions_in_fn_sig(self.infcx.tcx, None, b, |br| { let skol = self.infcx.region_vars.new_skolemized(br); debug!("Bound region {} skolemized to {:?}", bound_region_to_str(self.infcx.tcx, "", false, br), skol); skol - } + }) }; debug!("a_sig={}", a_sig.inf_str(self.infcx)); diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index ed2b1d1db4b5a..6afbcf053b8cd 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -330,10 +330,10 @@ impl get_and_find_region for isr_alist { fn find(&self, br: ty::BoundRegion) -> Option { let mut ret = None; - do list::each(*self) |isr| { + list::each(*self, |isr| { let (isr_br, isr_r) = *isr; if isr_br == br { ret = Some(isr_r); false } else { true } - }; + }); ret } } diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index f0f2ca2db3350..11c2aca6c343f 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -79,9 +79,9 @@ impl Clean for visit_ast::RustdocVisitor { let cx = local_data::get(super::ctxtkey, |x| *x.unwrap()); let mut externs = HashMap::new(); - do cstore::iter_crate_data(cx.sess.cstore) |n, meta| { + cstore::iter_crate_data(cx.sess.cstore, |n, meta| { externs.insert(n, meta.clean()); - } + }); Crate { name: match maybe_meta { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index b191eb37af1bc..0f490fd960e37 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -170,11 +170,11 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, } // Did someone say rightward-drift? - do local_data::get(current_location_key) |loc| { + local_data::get(current_location_key, |loc| { let loc = loc.unwrap(); - do local_data::get(cache_key) |cache| { - do cache.unwrap().read |cache| { + local_data::get(cache_key, |cache| { + cache.unwrap().read(|cache| { let abs_root = root(cache, loc.as_slice()); let rel_root = match path.segments[0].name.as_slice() { "self" => Some(~"./"), @@ -238,9 +238,9 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, } } write!(w, "{}", generics); - } - } - } + }) + }) + }) } /// Helper to render type parameters @@ -262,11 +262,11 @@ impl fmt::Default for clean::Type { fn fmt(g: &clean::Type, f: &mut fmt::Formatter) { match *g { clean::TyParamBinder(id) | clean::Generic(id) => { - do local_data::get(cache_key) |cache| { - do cache.unwrap().read |m| { + local_data::get(cache_key, |cache| { + cache.unwrap().read(|m| { f.buf.write(m.typarams.get(&id).as_bytes()); - } - } + }) + }) } clean::ResolvedPath{id, typarams: ref tp, path: ref path} => { resolved_path(f.buf, id, path, false); diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index c07befea18feb..ac7c50fdfd809 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -109,14 +109,14 @@ fn render(w: &mut io::Writer, s: &str) { let markdown = sd_markdown_new(extensions, 16, &callbacks, &options as *html_renderopt as *libc::c_void); - do s.as_imm_buf |data, len| { + s.as_imm_buf(|data, len| { sd_markdown_render(ob, data, len as libc::size_t, markdown); - } + }); sd_markdown_free(markdown); - do vec::raw::buf_as_slice((*ob).data, (*ob).size as uint) |buf| { + vec::raw::buf_as_slice((*ob).data, (*ob).size as uint, |buf| { w.write(buf); - } + }); bufrelease(ob); } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9f0a4cefc4c12..819316313b677 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -320,15 +320,15 @@ fn write(dst: Path, contents: &str) { /// Makes a directory on the filesystem, failing the task if an error occurs and /// skipping if the directory already exists. fn mkdir(path: &Path) { - do io::io_error::cond.trap(|err| { + io::io_error::cond.trap(|err| { error!("Couldn't create directory `{}`: {}", path.display(), err.desc); fail!() - }).inside { + }).inside(|| { if !path.is_dir() { fs::mkdir(path, io::UserRWX); } - } + }) } /// Takes a path to a source file and cleans the path to it. This canonicalizes @@ -439,11 +439,11 @@ impl<'self> SourceCollector<'self> { // Create the intermediate directories let mut cur = self.dst.clone(); let mut root_path = ~"../../"; - do clean_srcpath(p.dirname()) |component| { + clean_srcpath(p.dirname(), |component| { cur.push(component); mkdir(&cur); root_path.push_str("../"); - } + }); cur.push(p.filename().expect("source has no filename") + bytes!(".html")); let mut w = BufferedWriter::new(File::create(&cur).unwrap()); @@ -492,9 +492,9 @@ impl DocFolder for Cache { clean::ImplItem(ref i) => { match i.trait_ { Some(clean::ResolvedPath{ id, _ }) => { - let v = do self.implementors.find_or_insert_with(id) |_|{ + let v = self.implementors.find_or_insert_with(id, |_|{ ~[] - }; + }); match i.for_ { clean::ResolvedPath{_} => { v.unshift(PathType(i.for_.clone())); @@ -595,9 +595,9 @@ impl DocFolder for Cache { clean::Item{ attrs, inner: clean::ImplItem(i), _ } => { match i.for_ { clean::ResolvedPath { id, _ } => { - let v = do self.impls.find_or_insert_with(id) |_| { + let v = self.impls.find_or_insert_with(id, |_| { ~[] - }; + }); // extract relevant documentation for this impl match attrs.move_iter().find(|a| { match *a { @@ -726,16 +726,16 @@ impl Context { Process(cx, item) => { let mut cx = cx; let item = Cell::new(item); - do (|| { - do cx.item(item.take()) |cx, item| { + (|| { + cx.item(item.take(), |cx, item| { prog_chan.send(JobNew); chan.send(Process(cx.clone(), item)); - } - }).finally { + }) + }).finally(|| { // If we fail, everything else should still get // completed prog_chan.send(JobDone); - } + }) } Die => break, } @@ -803,7 +803,7 @@ impl Context { clean::ModuleItem(*) => { let name = item.name.get_ref().to_owned(); let item = Cell::new(item); - do self.recurse(name) |this| { + self.recurse(name, |this| { let item = item.take(); let dst = this.dst.join("index.html"); render(File::create(&dst).unwrap(), this, &item, false); @@ -816,7 +816,7 @@ impl Context { for item in m.items.move_iter() { f(this, item); } - } + }) } // Things which don't have names (like impls) don't get special @@ -875,9 +875,9 @@ impl<'self> fmt::Default for Item<'self> { if it.cx.include_sources { let mut path = ~[]; - do clean_srcpath(it.item.source.filename.as_bytes()) |component| { + clean_srcpath(it.item.source.filename.as_bytes(), |component| { path.push(component.to_owned()); - } + }); let href = if it.item.source.loline == it.item.source.hiline { format!("{}", it.item.source.loline) } else { @@ -1012,9 +1012,7 @@ fn item_module(w: &mut Writer, cx: &Context, } debug!("{:?}", indices); - do sort::quick_sort(indices) |&i1, &i2| { - lt(&items[i1], &items[i2], i1, i2) - } + sort::quick_sort(indices, |&i1, &i2| lt(&items[i1], &items[i2], i1, i2)); debug!("{:?}", indices); let mut curty = ""; @@ -1200,8 +1198,8 @@ fn item_trait(w: &mut Writer, it: &clean::Item, t: &clean::Trait) { write!(w, ""); } - do local_data::get(cache_key) |cache| { - do cache.unwrap().read |cache| { + local_data::get(cache_key, |cache| { + cache.unwrap().read(|cache| { match cache.implementors.find(&it.id) { Some(implementors) => { write!(w, " @@ -1223,8 +1221,8 @@ fn item_trait(w: &mut Writer, it: &clean::Item, t: &clean::Trait) { } None => {} } - } - } + }) + }) } fn render_method(w: &mut Writer, meth: &clean::Item, withlink: bool) { @@ -1412,9 +1410,9 @@ fn render_struct(w: &mut Writer, it: &clean::Item, } fn render_methods(w: &mut Writer, it: &clean::Item) { - do local_data::get(cache_key) |cache| { + local_data::get(cache_key, |cache| { let cache = cache.unwrap(); - do cache.read |c| { + cache.read(|c| { match c.impls.find(&it.id) { Some(v) => { let mut non_trait = v.iter().filter(|p| { @@ -1442,8 +1440,8 @@ fn render_methods(w: &mut Writer, it: &clean::Item) { } None => {} } - } - } + }) + }) } fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) { @@ -1492,8 +1490,8 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) { None => continue, Some(id) => id, }; - do local_data::get(cache_key) |cache| { - do cache.unwrap().read |cache| { + local_data::get(cache_key, |cache| { + cache.unwrap().read(|cache| { match cache.traits.find(&trait_id) { Some(t) => { let name = meth.name.clone(); @@ -1513,8 +1511,8 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) { } None => {} } - } - } + }) + }) } // If we've implemented a trait, then also emit documentation for all @@ -1522,8 +1520,8 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) { match trait_id { None => {} Some(id) => { - do local_data::get(cache_key) |cache| { - do cache.unwrap().read |cache| { + local_data::get(cache_key, |cache| { + cache.unwrap().read(|cache| { match cache.traits.find(&id) { Some(t) => { for method in t.methods.iter() { @@ -1538,8 +1536,8 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) { } None => {} } - } - } + }) + }) } } write!(w, ""); diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 99e825c35e366..f7705f93a79ee 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -57,9 +57,9 @@ pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult { // This stripper collects all *retained* nodes. let mut retained = HashSet::new(); let crate = Cell::new(crate); - let exported_items = do local_data::get(super::analysiskey) |analysis| { + let exported_items = local_data::get(super::analysiskey, |analysis| { analysis.unwrap().exported_items.clone() - }; + }); let mut crate = crate.take(); // strip all private items @@ -231,7 +231,7 @@ pub fn unindent(s: &str) -> ~str { let lines = s.lines_any().collect::<~[&str]>(); let mut saw_first_line = false; let mut saw_second_line = false; - let min_indent = do lines.iter().fold(uint::max_value) |min_indent, line| { + let min_indent = lines.iter().fold(uint::max_value, |min_indent, line| { // After we see the first non-whitespace line, look at // the line we have. If it is not whitespace, and therefore @@ -257,7 +257,7 @@ pub fn unindent(s: &str) -> ~str { } else { saw_first_line = true; let mut spaces = 0; - do line.chars().all |char| { + line.chars().all(|char| { // Only comparing against space because I wouldn't // know what to do with mixed whitespace chars if char == ' ' { @@ -266,22 +266,22 @@ pub fn unindent(s: &str) -> ~str { } else { false } - }; + }); num::min(min_indent, spaces) } - }; + }); match lines { [head, .. tail] => { let mut unindented = ~[ head.trim() ]; - unindented.push_all(do tail.map |&line| { + unindented.push_all(tail.map(|&line| { if line.is_whitespace() { line } else { assert!(line.len() >= min_indent); line.slice_from(min_indent) } - }); + })); unindented.connect("\n") } [] => s.to_owned() diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index 3eed6314a0333..b1e3d1bd879ec 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -19,7 +19,7 @@ use std::io::fs; pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool { let workspaces = rust_path(); for p in workspaces.iter() { - let binfiles = do io::ignore_io_error { fs::readdir(&p.join("bin")) }; + let binfiles = io::ignore_io_error(|| fs::readdir(&p.join("bin"))); for exec in binfiles.iter() { // FIXME (#9639): This needs to handle non-utf8 paths match exec.filestem_str() { @@ -31,7 +31,7 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool { } } } - let libfiles = do io::ignore_io_error { fs::readdir(&p.join("lib")) }; + let libfiles = io::ignore_io_error(|| fs::readdir(&p.join("lib"))); for lib in libfiles.iter() { debug!("Full name: {}", lib.display()); match has_library(lib) { @@ -42,10 +42,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool { let rel_p = lib.path_relative_from(&parent).unwrap(); debug!("Rel: {}", rel_p.display()); let rel_path = rel_p.join(basename); - do rel_path.display().with_str |s| { + rel_path.display().with_str(|s| { debug!("Rel name: {}", s); f(&PkgId::new(s)); - } + }); } None => () } @@ -55,7 +55,7 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool { } pub fn has_library(p: &Path) -> Option<~str> { - let files = do io::ignore_io_error { fs::readdir(p) }; + let files = io::ignore_io_error(|| fs::readdir(p)); for path in files.iter() { if path.extension_str() == Some(os::consts::DLL_EXTENSION) { let stuff : &str = path.filestem_str().expect("has_library: weird path"); @@ -71,13 +71,13 @@ pub fn has_library(p: &Path) -> Option<~str> { pub fn package_is_installed(p: &PkgId) -> bool { let mut is_installed = false; - do list_installed_packages() |installed| { + list_installed_packages(|installed| { if installed == p { is_installed = true; false } else { true } - }; + }); is_installed } diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index 46b7b466f236b..f40238364f3f5 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -255,7 +255,7 @@ impl CtxMethods for BuildContext { // argument let pkgid = PkgId::new(args[0].clone()); let mut dest_ws = default_workspace(); - do each_pkg_parent_workspace(&self.context, &pkgid) |workspace| { + each_pkg_parent_workspace(&self.context, &pkgid, |workspace| { debug!("found pkg {} in workspace {}, trying to build", pkgid.to_str(), workspace.display()); dest_ws = determine_destination(os::getcwd(), @@ -265,7 +265,7 @@ impl CtxMethods for BuildContext { false, pkgid.clone()); self.build(&mut pkg_src, what); true - }; + }); // n.b. If this builds multiple packages, it only returns the workspace for // the last one. The whole building-multiple-packages-with-the-same-ID is weird // anyway and there are no tests for it, so maybe take it out @@ -353,12 +353,10 @@ impl CtxMethods for BuildContext { } "list" => { println("Installed packages:"); - do installed_packages::list_installed_packages |pkg_id| { - do pkg_id.path.display().with_str |s| { - println(s); - } + installed_packages::list_installed_packages(|pkg_id| { + pkg_id.path.display().with_str(|s| println(s)); true - }; + }); } "prefer" => { if args.len() < 1 { @@ -402,12 +400,12 @@ impl CtxMethods for BuildContext { else { let rp = rust_path(); assert!(!rp.is_empty()); - do each_pkg_parent_workspace(&self.context, &pkgid) |workspace| { + each_pkg_parent_workspace(&self.context, &pkgid, |workspace| { path_util::uninstall_package_from(workspace, &pkgid); note(format!("Uninstalled package {} (was installed in {})", pkgid.to_str(), workspace.display())); true - }; + }); } } "unprefer" => { @@ -471,19 +469,19 @@ impl CtxMethods for BuildContext { // Build the package script if needed let script_build = format!("build_package_script({})", package_script_path.display()); - let pkg_exe = do self.workcache_context.with_prep(script_build) |prep| { + let pkg_exe = self.workcache_context.with_prep(script_build, |prep| { let subsysroot = sysroot.clone(); let psp = package_script_path.clone(); let ws = workspace.clone(); let pid = pkgid.clone(); - do prep.exec |exec| { + prep.exec(|exec| { let mut pscript = PkgScript::parse(subsysroot.clone(), psp.clone(), &ws, &pid); pscript.build_custom(exec) - } - }; + }) + }); // We always *run* the package script let (cfgs, hook_result) = PkgScript::run_custom(&Path::new(pkg_exe), &sysroot); debug!("Command return code = {:?}", hook_result); @@ -620,7 +618,7 @@ impl CtxMethods for BuildContext { target_exec.display(), target_lib, maybe_executable, maybe_library); - do self.workcache_context.with_prep(id.install_tag()) |prep| { + self.workcache_context.with_prep(id.install_tag(), |prep| { for ee in maybe_executable.iter() { // FIXME (#9639): This needs to handle non-utf8 paths prep.declare_input("binary", @@ -638,7 +636,7 @@ impl CtxMethods for BuildContext { let sub_target_ex = target_exec.clone(); let sub_target_lib = target_lib.clone(); let sub_build_inputs = build_inputs.to_owned(); - do prep.exec |exe_thing| { + prep.exec(|exe_thing| { let mut outputs = ~[]; // Declare all the *inputs* to the declared input too, as inputs for executable in subex.iter() { @@ -684,8 +682,8 @@ impl CtxMethods for BuildContext { outputs.push(target_lib.as_str().unwrap().to_owned()); } outputs - } - } + }) + }) } fn prefer(&self, _id: &str, _vers: Option<~str>) { diff --git a/src/librustpkg/package_id.rs b/src/librustpkg/package_id.rs index bb3f6f27e04f2..04ac30e373287 100644 --- a/src/librustpkg/package_id.rs +++ b/src/librustpkg/package_id.rs @@ -87,10 +87,10 @@ impl PkgId { pub fn hash(&self) -> ~str { // FIXME (#9639): hash should take a &[u8] so we can hash the real path - do self.path.display().with_str |s| { + self.path.display().with_str(|s| { let vers = self.version.to_str(); format!("{}-{}-{}", s, hash(s + vers), vers) - } + }) } pub fn short_name_with_version(&self) -> ~str { diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 4f48dab811f27..9d0812efe28d0 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -291,11 +291,9 @@ impl PkgSrc { let mut failed = false; - do cond.trap(|_| { + cond.trap(|_| { failed = true; - }).inside { - git_clone_url(url, &clone_target, &pkgid.version); - }; + }).inside(|| git_clone_url(url, &clone_target, &pkgid.version)); if failed { return None; @@ -400,7 +398,7 @@ impl PkgSrc { debug!("build_crates: compiling {}", path.display()); let cfgs = crate.cfgs + cfgs; - do ctx.workcache_context.with_prep(crate_tag(&path)) |prep| { + ctx.workcache_context.with_prep(crate_tag(&path), |prep| { debug!("Building crate {}, declaring it as an input", path.display()); // FIXME (#9639): This needs to handle non-utf8 paths prep.declare_input("file", path.as_str().unwrap(), @@ -414,7 +412,7 @@ impl PkgSrc { let sub_deps = deps.clone(); let inputs = inputs_to_discover.map(|&(ref k, ref p)| (k.clone(), p.as_str().unwrap().to_owned())); - do prep.exec |exec| { + prep.exec(|exec| { for &(ref kind, ref p) in inputs.iter() { let pth = Path::new(p.clone()); exec.discover_input(*kind, *p, if *kind == ~"file" { @@ -445,8 +443,8 @@ impl PkgSrc { let result = result.as_ref().map(|p|p.as_str().unwrap()); debug!("Result of compiling {} was {}", subpath.display(), result.to_str()); result.to_str() - } - }; + }) + }); } } diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index adf86d2cf9d75..9d5b5e91fe27c 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -76,7 +76,7 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, if p.is_dir() { if p == src_dir.join(&pkgid.path) || { let pf = p.filename_str(); - do pf.iter().any |&g| { + pf.iter().any(|&g| { match split_version_general(g, '-') { None => false, Some((ref might_match, ref vers)) => { @@ -84,7 +84,7 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path, && (pkgid.version == *vers || pkgid.version == NoVersion) } } - } + }) } { found = Some(p.clone()); } @@ -215,7 +215,7 @@ pub fn system_library(sysroot: &Path, lib_name: &str) -> Option { fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option { debug!("Listing directory {}", dir_to_search.display()); - let dir_contents = do io::ignore_io_error { fs::readdir(dir_to_search) }; + let dir_contents = io::ignore_io_error(|| fs::readdir(dir_to_search)); debug!("dir has {:?} entries", dir_contents.len()); let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name); @@ -225,14 +225,14 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti // Find a filename that matches the pattern: // (lib_prefix)-hash-(version)(lib_suffix) - let mut libraries = do dir_contents.iter().filter |p| { + let mut libraries = dir_contents.iter().filter(|p| { let extension = p.extension_str(); debug!("p = {}, p's extension is {:?}", p.display(), extension); match extension { None => false, Some(ref s) => lib_filetype == *s } - }; + }); let mut result_filename = None; for p_path in libraries { @@ -277,11 +277,11 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti // Return the filename that matches, which we now know exists // (if result_filename != None) - let abs_path = do result_filename.map |result_filename| { + let abs_path = result_filename.map(|result_filename| { let absolute_path = dir_to_search.join(&result_filename); debug!("result_filename = {}", absolute_path.display()); absolute_path - }; + }); abs_path } @@ -463,19 +463,14 @@ pub fn versionize(p: &Path, v: &Version) -> Path { #[cfg(target_os = "win32")] pub fn chmod_read_only(p: &Path) -> bool { unsafe { - do p.with_c_str |src_buf| { - libc::chmod(src_buf, S_IRUSR as libc::c_int) == 0 as libc::c_int - } + p.with_c_str(|src_buf| libc::chmod(src_buf, S_IRUSR as libc::c_int) == 0 as libc::c_int) } } #[cfg(not(target_os = "win32"))] pub fn chmod_read_only(p: &Path) -> bool { unsafe { - do p.with_c_str |src_buf| { - libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0 - as libc::c_int - } + p.with_c_str(|src_buf| libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0 as libc::c_int) } } diff --git a/src/librustpkg/sha1.rs b/src/librustpkg/sha1.rs index db31f603d6ee0..396ef756c7610 100644 --- a/src/librustpkg/sha1.rs +++ b/src/librustpkg/sha1.rs @@ -51,11 +51,11 @@ fn read_u32v_be(dst: &mut[u32], input: &[u8]) { unsafe { let mut x: *mut i32 = transmute(dst.unsafe_mut_ref(0)); let mut y: *i32 = transmute(input.unsafe_ref(0)); - do dst.len().times() { + dst.len().times(|| { *x = to_be32(*y); x = x.offset(1); y = y.offset(1); - } + }) } } @@ -613,9 +613,7 @@ mod bench { pub fn sha1_10(bh: & mut BenchHarness) { let mut sh = Sha1::new(); let bytes = [1u8, ..10]; - do bh.iter { - sh.input(bytes); - } + bh.iter(|| sh.input(bytes)); bh.bytes = bytes.len() as u64; } @@ -623,9 +621,7 @@ mod bench { pub fn sha1_1k(bh: & mut BenchHarness) { let mut sh = Sha1::new(); let bytes = [1u8, ..1024]; - do bh.iter { - sh.input(bytes); - } + bh.iter(|| sh.input(bytes)); bh.bytes = bytes.len() as u64; } @@ -633,9 +629,7 @@ mod bench { pub fn sha1_64k(bh: & mut BenchHarness) { let mut sh = Sha1::new(); let bytes = [1u8, ..65536]; - do bh.iter { - sh.input(bytes); - } + bh.iter(|| sh.input(bytes)); bh.bytes = bytes.len() as u64; } } diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index a6897e141aac7..7413e7847b4ce 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -384,9 +384,7 @@ fn executable_exists(repo: &Path, short_name: &str) -> bool { fn test_executable_exists(repo: &Path, short_name: &str) -> bool { debug!("test_executable_exists: repo = {}, short_name = {}", repo.display(), short_name); let exec = built_test_in_workspace(&PkgId::new(short_name), repo); - do exec.map_default(false) |exec| { - exec.exists() && is_rwx(&exec) - } + exec.map_default(false, |exec| exec.exists() && is_rwx(&exec)); } fn remove_executable_file(p: &PkgId, workspace: &Path) { @@ -544,12 +542,12 @@ fn frob_source_file(workspace: &Path, pkgid: &PkgId, filename: &str) { debug!("Frobbed? {:?}", maybe_p); match maybe_p { Some(ref p) => { - do io::io_error::cond.trap(|e| { + io::io_error::cond.trap(|e| { cond.raise((p.clone(), format!("Bad path: {}", e.desc))); - }).inside { + }).inside(|| { let mut w = File::open_mode(p, io::Append, io::Write); w.write(bytes!("/* hi */\n")); - } + }) } None => fail!("frob_source_file failed to find a source file in {}", pkg_src_dir.display()) @@ -744,26 +742,26 @@ fn test_package_ids_must_be_relative_path_like() { assert!("github.com/catamorphism/test-pkg-0.1" == PkgId::new("github.com/catamorphism/test-pkg").to_str()); - do cond.trap(|(p, e)| { + cond.trap(|(p, e)| { assert!(p.filename().is_none()) assert!("0-length pkgid" == e); whatever.clone() - }).inside { + }).inside(|| { let x = PkgId::new(""); assert_eq!(~"foo-0.1", x.to_str()); - } + }); - do cond.trap(|(p, e)| { + cond.trap(|(p, e)| { let abs = os::make_absolute(&Path::new("foo/bar/quux")); assert_eq!(p, abs); assert!("absolute pkgid" == e); whatever.clone() - }).inside { + }).inside(|| { let zp = os::make_absolute(&Path::new("foo/bar/quux")); // FIXME (#9639): This needs to handle non-utf8 paths let z = PkgId::new(zp.as_str().unwrap()); assert_eq!(~"foo-0.1", z.to_str()); - } + }) } diff --git a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs index f5d6317e7a68f..180f8cc74cee6 100644 --- a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs +++ b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs @@ -44,13 +44,13 @@ pub fn main() { let my_workspace = api::my_workspace(&context.context, "cdep"); let foo_c_name = my_workspace.join_many(["src", "cdep-0.1", "foo.c"]); - let out_lib_path = do context.workcache_context.with_prep("foo.c") |prep| { + let out_lib_path = context.workcache_context.with_prep("foo.c", |prep| { let sub_cx = context.context.clone(); debug!("foo_c_name = {}", foo_c_name.display()); prep.declare_input("file", foo_c_name.as_str().unwrap().to_owned(), digest_file_with_date(&foo_c_name)); - let out_path = do prep.exec |exec| { + let out_path = prep.exec(|exec| { let out_path = api::build_library_in_workspace(exec, &mut sub_cx.clone(), "cdep", @@ -60,9 +60,9 @@ pub fn main() { "foo"); let out_p = Path::new(out_path); out_p.as_str().unwrap().to_owned() - }; + }); out_path - }; + }); let out_lib_path = Path::new(out_lib_path); debug!("out_lib_path = {}", out_lib_path.display()); context.add_library_path(out_lib_path.dir_path()); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index befb6aaa21809..9842508a5c320 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -81,21 +81,19 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &CrateSetup) -> ast::_mod { fn strip_main(item: @ast::item) -> @ast::item { @ast::item { - attrs: do item.attrs.iter().filter_map |attr| { + attrs: item.attrs.iter().filter_map(|attr| { if "main" != attr.name() { Some(*attr) } else { None } - }.collect(), + }).collect(), .. (*item).clone() } } fold::noop_fold_mod(&ast::_mod { - items: do m.items.map |item| { - strip_main(*item) - }, + items: m.items.map(|item| strip_main(*item)), .. (*m).clone() }, fold) } @@ -493,21 +491,21 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> { // and the `PkgSrc` constructor will detect that; // or else it's already in a workspace and we'll build into that // workspace - let pkg_src = do cond.trap(|_| { + let pkg_src = cond.trap(|_| { // Nonexistent package? Then print a better error error(format!("Package {} depends on {}, but I don't know \ how to find it", self.parent.path.display(), pkg_id.path.display())); fail!() - }).inside { + }).inside(|| { PkgSrc::new(source_workspace.clone(), dest_workspace.clone(), // Use the rust_path_hack to search for dependencies iff // we were already using it self.context.context.use_rust_path_hack, pkg_id.clone()) - }; + }); let (outputs_disc, inputs_disc) = self.context.install( pkg_src, From f571e46ddb696d15a8cc912309714ca74f23dcc4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Nov 2013 17:23:21 -0800 Subject: [PATCH 08/12] test: Remove non-procedure uses of `do` from compiletest, libstd tests, compile-fail tests, run-fail tests, and run-pass tests. --- src/compiletest/compiletest.rs | 4 +- src/compiletest/header.rs | 12 ++--- src/compiletest/procsrv.rs | 4 +- src/compiletest/runtest.rs | 4 +- src/libstd/at_vec.rs | 36 ++++++++++----- src/libstd/bool.rs | 12 ++--- src/libstd/cell.rs | 1 - src/libstd/char.rs | 4 +- src/libstd/condition.rs | 36 +++++++-------- src/libstd/io/buffered.rs | 12 ++--- src/libstd/io/extensions.rs | 32 ++++++------- src/libstd/io/mem.rs | 6 +-- src/libstd/io/net/tcp.rs | 44 +++++++++--------- src/libstd/io/net/udp.rs | 6 +-- src/libstd/io/net/unix.rs | 26 +++++------ src/libstd/io/option.rs | 24 +++++----- src/libstd/iter.rs | 4 +- src/libstd/local_data.rs | 40 ++++++++--------- src/libstd/num/strconv.rs | 8 ++-- src/libstd/num/uint.rs | 2 +- src/libstd/option.rs | 4 +- src/libstd/path/posix.rs | 45 +++++++++---------- src/libstd/path/windows.rs | 44 +++++++++--------- src/libstd/ptr.rs | 44 +++++++++--------- src/libstd/rand/distributions/gamma.rs | 8 ++-- src/libstd/rand/distributions/mod.rs | 8 ++-- src/libstd/rand/mod.rs | 20 ++++----- src/libstd/result.rs | 12 ++--- src/libstd/rt/comm.rs | 18 ++++---- src/libstd/rt/crate_map.rs | 12 ++--- src/libstd/rt/global_heap.rs | 8 ++-- src/libstd/rt/local.rs | 4 +- src/libstd/rt/local_heap.rs | 4 +- src/libstd/rt/sched.rs | 18 ++++---- src/libstd/rt/tube.rs | 16 +++---- src/libstd/select.rs | 6 +-- src/libstd/str.rs | 12 +++-- src/libstd/task/mod.rs | 32 ++++++------- src/libstd/unstable/finally.rs | 20 ++++----- src/libstd/util.rs | 16 +++---- src/libstd/vec.rs | 8 +++- src/test/auxiliary/xc_conditions_3.rs | 4 +- .../arc-rw-cond-shouldnt-escape.rs | 4 +- .../arc-rw-read-mode-shouldnt-escape.rs | 4 +- .../arc-rw-state-shouldnt-escape.rs | 4 +- .../arc-rw-write-mode-cond-shouldnt-escape.rs | 8 ++-- .../arc-rw-write-mode-shouldnt-escape.rs | 4 +- .../block-arg-as-stmt-with-value.rs | 22 --------- .../compile-fail/borrowck-assign-comp-idx.rs | 4 +- .../compile-fail/borrowck-autoref-3261.rs | 4 +- .../borrowck-insert-during-each.rs | 4 +- .../compile-fail/borrowck-lend-flow-loop.rs | 4 +- .../borrowck-loan-blocks-mut-uniq.rs | 4 +- src/test/compile-fail/borrowck-loan-rcvr.rs | 8 ++-- .../compile-fail/borrowck-loan-vec-content.rs | 7 ++- src/test/compile-fail/break-outside-loop.rs | 4 +- ...ure-bounds-static-cant-capture-borrowed.rs | 4 +- src/test/compile-fail/do2.rs | 2 +- .../compile-fail/lint-unused-mut-variables.rs | 4 +- src/test/compile-fail/lint-unused-unsafe.rs | 6 +-- .../moves-based-on-type-block-bad.rs | 4 +- ...ased-on-type-no-recursive-stack-closure.rs | 4 +- src/test/compile-fail/mutex-arc-nested.rs | 4 +- .../once-cant-call-twice-on-stack.rs | 4 +- ...once-cant-move-out-of-non-once-on-stack.rs | 4 +- src/test/compile-fail/regions-freevar.rs | 4 +- src/test/compile-fail/regions-infer-call-3.rs | 2 +- .../compile-fail/sync-cond-shouldnt-escape.rs | 4 +- .../sync-rwlock-cond-shouldnt-escape.rs | 4 +- .../sync-rwlock-read-mode-shouldnt-escape.rs | 4 +- ...-rwlock-write-mode-cond-shouldnt-escape.rs | 8 ++-- .../sync-rwlock-write-mode-shouldnt-escape.rs | 4 +- .../bug-2470-bounds-check-overflow.rs | 4 +- src/test/run-pass/assignability-trait.rs | 9 ++-- src/test/run-pass/bitv-perf-test.rs | 2 +- .../block-arg-can-be-followed-by-binop.rs | 10 +++-- .../block-arg-can-be-followed-by-block-arg.rs | 9 ++-- .../block-arg-can-be-followed-by-call.rs | 8 ++-- src/test/run-pass/block-arg-in-parentheses.rs | 29 ++++++------ src/test/run-pass/block-arg-used-as-any.rs | 2 +- src/test/run-pass/block-arg.rs | 43 +++++++++++------- .../borrowck-borrow-from-expr-block.rs | 4 +- src/test/run-pass/borrowck-mut-uniq.rs | 4 +- .../borrowck-preserve-box-in-field.rs | 4 +- .../run-pass/borrowck-preserve-box-in-uniq.rs | 4 +- src/test/run-pass/borrowck-preserve-box.rs | 4 +- .../run-pass/borrowck-preserve-expl-deref.rs | 4 +- src/test/run-pass/cci_impl_exe.rs | 4 +- src/test/run-pass/cci_iter_exe.rs | 4 +- src/test/run-pass/cci_no_inline_exe.rs | 4 +- src/test/run-pass/core-run-destroy.rs | 4 +- .../run-pass/deriving-encodable-decodable.rs | 4 +- src/test/run-pass/deriving-rand.rs | 4 +- src/test/run-pass/do-empty-args.rs | 2 +- src/test/run-pass/do-no-args.rs | 4 +- src/test/run-pass/do-pure.rs | 20 --------- src/test/run-pass/do-stack.rs | 15 ------- src/test/run-pass/do1.rs | 2 +- src/test/run-pass/do2.rs | 2 +- src/test/run-pass/do3.rs | 2 +- src/test/run-pass/extern-stress.rs | 4 +- src/test/run-pass/extern-yield.rs | 4 +- src/test/run-pass/foreach-nested.rs | 6 +-- src/test/run-pass/foreach-put-structured.rs | 4 +- .../run-pass/foreach-simple-outer-slot.rs | 2 +- src/test/run-pass/foreign-fn-linkname.rs | 4 +- src/test/run-pass/issue-1458.rs | 22 --------- src/test/run-pass/issue-2487-a.rs | 4 +- src/test/run-pass/issue-2804.rs | 4 +- src/test/run-pass/issue-3211.rs | 4 +- src/test/run-pass/issue-3563-3.rs | 10 ++--- src/test/run-pass/issue-4401.rs | 4 +- .../issue-5321-immediates-with-bare-self.rs | 4 +- src/test/run-pass/issue-6153.rs | 2 +- .../match-ref-binding-in-guard-3256.rs | 2 +- src/test/run-pass/newlambdas.rs | 4 +- src/test/run-pass/once-move-out-on-stack.rs | 4 +- src/test/run-pass/reflect-visit-data.rs | 16 ++----- src/test/run-pass/regions-infer-call-2.rs | 2 +- src/test/run-pass/rename-directory.rs | 12 ++--- src/test/run-pass/trait-bounds-in-arc.rs | 4 +- src/test/run-pass/type-params-in-for-each.rs | 4 +- src/test/run-pass/variadic-ffi.rs | 24 +++++----- src/test/run-pass/writealias.rs | 2 +- src/test/run-pass/xc_conditions_client.rs | 4 +- src/test/run-pass/xc_conditions_client_2.rs | 4 +- src/test/run-pass/xc_conditions_client_4.rs | 4 +- src/test/run-pass/xcrate-static-addresses.rs | 6 +-- 128 files changed, 575 insertions(+), 637 deletions(-) delete mode 100644 src/test/compile-fail/block-arg-as-stmt-with-value.rs delete mode 100644 src/test/run-pass/do-pure.rs delete mode 100644 src/test/run-pass/do-stack.rs delete mode 100644 src/test/run-pass/issue-1458.rs diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 9c8fdafe9ad10..65f733cf1dec3 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -266,12 +266,12 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] { let file = file.clone(); debug!("inspecting file {}", file.display()); if is_test(config, &file) { - let t = do make_test(config, &file) { + let t = make_test(config, &file, || { match config.mode { mode_codegen => make_metrics_test_closure(config, &file), _ => make_test_closure(config, &file) } - }; + }); tests.push(t) } } diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index f722f873d5e67..1966701dbdedd 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -39,7 +39,7 @@ pub fn load_props(testfile: &Path) -> TestProps { let mut pp_exact = None; let mut debugger_cmds = ~[]; let mut check_lines = ~[]; - do iter_header(testfile) |ln| { + iter_header(testfile, |ln| { match parse_error_pattern(ln) { Some(ep) => error_patterns.push(ep), None => () @@ -74,7 +74,7 @@ pub fn load_props(testfile: &Path) -> TestProps { }; true - }; + }); return TestProps { error_patterns: error_patterns, compile_flags: compile_flags, @@ -91,13 +91,13 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool { ~"xfail-" + util::get_os(config.target) } - let val = do iter_header(testfile) |ln| { + let val = iter_header(testfile, |ln| { if parse_name_directive(ln, "xfail-test") { false } else if parse_name_directive(ln, xfail_target(config)) { false } else if config.mode == common::mode_pretty && parse_name_directive(ln, "xfail-pretty") { false } else { true } - }; + }); !val } @@ -143,7 +143,7 @@ fn parse_check_line(line: &str) -> Option<~str> { } fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { - do parse_name_value_directive(line, ~"exec-env").map |nv| { + parse_name_value_directive(line, ~"exec-env").map(|nv| { // nv is either FOO or FOO=BAR let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect(); @@ -155,7 +155,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { } n => fail!("Expected 1 or 2 strings, not {}", n) } - } + }) } fn parse_pp_exact(line: &str, testfile: &Path) -> Option { diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index e107c53018def..012d57da123cf 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -22,11 +22,11 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] { assert!(prog.ends_with(".exe")); let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux"; - env = do env.map() |pair| { + env = env.map(|pair| { let (k,v) = (*pair).clone(); if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) } else { (k,v) } - }; + }); if prog.ends_with("rustc.exe") { env.push((~"RUST_THREADS", ~"1")); } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 7104a506fccc5..4c7b212304ceb 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -427,9 +427,9 @@ fn check_error_patterns(props: &TestProps, testfile: &Path, ProcRes: &ProcRes) { if props.error_patterns.is_empty() { - do testfile.display().with_str |s| { + testfile.display().with_str(|s| { fatal(~"no error pattern specified in " + s); - } + }) } if ProcRes.status.success() { diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 4405d5be3886b..2b105a3fa7d23 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -333,47 +333,57 @@ mod test { #[bench] fn bench_capacity(b: &mut bh) { let x = @[1, 2, 3]; - b.iter(|| capacity(x)); + b.iter(|| { + let _ = capacity(x); + }); } #[bench] fn bench_build_sized(b: &mut bh) { let len = 64; - do b.iter { + b.iter(|| { build(Some(len), |push| for i in range(0, 1024) { push(i) }); - } + }); } #[bench] fn bench_build(b: &mut bh) { - do b.iter { + b.iter(|| { for i in range(0, 95) { build(None, |push| push(i)); } - } + }); } #[bench] fn bench_append(b: &mut bh) { let lhs = @[7, ..128]; let rhs = range(0, 256).to_owned_vec(); - b.iter(|| append(lhs, rhs)) + b.iter(|| { + let _ = append(lhs, rhs); + }) } #[bench] fn bench_map(b: &mut bh) { let elts = range(0, 256).to_owned_vec(); - b.iter(|| map(elts, |x| x*2)) + b.iter(|| { + let _ = map(elts, |x| x*2); + }) } #[bench] fn bench_from_fn(b: &mut bh) { - b.iter(|| from_fn(1024, |x| x)); + b.iter(|| { + let _ = from_fn(1024, |x| x); + }); } #[bench] fn bench_from_elem(b: &mut bh) { - b.iter(|| from_elem(1024, 0u64)); + b.iter(|| { + let _ = from_elem(1024, 0u64); + }); } #[bench] @@ -387,12 +397,16 @@ mod test { #[bench] fn bench_to_managed(b: &mut bh) { let elts = range(0, 1024).to_owned_vec(); - b.iter(|| to_managed(elts)); + b.iter(|| { + let _ = to_managed(elts); + }); } #[bench] fn bench_clone(b: &mut bh) { let elts = to_managed(range(0, 1024).to_owned_vec()); - b.iter(|| elts.clone()); + b.iter(|| { + let _ = elts.clone(); + }); } } diff --git a/src/libstd/bool.rs b/src/libstd/bool.rs index ce0a669659623..29c304f9ac539 100644 --- a/src/libstd/bool.rs +++ b/src/libstd/bool.rs @@ -53,9 +53,9 @@ use num::FromPrimitive; /// # Examples /// /// ``` -/// do std::bool::all_values |x: bool| { +/// std::bool::all_values(|x: bool| { /// println(x.to_str()); -/// } +/// }) /// ``` #[inline] pub fn all_values(blk: |v: bool|) { @@ -396,9 +396,9 @@ mod tests { #[test] fn test_bool_from_str() { - do all_values |v| { + all_values(|v| { assert!(Some(v) == FromStr::from_str(v.to_str())) - } + }); } #[test] @@ -409,11 +409,11 @@ mod tests { #[test] fn test_bool_to_bit() { - do all_values |v| { + all_values(|v| { assert_eq!(v.to_bit::(), if v { 1u8 } else { 0u8 }); assert_eq!(v.to_bit::(), if v { 1u } else { 0u }); assert_eq!(v.to_bit::(), if v { 1i } else { 0i }); - } + }); } #[test] diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 634558b9b971d..e49cf3e5303b3 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -82,7 +82,6 @@ pub struct RefCell { priv nc: NonCopyable } -<<<<<<< HEAD // Values [1, MAX-1] represent the number of `Ref` active // (will not outgrow its range since `uint` is the size of the address space) type BorrowFlag = uint; diff --git a/src/libstd/char.rs b/src/libstd/char.rs index c5a4dd1631df9..b372993e3e506 100644 --- a/src/libstd/char.rs +++ b/src/libstd/char.rs @@ -532,7 +532,7 @@ fn test_is_digit() { fn test_escape_default() { fn string(c: char) -> ~str { let mut result = ~""; - do escape_default(c) |c| { result.push_char(c); } + escape_default(c, |c| { result.push_char(c); }); return result; } assert_eq!(string('\n'), ~"\\n"); @@ -554,7 +554,7 @@ fn test_escape_default() { fn test_escape_unicode() { fn string(c: char) -> ~str { let mut result = ~""; - do escape_unicode(c) |c| { result.push_char(c); } + escape_unicode(c, |c| { result.push_char(c); }); return result; } assert_eq!(string('\x00'), ~"\\x00"); diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 03994043dcf0c..80ff104e8303e 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -224,14 +224,14 @@ mod test { fn nested_trap_test_inner() { let mut inner_trapped = false; - do sadness::cond.trap(|_j| { + sadness::cond.trap(|_j| { debug!("nested_trap_test_inner: in handler"); inner_trapped = true; 0 - }).inside { + }).inside(|| { debug!("nested_trap_test_inner: in protected block"); trouble(1); - } + }); assert!(inner_trapped); } @@ -240,14 +240,14 @@ mod test { fn nested_trap_test_outer() { let mut outer_trapped = false; - do sadness::cond.trap(|_j| { + sadness::cond.trap(|_j| { debug!("nested_trap_test_outer: in handler"); outer_trapped = true; 0 - }).inside { + }).inside(|| { debug!("nested_guard_test_outer: in protected block"); nested_trap_test_inner(); trouble(1); - } + }); assert!(outer_trapped); } @@ -255,16 +255,16 @@ mod test { fn nested_reraise_trap_test_inner() { let mut inner_trapped = false; - do sadness::cond.trap(|_j| { + sadness::cond.trap(|_j| { debug!("nested_reraise_trap_test_inner: in handler"); inner_trapped = true; let i = 10; debug!("nested_reraise_trap_test_inner: handler re-raising"); sadness::cond.raise(i) - }).inside { + }).inside(|| { debug!("nested_reraise_trap_test_inner: in protected block"); trouble(1); - } + }); assert!(inner_trapped); } @@ -273,13 +273,13 @@ mod test { fn nested_reraise_trap_test_outer() { let mut outer_trapped = false; - do sadness::cond.trap(|_j| { + sadness::cond.trap(|_j| { debug!("nested_reraise_trap_test_outer: in handler"); outer_trapped = true; 0 - }).inside { + }).inside(|| { debug!("nested_reraise_trap_test_outer: in protected block"); nested_reraise_trap_test_inner(); - } + }); assert!(outer_trapped); } @@ -288,13 +288,13 @@ mod test { fn test_default() { let mut trapped = false; - do sadness::cond.trap(|j| { + sadness::cond.trap(|j| { debug!("test_default: in handler"); sadness::cond.raise_default(j, || { trapped=true; 5 }) - }).inside { + }).inside(|| { debug!("test_default: in protected block"); trouble(1); - } + }); assert!(trapped); } @@ -312,12 +312,12 @@ mod test { #[test] fn test_conditions_are_public() { let mut trapped = false; - do sadness::cond.trap(|_| { + sadness::cond.trap(|_| { trapped = true; 0 - }).inside { + }).inside(|| { sadness::cond.raise(0); - } + }); assert!(trapped); } } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index d74acb5f59baa..8c1897339cbef 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -438,22 +438,22 @@ mod test { #[bench] fn bench_buffered_reader(bh: &mut Harness) { - do bh.iter { + bh.iter(|| { BufferedReader::new(NullStream); - } + }); } #[bench] fn bench_buffered_writer(bh: &mut Harness) { - do bh.iter { + bh.iter(|| { BufferedWriter::new(NullStream); - } + }); } #[bench] fn bench_buffered_stream(bh: &mut Harness) { - do bh.iter { + bh.iter(|| { BufferedStream::new(NullStream); - } + }); } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 5eb2e72e96b21..564e664027f73 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -276,11 +276,11 @@ mod test { #[test] fn read_byte_error() { let mut reader = ErroringReader; - do io_error::cond.trap(|_| { - }).inside { + io_error::cond.trap(|_| { + }).inside(|| { let byte = reader.read_byte(); assert!(byte == None); - } + }); } #[test] @@ -303,10 +303,10 @@ mod test { fn bytes_error() { let reader = ErroringReader; let mut it = reader.bytes(); - do io_error::cond.trap(|_| ()).inside { + io_error::cond.trap(|_| ()).inside(|| { let byte = it.next(); assert!(byte == None); - } + }) } #[test] @@ -328,10 +328,10 @@ mod test { #[test] fn read_bytes_eof() { let mut reader = MemReader::new(~[10, 11]); - do io_error::cond.trap(|_| { - }).inside { + io_error::cond.trap(|_| { + }).inside(|| { assert!(reader.read_bytes(4) == ~[10, 11]); - } + }) } #[test] @@ -356,11 +356,11 @@ mod test { fn push_bytes_eof() { let mut reader = MemReader::new(~[10, 11]); let mut buf = ~[8, 9]; - do io_error::cond.trap(|_| { - }).inside { + io_error::cond.trap(|_| { + }).inside(|| { reader.push_bytes(&mut buf, 4); assert!(buf == ~[8, 9, 10, 11]); - } + }) } #[test] @@ -369,9 +369,9 @@ mod test { count: 0, }; let mut buf = ~[8, 9]; - do io_error::cond.trap(|_| { } ).inside { + io_error::cond.trap(|_| { } ).inside(|| { reader.push_bytes(&mut buf, 4); - } + }); assert!(buf == ~[8, 9, 10]); } @@ -384,13 +384,13 @@ mod test { count: 0, }; let buf = @mut ~[8, 9]; - do (|| { + (|| { reader.push_bytes(&mut *buf, 4); - }).finally { + }).finally(|| { // NB: Using rtassert here to trigger abort on failure since this is a should_fail test // FIXME: #7049 This fails because buf is still borrowed //rtassert!(*buf == ~[8, 9, 10]); - } + }) } #[test] diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index decdfb60bfbe5..b08f4af9a54c6 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -331,12 +331,12 @@ mod test { writer.write([0]); let mut called = false; - do io_error::cond.trap(|err| { + io_error::cond.trap(|err| { assert_eq!(err.kind, OtherIoError); called = true; - }).inside { + }).inside(|| { writer.write([0, 0]); - } + }); assert!(called); } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index ac099e67f795f..aa7a64d221074 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -157,14 +157,14 @@ mod test { fn bind_error() { do run_in_mt_newsched_task { let mut called = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { assert!(e.kind == PermissionDenied); called = true; - }).inside { + }).inside(|| { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let listener = TcpListener::bind(addr); assert!(listener.is_none()); - } + }); assert!(called); } } @@ -173,7 +173,7 @@ mod test { fn connect_error() { do run_in_mt_newsched_task { let mut called = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { let expected_error = if cfg!(unix) { ConnectionRefused } else { @@ -182,11 +182,11 @@ mod test { }; assert_eq!(e.kind, expected_error); called = true; - }).inside { + }).inside(|| { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let stream = TcpStream::connect(addr); assert!(stream.is_none()); - } + }); assert!(called); } } @@ -306,16 +306,16 @@ mod test { let mut buf = [0]; let nread = stream.read(buf); assert!(nread.is_none()); - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { if cfg!(windows) { assert_eq!(e.kind, NotConnected); } else { fail!(); } - }).inside { + }).inside(|| { let nread = stream.read(buf); assert!(nread.is_none()); - } + }) } do spawntask { @@ -341,16 +341,16 @@ mod test { let mut buf = [0]; let nread = stream.read(buf); assert!(nread.is_none()); - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { if cfg!(windows) { assert_eq!(e.kind, NotConnected); } else { fail!(); } - }).inside { + }).inside(|| { let nread = stream.read(buf); assert!(nread.is_none()); - } + }) } do spawntask { @@ -376,7 +376,7 @@ mod test { let buf = [0]; loop { let mut stop = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { // NB: ECONNRESET on linux, EPIPE on mac, ECONNABORTED // on windows assert!(e.kind == ConnectionReset || @@ -384,9 +384,9 @@ mod test { e.kind == ConnectionAborted, "unknown error: {:?}", e); stop = true; - }).inside { + }).inside(|| { stream.write(buf); - } + }); if stop { break } } } @@ -414,7 +414,7 @@ mod test { let buf = [0]; loop { let mut stop = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { // NB: ECONNRESET on linux, EPIPE on mac, ECONNABORTED // on windows assert!(e.kind == ConnectionReset || @@ -422,9 +422,9 @@ mod test { e.kind == ConnectionAborted, "unknown error: {:?}", e); stop = true; - }).inside { + }).inside(|| { stream.write(buf); - } + }); if stop { break } } } @@ -458,10 +458,10 @@ mod test { do spawntask { port.take().recv(); - do max.times { + max.times(|| { let mut stream = TcpStream::connect(addr); stream.write([99]); - } + }); } } } @@ -487,10 +487,10 @@ mod test { do spawntask { port.take().recv(); - do max.times { + max.times(|| { let mut stream = TcpStream::connect(addr); stream.write([99]); - } + }); } } } diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 38def44d9d0e9..f02fc1ae4471c 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -116,14 +116,14 @@ mod test { fn bind_error() { do run_in_mt_newsched_task { let mut called = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { assert!(e.kind == PermissionDenied); called = true; - }).inside { + }).inside(|| { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let socket = UdpSocket::bind(addr); assert!(socket.is_none()); - } + }); assert!(called); } } diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index eb86f0ef97fe3..809473d64c68e 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -186,13 +186,13 @@ mod tests { fn bind_error() { do run_in_mt_newsched_task { let mut called = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { assert!(e.kind == PermissionDenied); called = true; - }).inside { + }).inside(|| { let listener = UnixListener::bind(&("path/to/nowhere")); assert!(listener.is_none()); - } + }); assert!(called); } } @@ -201,13 +201,13 @@ mod tests { fn connect_error() { do run_in_mt_newsched_task { let mut called = false; - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { assert_eq!(e.kind, OtherIoError); called = true; - }).inside { + }).inside(|| { let stream = UnixStream::connect(&("path/to/nowhere")); assert!(stream.is_none()); - } + }); assert!(called); } } @@ -240,13 +240,13 @@ mod tests { let buf = [0]; let mut stop = false; while !stop{ - do io_error::cond.trap(|e| { + io_error::cond.trap(|e| { assert!(e.kind == BrokenPipe || e.kind == NotConnected, "unknown error {:?}", e); stop = true; - }).inside { + }).inside(|| { server.write(buf); - } + }) } }, |_client| { // drop the client @@ -266,20 +266,20 @@ mod tests { do spawntask { let mut acceptor = UnixListener::bind(&path1).listen(); chan.take().send(()); - do times.times { + times.times(|| { let mut client = acceptor.accept(); let mut buf = [0]; client.read(buf); assert_eq!(buf[0], 100); - } + }) } do spawntask { port.take().recv(); - do times.times { + times.times(|| { let mut stream = UnixStream::connect(&path2); stream.write([100]); - } + }) } } } diff --git a/src/libstd/io/option.rs b/src/libstd/io/option.rs index 5938252571f51..61c5411f3602f 100644 --- a/src/libstd/io/option.rs +++ b/src/libstd/io/option.rs @@ -125,21 +125,21 @@ mod test { let mut writer: Option = None; let mut called = false; - do io_error::cond.trap(|err| { + io_error::cond.trap(|err| { assert_eq!(err.kind, PreviousIoError); called = true; - }).inside { + }).inside(|| { writer.write([0, 0, 0]); - } + }); assert!(called); let mut called = false; - do io_error::cond.trap(|err| { + io_error::cond.trap(|err| { assert_eq!(err.kind, PreviousIoError); called = true; - }).inside { + }).inside(|| { writer.flush(); - } + }); assert!(called); } } @@ -161,21 +161,21 @@ mod test { let mut buf = []; let mut called = false; - do io_error::cond.trap(|err| { + io_error::cond.trap(|err| { assert_eq!(err.kind, PreviousIoError); called = true; - }).inside { + }).inside(|| { reader.read(buf); - } + }); assert!(called); let mut called = false; - do io_error::cond.trap(|err| { + io_error::cond.trap(|err| { assert_eq!(err.kind, PreviousIoError); called = true; - }).inside { + }).inside(|| { assert!(reader.eof()); - } + }); assert!(called); } } diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index b1958bde60d2a..75a7d5db1321e 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2674,13 +2674,13 @@ mod tests { fn test_rposition_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do v.iter().rposition |_elt| { + v.iter().rposition(|_elt| { if i == 2 { fail!() } i += 1; false - }; + }); } diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 89907c7434cdf..335bbc8b1da30 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -479,19 +479,19 @@ mod tests { static key: Key<~int> = &Key; set(key, ~1); - do get(key) |v| { - do get(key) |v| { - do get(key) |v| { + get(key, |v| { + get(key, |v| { + get(key, |v| { assert_eq!(**v.unwrap(), 1); - } + }); assert_eq!(**v.unwrap(), 1); - } + }); assert_eq!(**v.unwrap(), 1); - } + }); set(key, ~2); - do get(key) |v| { + get(key, |v| { assert_eq!(**v.unwrap(), 2); - } + }) } #[test] @@ -499,13 +499,13 @@ mod tests { static key: Key = &Key; set(key, 1); - do get_mut(key) |v| { + get_mut(key, |v| { *v.unwrap() = 2; - } + }); - do get(key) |v| { + get(key, |v| { assert_eq!(*v.unwrap(), 2); - } + }) } #[test] @@ -533,9 +533,9 @@ mod tests { fn test_nested_get_set1() { static key: Key = &Key; set(key, 4); - do get(key) |_| { + get(key, |_| { set(key, 4); - } + }) } #[test] @@ -543,9 +543,9 @@ mod tests { fn test_nested_get_mut2() { static key: Key = &Key; set(key, 4); - do get(key) |_| { + get(key, |_| { get_mut(key, |_| {}) - } + }) } #[test] @@ -553,9 +553,9 @@ mod tests { fn test_nested_get_mut3() { static key: Key = &Key; set(key, 4); - do get_mut(key) |_| { + get_mut(key, |_| { get(key, |_| {}) - } + }) } #[test] @@ -563,8 +563,8 @@ mod tests { fn test_nested_get_mut4() { static key: Key = &Key; set(key, 4); - do get_mut(key) |_| { + get_mut(key, |_| { get_mut(key, |_| {}) - } + }) } } diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 5d713f1a622cc..1028cef9dc647 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -750,16 +750,16 @@ mod bench { #[bench] fn uint_to_str_rand(bh: &mut BenchHarness) { let mut rng = XorShiftRng::new(); - do bh.iter { + bh.iter(|| { rng.gen::().to_str(); - } + }) } #[bench] fn float_to_str_rand(bh: &mut BenchHarness) { let mut rng = XorShiftRng::new(); - do bh.iter { + bh.iter(|| { f64::to_str(rng.gen()); - } + }) } } diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 1cc0c19150137..cf7047bd068a0 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -244,6 +244,6 @@ pub fn test_times() { use num::Times; let ten = 10 as uint; let mut accum = 0; - do ten.times { accum += 1; } + ten.times(|| { accum += 1; }); assert!((accum == 10)); } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index c5a10c75640ec..715072653a7ab 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -612,14 +612,14 @@ mod tests { #[test] fn test_option_while_some() { let mut i = 0; - do Some(10).while_some |j| { + Some(10).while_some(|j| { i += 1; if (j > 0) { Some(j-1) } else { None } - } + }); assert_eq!(i, 11); } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index dcd0829533174..ddfb43ed56f87 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -523,35 +523,35 @@ mod tests { use path::null_byte::cond; let mut handled = false; - let mut p = do cond.trap(|v| { + let mut p = cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("foo/bar", 0)); (b!("/bar").to_owned()) - }).inside { + }).inside(|| { Path::new(b!("foo/bar", 0)) - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("/bar")); handled = false; - do cond.trap(|v| { + cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("f", 0, "o")); (b!("foo").to_owned()) - }).inside { + }).inside(|| { p.set_filename(b!("f", 0, "o")) - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("/foo")); handled = false; - do cond.trap(|v| { + cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("f", 0, "o")); (b!("foo").to_owned()) - }).inside { + }).inside(|| { p.push(b!("f", 0, "o")); - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("/foo/foo")); } @@ -573,29 +573,29 @@ mod tests { ) t!(~"new() w/nul" => { - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { Path::new(b!("foo/bar", 0)) - }; + }); }) t!(~"set_filename w/nul" => { let mut p = Path::new(b!("foo/bar")); - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { p.set_filename(b!("foo", 0)) - }; + }); }) t!(~"push w/nul" => { let mut p = Path::new(b!("foo/bar")); - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { p.push(b!("foo", 0)) - }; + }); }) } @@ -621,10 +621,10 @@ mod tests { { let mut called = false; let path = Path::new($path); - do path.display().with_str |s| { + path.display().with_str(|s| { assert_eq!(s, $exp); called = true; - }; + }); assert!(called); } ); @@ -632,11 +632,10 @@ mod tests { { let mut called = false; let path = Path::new($path); - do path.filename_display().with_str |s| { + path.filename_display().with_str(|s| { assert_eq!(s, $exp); called = true; - - }; + }); assert!(called); } ) diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 4e736458fd8f2..cc2af54fd105c 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1248,35 +1248,35 @@ mod tests { use path::null_byte::cond; let mut handled = false; - let mut p = do cond.trap(|v| { + let mut p = cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("foo\\bar", 0)); (b!("\\bar").to_owned()) - }).inside { + }).inside(|| { Path::new(b!("foo\\bar", 0)) - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("\\bar")); handled = false; - do cond.trap(|v| { + cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("f", 0, "o")); (b!("foo").to_owned()) - }).inside { + }).inside(|| { p.set_filename(b!("f", 0, "o")) - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("\\foo")); handled = false; - do cond.trap(|v| { + cond.trap(|v| { handled = true; assert_eq!(v.as_slice(), b!("f", 0, "o")); (b!("foo").to_owned()) - }).inside { + }).inside(|| { p.push(b!("f", 0, "o")); - }; + }); assert!(handled); assert_eq!(p.as_vec(), b!("\\foo\\foo")); } @@ -1298,29 +1298,29 @@ mod tests { ) t!(~"from_vec() w\\nul" => { - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { Path::new(b!("foo\\bar", 0)) - }; + }); }) t!(~"set_filename w\\nul" => { let mut p = Path::new(b!("foo\\bar")); - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { p.set_filename(b!("foo", 0)) - }; + }); }) t!(~"push w\\nul" => { let mut p = Path::new(b!("foo\\bar")); - do cond.trap(|_| { + cond.trap(|_| { (b!("null", 0).to_owned()) - }).inside { + }).inside(|| { p.push(b!("foo", 0)) - }; + }); }) } @@ -1339,17 +1339,17 @@ mod tests { let mut called = false; let path = Path::new("foo"); - do path.display().with_str |s| { + path.display().with_str(|s| { assert_eq!(s, "foo"); called = true; - }; + }); assert!(called); called = false; let path = Path::new(b!("\\")); - do path.filename_display().with_str |s| { + path.filename_display().with_str(|s| { assert_eq!(s, ""); called = true; - } + }); assert!(called); } diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 9f60c3a32b266..9b9636af901f2 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -492,28 +492,28 @@ pub mod ptr_tests { fn test_position() { use libc::c_char; - do "hello".with_c_str |p| { + "hello".with_c_str(|p| { unsafe { assert!(2u == position(p, |c| *c == 'l' as c_char)); assert!(4u == position(p, |c| *c == 'o' as c_char)); assert!(5u == position(p, |c| *c == 0 as c_char)); } - } + }) } #[test] fn test_buf_len() { - do "hello".with_c_str |p0| { - do "there".with_c_str |p1| { - do "thing".with_c_str |p2| { + "hello".with_c_str(|p0| { + "there".with_c_str(|p1| { + "thing".with_c_str(|p2| { let v = ~[p0, p1, p2, null()]; - do v.as_imm_buf |vp, len| { + v.as_imm_buf(|vp, len| { assert_eq!(unsafe { buf_len(vp) }, 3u); assert_eq!(len, 4u); - } - } - } - } + }) + }) + }) + }) } #[test] @@ -621,23 +621,23 @@ pub mod ptr_tests { one, two, three ]; - do arr.as_imm_buf |arr_ptr, arr_len| { + arr.as_imm_buf(|arr_ptr, arr_len| { let mut ctr = 0; let mut iteration_count = 0; - do array_each_with_len(arr_ptr, arr_len) |e| { + array_each_with_len(arr_ptr, arr_len, |e| { let actual = str::raw::from_c_str(e); - let expected = do expected_arr[ctr].with_ref |buf| { + let expected = expected_arr[ctr].with_ref(|buf| { str::raw::from_c_str(buf) - }; + }); debug!( "test_ptr_array_each_with_len e: {}, a: {}", expected, actual); assert_eq!(actual, expected); ctr += 1; iteration_count += 1; - } + }); assert_eq!(iteration_count, 3u); - } + }) } } @@ -658,23 +658,23 @@ pub mod ptr_tests { one, two, three ]; - do arr.as_imm_buf |arr_ptr, _| { + arr.as_imm_buf(|arr_ptr, _| { let mut ctr = 0; let mut iteration_count = 0; - do array_each(arr_ptr) |e| { + array_each(arr_ptr, |e| { let actual = str::raw::from_c_str(e); - let expected = do expected_arr[ctr].with_ref |buf| { + let expected = expected_arr[ctr].with_ref(|buf| { str::raw::from_c_str(buf) - }; + }); debug!( "test_ptr_array_each e: {}, a: {}", expected, actual); assert_eq!(actual, expected); ctr += 1; iteration_count += 1; - } + }); assert_eq!(iteration_count, 3); - } + }) } } diff --git a/src/libstd/rand/distributions/gamma.rs b/src/libstd/rand/distributions/gamma.rs index 7e8c193cb777e..e042874245967 100644 --- a/src/libstd/rand/distributions/gamma.rs +++ b/src/libstd/rand/distributions/gamma.rs @@ -184,11 +184,11 @@ mod bench { let gamma = Gamma::new(10., 1.0); let mut rng = StdRng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { gamma.ind_sample(&mut rng); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } @@ -197,11 +197,11 @@ mod bench { let gamma = Gamma::new(0.1, 1.0); let mut rng = StdRng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { gamma.ind_sample(&mut rng); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } } diff --git a/src/libstd/rand/distributions/mod.rs b/src/libstd/rand/distributions/mod.rs index 247a7824a4465..4778e81f95169 100644 --- a/src/libstd/rand/distributions/mod.rs +++ b/src/libstd/rand/distributions/mod.rs @@ -571,11 +571,11 @@ mod bench { let mut rng = XorShiftRng::new(); let mut normal = Normal::new(-2.71828, 3.14159); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { normal.sample(&mut rng); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } #[bench] @@ -583,11 +583,11 @@ mod bench { let mut rng = XorShiftRng::new(); let mut exp = Exp::new(2.71828 * 3.14159); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { exp.sample(&mut rng); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 39b4cca206358..ae53ef8b7c0b1 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -899,44 +899,44 @@ mod bench { #[bench] fn rand_xorshift(bh: &mut BenchHarness) { let mut rng = XorShiftRng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { rng.gen::(); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } #[bench] fn rand_isaac(bh: &mut BenchHarness) { let mut rng = IsaacRng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { rng.gen::(); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } #[bench] fn rand_isaac64(bh: &mut BenchHarness) { let mut rng = Isaac64Rng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { rng.gen::(); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } #[bench] fn rand_std(bh: &mut BenchHarness) { let mut rng = StdRng::new(); - do bh.iter { + bh.iter(|| { for _ in range(0, RAND_BENCH_N) { rng.gen::(); } - } + }); bh.bytes = size_of::() as u64 * RAND_BENCH_N; } @@ -944,8 +944,8 @@ mod bench { fn rand_shuffle_100(bh: &mut BenchHarness) { let mut rng = XorShiftRng::new(); let x : &mut[uint] = [1,..100]; - do bh.iter { + bh.iter(|| { rng.shuffle_mut(x); - } + }) } } diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 97daf8d7e60df..ff425a8a73b25 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -139,9 +139,9 @@ impl Result { /// /// Example: /// - /// let res = do read_file(file).map |buf| { + /// let res = read_file(file).map(|buf| { /// parse_bytes(buf) - /// } + /// }) #[inline] pub fn map(self, op: |T| -> U) -> Result { match self { @@ -462,11 +462,11 @@ mod tests { pub fn test_impl_iter() { let mut valid = false; let okval = Ok::<~str, ~str>(~"a"); - do okval.iter().next().map |_| { valid = true; }; + okval.iter().next().map(|_| { valid = true; }); assert!(valid); let errval = Err::<~str, ~str>(~"b"); - do errval.iter().next().map |_| { valid = false; }; + errval.iter().next().map(|_| { valid = false; }); assert!(valid); } @@ -474,12 +474,12 @@ mod tests { pub fn test_impl_iter_err() { let mut valid = true; let okval = Ok::<~str, ~str>(~"a"); - do okval.iter_err().next().map |_| { valid = false }; + okval.iter_err().next().map(|_| { valid = false }); assert!(valid); valid = false; let errval = Err::<~str, ~str>(~"b"); - do errval.iter_err().next().map |_| { valid = true }; + errval.iter_err().next().map(|_| { valid = true }); assert!(valid); } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index e3e425f620bd1..52a6d67cb05fb 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -1013,7 +1013,7 @@ mod test { total.times(|| { port.recv(); - }) + }); } } @@ -1041,7 +1041,7 @@ mod test { total.times(|| { end_port.recv(); - }) + }); } } @@ -1071,7 +1071,7 @@ mod test { do spawntask_random { chan_clone.send(()); } - }) + }); } let end_chan_clone = end_chan.clone(); do spawntask_random { @@ -1082,7 +1082,7 @@ mod test { let recvd = port_clone.try_recv().is_some(); end_chan_clone.send(recvd); } - }) + }); } let mut recvd = 0; @@ -1112,12 +1112,12 @@ mod test { let pipe_clone = pipe.clone(); let end_chan_clone = end_chan.clone(); do spawntask_random { - do msgs.times { + msgs.times(|| { pipe_clone.send(()); - } - do msgs.times { + }); + msgs.times(|| { pipe_clone.recv(); - } + }); } end_chan_clone.send(()); @@ -1125,7 +1125,7 @@ mod test { total.times(|| { end_port.recv(); - }) + }); } } diff --git a/src/libstd/rt/crate_map.rs b/src/libstd/rt/crate_map.rs index 76ccacb331fe7..6dcbd4a129e5c 100644 --- a/src/libstd/rt/crate_map.rs +++ b/src/libstd/rt/crate_map.rs @@ -61,9 +61,9 @@ pub fn get_crate_map() -> Option<&'static CrateMap<'static>> { } else { "_rust_crate_map_toplevel" }; - let sym = do rust_crate_map_toplevel.with_c_str |buf| { + let sym = rust_crate_map_toplevel.with_c_str(|buf| { dl::symbol(module, buf) - }; + }); dl::close(module); sym }; @@ -141,10 +141,10 @@ mod tests { let mut cnt = 0; unsafe { - do iter_crate_map(&root_crate) |entry| { + iter_crate_map(&root_crate, |entry| { assert!(*entry.log_level == 3); cnt += 1; - } + }); assert!(cnt == 1); } } @@ -183,10 +183,10 @@ mod tests { let mut cnt = 0; unsafe { - do iter_crate_map(&root_crate) |entry| { + iter_crate_map(&root_crate, |entry| { assert!(*entry.log_level == cnt); cnt += 1; - } + }); assert!(cnt == 4); } } diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 08d111da35155..3147e3c8a078e 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -103,15 +103,15 @@ mod bench { #[bench] fn alloc_owned_small(bh: &mut BenchHarness) { - do bh.iter { + bh.iter(|| { ~10; - } + }) } #[bench] fn alloc_owned_big(bh: &mut BenchHarness) { - do bh.iter { + bh.iter(|| { ~[10, ..1000]; - } + }) } } diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 23345926543c0..d5b0e384ca291 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -182,9 +182,9 @@ mod test { let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); Local::put(task); - let res = do Local::borrow |_task: &mut Task| { + let res = Local::borrow(|_task: &mut Task| { true - }; + }); assert!(res) let task: ~Task = Local::take(); cleanup_task(task); diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index a7805a9f55925..c98a66453eb15 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -311,11 +311,11 @@ mod bench { #[bench] fn alloc_managed_small(bh: &mut BenchHarness) { - bh.iter(|| @10); + bh.iter(|| { @10; }); } #[bench] fn alloc_managed_big(bh: &mut BenchHarness) { - bh.iter(|| @[10, ..1000]); + bh.iter(|| { @[10, ..1000]; }); } } diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 519274bb131cf..ccc786242e6eb 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -1176,7 +1176,7 @@ mod test { use util; do run_in_bare_thread { - do stress_factor().times { + stress_factor().times(|| { let sleepers = SleeperList::new(); let queue = WorkQueue::new(); let queues = ~[queue.clone()]; @@ -1205,7 +1205,7 @@ mod test { util::ignore(handle); thread.join(); - } + }) } } @@ -1218,14 +1218,14 @@ mod test { do run_in_mt_newsched_task { let mut ports = ~[]; - do 10.times { + 10.times(|| { let (port, chan) = oneshot(); let chan_cell = Cell::new(chan); do spawntask_later { chan_cell.take().send(()); } ports.push(port); - } + }); while !ports.is_empty() { ports.pop().recv(); @@ -1315,7 +1315,7 @@ mod test { fn dont_starve_1() { use rt::comm::oneshot; - do stress_factor().times { + stress_factor().times(|| { do run_in_mt_newsched_task { let (port, chan) = oneshot(); @@ -1327,14 +1327,14 @@ mod test { chan.send(()); } - } + }) } #[test] fn dont_starve_2() { use rt::comm::oneshot; - do stress_factor().times { + stress_factor().times(|| { do run_in_newsched_task { let (port, chan) = oneshot(); let (_port2, chan2) = stream(); @@ -1349,7 +1349,7 @@ mod test { chan.send(()); } - } + }) } // Regression test for a logic bug that would cause single-threaded schedulers @@ -1360,7 +1360,7 @@ mod test { use num::Times; do spawn_sched(SingleThreaded) { - do 5.times { deschedule(); } + 5.times(|| { deschedule(); }) } do spawn { } do spawn { } diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index 360764daf156c..0d4171d5a643c 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -103,11 +103,11 @@ mod test { let tube_clone = tube.clone(); let tube_clone_cell = Cell::new(tube_clone); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |sched, task| { + sched.deschedule_running_task_and_then(|sched, task| { let mut tube_clone = tube_clone_cell.take(); tube_clone.send(1); sched.enqueue_blocked_task(task); - } + }); assert!(tube.recv() == 1); } @@ -120,7 +120,7 @@ mod test { let tube_clone = tube.clone(); let tube_clone = Cell::new(tube_clone); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |sched, task| { + sched.deschedule_running_task_and_then(|sched, task| { let tube_clone = Cell::new(tube_clone.take()); do sched.event_loop.callback { let mut tube_clone = tube_clone.take(); @@ -129,7 +129,7 @@ mod test { tube_clone.send(1); } sched.enqueue_blocked_task(task); - } + }); assert!(tube.recv() == 1); } @@ -144,14 +144,14 @@ mod test { let tube_clone = tube.clone(); let tube_clone = Cell::new(tube_clone); let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |sched, task| { + sched.deschedule_running_task_and_then(|sched, task| { callback_send(tube_clone.take(), 0); fn callback_send(tube: Tube, i: int) { if i == 100 { return; } let tube = Cell::new(Cell::new(tube)); - do Local::borrow |sched: &mut Scheduler| { + Local::borrow(|sched: &mut Scheduler| { let tube = tube.take(); do sched.event_loop.callback { let mut tube = tube.take(); @@ -160,11 +160,11 @@ mod test { tube.send(i); callback_send(tube, i + 1); } - } + }) } sched.enqueue_blocked_task(task); - } + }); for i in range(0, MAX) { let j = tube.recv(); diff --git a/src/libstd/select.rs b/src/libstd/select.rs index b619085e20180..9b83c493065d2 100644 --- a/src/libstd/select.rs +++ b/src/libstd/select.rs @@ -211,7 +211,7 @@ mod test { do run_in_uv_task { let (ports, _) = unzip(range(0u, 10).map(|_| stream::())); let (port, chan) = stream(); - do 10.times { chan.send(31337); } + 10.times(|| { chan.send(31337); }); let mut ports = ports; let mut port = Some(port); let order = [5u,0,4,3,2,6,9,8,7,1]; @@ -276,7 +276,7 @@ mod test { do run_in_uv_task { // A bit of stress, since ordinarily this is just smoke and mirrors. - do 4.times { + 4.times(|| { let send_on_chans = send_on_chans.clone(); do task::spawn { let mut ports = ~[]; @@ -294,7 +294,7 @@ mod test { // nondeterministic result, but should succeed select(ports); } - } + }) } } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b2ded6ab7541e..f65ec6971aba7 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -3966,19 +3966,25 @@ mod bench { Lorem ipsum dolor sit amet, consectetur. "); assert_eq!(100, s.len()); - bh.iter(|| is_utf8(s)); + bh.iter(|| { + let _ = is_utf8(s); + }); } #[bench] fn is_utf8_100_multibyte(bh: &mut BenchHarness) { let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰"); assert_eq!(100, s.len()); - bh.iter(|| is_utf8(s)); + bh.iter(|| { + let _ = is_utf8(s); + }); } #[bench] fn bench_with_capacity(bh: &mut BenchHarness) { - bh.iter(|| with_capacity(100)); + bh.iter(|| { + let _ = with_capacity(100); + }); } #[bench] diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 85f66d4ada827..189f1436d42d7 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -477,9 +477,9 @@ fn test_unnamed_task() { do run_in_uv_task { do spawn { - do with_task_name |name| { + with_task_name(|name| { assert!(name.is_none()); - } + }) } } } @@ -492,9 +492,9 @@ fn test_owned_named_task() { let mut t = task(); t.name(~"ada lovelace"); do t.spawn { - do with_task_name |name| { + with_task_name(|name| { assert!(name.unwrap() == "ada lovelace"); - } + }) } } } @@ -507,9 +507,9 @@ fn test_static_named_task() { let mut t = task(); t.name("ada lovelace"); do t.spawn { - do with_task_name |name| { + with_task_name(|name| { assert!(name.unwrap() == "ada lovelace"); - } + }) } } } @@ -522,9 +522,9 @@ fn test_send_named_task() { let mut t = task(); t.name("ada lovelace".into_send_str()); do t.spawn { - do with_task_name |name| { + with_task_name(|name| { assert!(name.unwrap() == "ada lovelace"); - } + }) } } } @@ -606,9 +606,9 @@ fn test_try_fail() { #[cfg(test)] fn get_sched_id() -> int { - do Local::borrow |sched: &mut ::rt::sched::Scheduler| { + Local::borrow(|sched: &mut ::rt::sched::Scheduler| { sched.sched_id() as int - } + }) } #[test] @@ -666,7 +666,7 @@ fn test_spawn_sched_blocking() { // Testing that a task in one scheduler can block in foreign code // without affecting other schedulers - do 20u.times { + 20u.times(|| { let (start_po, start_ch) = stream(); let (fin_po, fin_ch) = stream(); @@ -713,7 +713,7 @@ fn test_spawn_sched_blocking() { lock.unlock(); fin_po.recv(); lock.destroy(); - } + }) } } @@ -740,21 +740,21 @@ fn test_avoid_copying_the_body_spawn() { #[test] fn test_avoid_copying_the_body_task_spawn() { - do avoid_copying_the_body |f| { + avoid_copying_the_body(|f| { let builder = task(); do builder.spawn || { f(); } - } + }) } #[test] fn test_avoid_copying_the_body_try() { - do avoid_copying_the_body |f| { + avoid_copying_the_body(|f| { do try || { f() }; - } + }) } #[test] diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index 226ce9ef6f2e6..57aff6031bafd 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -15,11 +15,11 @@ stack closures that emulates Java-style try/finally blocks. # Example ``` -do || { +(|| { ... -}.finally { +}).finally(|| { always_run_this(); -} +}) ``` */ @@ -70,13 +70,13 @@ impl<'self> Drop for Finallyalizer<'self> { #[test] fn test_success() { let mut i = 0; - do (|| { + (|| { i = 10; - }).finally { + }).finally(|| { assert!(!failing()); assert_eq!(i, 10); i = 20; - } + }); assert_eq!(i, 20); } @@ -84,19 +84,19 @@ fn test_success() { #[should_fail] fn test_fail() { let mut i = 0; - do (|| { + (|| { i = 10; fail!(); - }).finally { + }).finally(|| { assert!(failing()); assert_eq!(i, 10); - } + }) } #[test] fn test_retval() { let closure: || -> int = || 10; - let i = do closure.finally { }; + let i = closure.finally(|| { }); assert_eq!(i, 10); } diff --git a/src/libstd/util.rs b/src/libstd/util.rs index 8e939caf75690..ddcf408189ed2 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -178,17 +178,17 @@ mod bench { fn trait_vtable_method_call(bh: &mut BenchHarness) { let s = Struct { field: 10 }; let t = &s as &Trait; - do bh.iter { + bh.iter(|| { t.method(); - } + }); } #[bench] fn trait_static_method_call(bh: &mut BenchHarness) { let s = Struct { field: 10 }; - do bh.iter { + bh.iter(|| { s.method(); - } + }); } // Overhead of various match forms @@ -196,22 +196,22 @@ mod bench { #[bench] fn match_option_some(bh: &mut BenchHarness) { let x = Some(10); - do bh.iter { + bh.iter(|| { let _q = match x { Some(y) => y, None => 11 }; - } + }); } #[bench] fn match_vec_pattern(bh: &mut BenchHarness) { let x = [1,2,3,4,5,6]; - do bh.iter { + bh.iter(|| { let _q = match x { [1,2,3,.._] => 10, _ => 11 }; - } + }); } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 30627327d7327..9dc4f6ae3771c 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -3878,13 +3878,17 @@ mod bench { #[bench] fn concat(bh: &mut BenchHarness) { let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect()); - bh.iter(|| xss.concat_vec()); + bh.iter(|| { + let _ = xss.concat_vec(); + }); } #[bench] fn connect(bh: &mut BenchHarness) { let xss: &[~[uint]] = vec::from_fn(100, |i| range(0, i).collect()); - bh.iter(|| xss.connect_vec(&0)); + bh.iter(|| { + let _ = xss.connect_vec(&0); + }); } #[bench] diff --git a/src/test/auxiliary/xc_conditions_3.rs b/src/test/auxiliary/xc_conditions_3.rs index d5ce63e7e9bc0..afe9de7abb969 100644 --- a/src/test/auxiliary/xc_conditions_3.rs +++ b/src/test/auxiliary/xc_conditions_3.rs @@ -15,7 +15,7 @@ condition! { } pub fn guard(k: extern fn() -> int, x: int) -> int { - do oops::cond.trap(|i| i*x).inside { + oops::cond.trap(|i| i*x).inside(|| { k() - } + }) } diff --git a/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs index f8a3c5c573a0d..c31a7bb244c72 100644 --- a/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs @@ -14,8 +14,6 @@ use extra::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; - do x.write_cond |_one, cond| { - y = Some(cond); - } + x.write_cond(|_one, cond| y = Some(cond)); y.unwrap().wait(); } diff --git a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs index cb6290686816d..2fe2095ca879e 100644 --- a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs @@ -13,10 +13,10 @@ use extra::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; - do x.write_downgrade |write_mode| { + x.write_downgrade(|write_mode| { y = Some(x.downgrade(write_mode)); //~^ ERROR cannot infer an appropriate lifetime - } + }); y.unwrap(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).read |state| { assert!(*state == 1); } diff --git a/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs index 44657dfd0efe6..7c129ae0dcaad 100644 --- a/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs @@ -13,9 +13,7 @@ use extra::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration - do x.write |one| { - y = Some(one); - } + x.write(|one| y = Some(one)); *y.unwrap() = 2; //~^ ERROR lifetime of return value does not outlive the function call //~^^ ERROR dereference of reference outside its lifetime diff --git a/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs index 44ac0e722d38a..674cd5708889c 100644 --- a/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs @@ -14,10 +14,10 @@ use extra::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; - do x.write_downgrade |write_mode| { - do (&write_mode).write_cond |_one, cond| { + x.write_downgrade(|write_mode| { + (&write_mode).write_cond(|_one, cond| { y = Some(cond); - } - } + }) + }); y.unwrap().wait(); } diff --git a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs index 75e1989aff01a..d9247ab4fc170 100644 --- a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs @@ -14,9 +14,7 @@ use extra::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; - do x.write_downgrade |write_mode| { - y = Some(write_mode); - } + x.write_downgrade(|write_mode| y = Some(write_mode)); y.unwrap(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).write |state| { assert!(*state == 1); } diff --git a/src/test/compile-fail/block-arg-as-stmt-with-value.rs b/src/test/compile-fail/block-arg-as-stmt-with-value.rs deleted file mode 100644 index 7637ebdc80dcc..0000000000000 --- a/src/test/compile-fail/block-arg-as-stmt-with-value.rs +++ /dev/null @@ -1,22 +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. - -fn compute1() -> f64 { - let v = ~[0f64, 1.0, 2.0, 3.0]; - - do v.iter().fold(0.0) |x, y| { x + *y } - 10.0 - //~^ ERROR mismatched types: expected `()` -} - -fn main() { - let x = compute1(); - info!("{:?}", x); - assert_eq!(x, -4f64); -} diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 55ef70ad8520f..b50a657eae79a 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -32,9 +32,9 @@ fn b() { let mut p = ~[1]; - do borrow(p) { + borrow(p, || { p[0] = 5; //~ ERROR cannot assign to - } + }); } fn c() { diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index f834642eb3cc5..5c7e328969bb5 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -18,7 +18,7 @@ impl X { fn main() { let mut x = X(Right(main)); - do (&mut x).with |opt| { + (&mut x).with(|opt| { match opt { &Right(ref f) => { x = X(Left((0,0))); //~ ERROR cannot assign to `x` @@ -26,5 +26,5 @@ fn main() { }, _ => fail!() } - } + }) } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 358305aee08fb..94ed47b01e1ee 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -23,9 +23,9 @@ impl Foo { } fn bar(f: &mut Foo) { - do f.foo |a| { + f.foo(|a| { f.n.insert(*a); //~ ERROR cannot borrow - } + }) } fn main() { diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 14994c0245da9..c25f39a9d4329 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -39,9 +39,9 @@ fn block_overarching_alias_mut() { let mut v = ~3; let mut x = &mut v; - do 3.times { + 3.times(|| { borrow(v); //~ ERROR cannot borrow - } + }); *x = ~5; } diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index 417330b6864a7..a54476abb26d6 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -14,11 +14,11 @@ fn borrow(v: &int, f: |x: &int|) { fn box_imm() { let mut v = ~3; - do borrow(v) |w| { + borrow(v, |w| { v = ~4; //~ ERROR cannot assign to `v` because it is borrowed assert_eq!(*v, 3); assert_eq!(*w, 4); - } + }) } fn main() { diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index e04eaa4d7af6a..c2ed3378bf97c 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -30,9 +30,9 @@ fn a() { p.impurem(); // But in this case we do not honor the loan: - do p.blockm { + p.blockm(|| { p.x = 10; //~ ERROR cannot assign - } + }) } fn b() { @@ -52,9 +52,9 @@ fn c() { q.impurem(); // ...but we still detect errors statically when we can. - do q.blockm { + q.blockm(|| { q.x = 10; //~ ERROR cannot assign - } + }) } fn main() { diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 0617d19919114..6527ddfa2ecf6 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -18,15 +18,14 @@ fn takes_imm_elt(_v: &int, f: ||) { fn has_mut_vec_and_does_not_try_to_change_it() { let mut v = ~[1, 2, 3]; - do takes_imm_elt(&v[0]) { - } + takes_imm_elt(&v[0], || {}) } fn has_mut_vec_but_tries_to_change_it() { let mut v = ~[1, 2, 3]; - do takes_imm_elt(&v[0]) { + takes_imm_elt(&v[0], || { v[1] = 4; //~ ERROR cannot assign - } + }) } fn main() { diff --git a/src/test/compile-fail/break-outside-loop.rs b/src/test/compile-fail/break-outside-loop.rs index 06281a5e2884b..4633ca662897f 100644 --- a/src/test/compile-fail/break-outside-loop.rs +++ b/src/test/compile-fail/break-outside-loop.rs @@ -23,10 +23,10 @@ fn main() { while cond() { if cond() { break } if cond() { continue } - do foo { + foo(|| { if cond() { break } //~ ERROR: `break` inside of a closure if cond() { continue } //~ ERROR: `continue` inside of a closure - } + }) } let rs: Foo = Foo{t: pth}; diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 8fb64ee6dacec..1c6d65ba54167 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -12,9 +12,9 @@ fn bar(blk: ||:'static) { } fn foo(x: &()) { - do bar { + bar(|| { let _ = x; //~ ERROR does not fulfill `'static` - } + }) } fn main() { diff --git a/src/test/compile-fail/do2.rs b/src/test/compile-fail/do2.rs index ffb779da354f8..309abe218f6f1 100644 --- a/src/test/compile-fail/do2.rs +++ b/src/test/compile-fail/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: |int| -> bool) -> bool { f(10i) } +fn f(f: proc(int) -> bool) -> bool { f(10i) } fn main() { assert!(do f() |i| { i == 10i } == 10i); diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index d73f0e6ab1e68..798c1194af872 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -35,9 +35,9 @@ fn main() { let mut a = ~[]; a.push(3); let mut a = ~[]; - do callback { + callback(|| { a.push(3); - } + }); let (mut a, b) = (1, 2); a = 34; diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index 253459be85a82..f28322d3bf763 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -24,7 +24,7 @@ unsafe fn unsf() {} fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block unsafe fn bad3() { unsafe {} } //~ ERROR: unnecessary `unsafe` block -fn bad4() { unsafe { do callback {} } } //~ ERROR: unnecessary `unsafe` block +fn bad4() { unsafe { callback(||{}) } } //~ ERROR: unnecessary `unsafe` block unsafe fn bad5() { unsafe { unsf() } } //~ ERROR: unnecessary `unsafe` block fn bad6() { unsafe { // don't put the warning here @@ -50,9 +50,9 @@ fn good2() { unsafe { unsafe fn what() -> ~[~str] { fail!() } - do callback { + callback(|| { what(); - } + }); } } diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index 355305b6c630c..690c778183c60 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -15,12 +15,12 @@ fn f(s: &S, g: |&S|) { fn main() { let s = S { x: ~Bar(~42) }; loop { - do f(&s) |hellothere| { + f(&s, |hellothere| { match hellothere.x { ~Foo(_) => {} ~Bar(x) => println(x.to_str()), //~ ERROR cannot move out ~Baz => {} } - } + }) } } diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index bf7383f9c72b8..260d5a5dd4475 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -21,7 +21,7 @@ struct R<'self> { fn innocent_looking_victim() { let mut x = Some(~"hello"); - do conspirator |f, writer| { + conspirator(|f, writer| { if writer { x = None; } else { @@ -33,7 +33,7 @@ fn innocent_looking_victim() { None => fail!("oops"), } } - } + }) } fn conspirator(f: |&R, bool|) { diff --git a/src/test/compile-fail/mutex-arc-nested.rs b/src/test/compile-fail/mutex-arc-nested.rs index bac17dec8ecbc..476b890efcd6b 100644 --- a/src/test/compile-fail/mutex-arc-nested.rs +++ b/src/test/compile-fail/mutex-arc-nested.rs @@ -18,8 +18,8 @@ fn test_mutex_arc_nested() { let arc2 = ~MutexArc::new(*arc); do task::spawn || { - do (*arc2).access |mutex| { //~ ERROR instantiating a type parameter with an incompatible type - } + (*arc2).access(|mutex| { //~ ERROR instantiating a type parameter with an incompatible type + }) }; } diff --git a/src/test/compile-fail/once-cant-call-twice-on-stack.rs b/src/test/compile-fail/once-cant-call-twice-on-stack.rs index 9cc69228c56f5..98362baef2c34 100644 --- a/src/test/compile-fail/once-cant-call-twice-on-stack.rs +++ b/src/test/compile-fail/once-cant-call-twice-on-stack.rs @@ -23,8 +23,8 @@ fn foo(blk: once ||) { fn main() { let x = arc::Arc::new(true); - do foo { + foo(|| { assert!(*x.get()); util::ignore(x); - } + }) } diff --git a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs index 4927acde48d87..60d1b9c1c34fd 100644 --- a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs +++ b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs @@ -22,8 +22,8 @@ fn foo(blk: ||) { fn main() { let x = arc::Arc::new(true); - do foo { + foo(|| { assert!(*x.get()); util::ignore(x); //~ ERROR cannot move out of captured outer variable - } + }) } diff --git a/src/test/compile-fail/regions-freevar.rs b/src/test/compile-fail/regions-freevar.rs index 7e5abe8e2f7e4..493b9c466bd3b 100644 --- a/src/test/compile-fail/regions-freevar.rs +++ b/src/test/compile-fail/regions-freevar.rs @@ -12,7 +12,7 @@ fn wants_static_fn(_x: 'static ||) {} fn main() { let i = 3; - do wants_static_fn { //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements + wants_static_fn(|| { //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements info!("i={}", i); - } + }) } diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index 8002f8bcc50d2..bb7c487005faa 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -15,7 +15,7 @@ fn with(f: |x: &int| -> T) -> T { } fn manip<'a>(x: &'a int) -> int { - let z = do with |y| { select(x, y) }; + let z = with(|y| { select(x, y) }); //~^ ERROR cannot infer an appropriate lifetime *z } diff --git a/src/test/compile-fail/sync-cond-shouldnt-escape.rs b/src/test/compile-fail/sync-cond-shouldnt-escape.rs index 928953de39088..4df08b28eb896 100644 --- a/src/test/compile-fail/sync-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/sync-cond-shouldnt-escape.rs @@ -15,8 +15,8 @@ use extra::sync; fn main() { let m = ~sync::Mutex::new(); let mut cond = None; - do m.lock_cond |c| { + m.lock_cond(|c| { cond = Some(c); - } + }); cond.unwrap().signal(); } diff --git a/src/test/compile-fail/sync-rwlock-cond-shouldnt-escape.rs b/src/test/compile-fail/sync-rwlock-cond-shouldnt-escape.rs index 03779b3ffe3d1..d59eaf62abf84 100644 --- a/src/test/compile-fail/sync-rwlock-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/sync-rwlock-cond-shouldnt-escape.rs @@ -14,8 +14,8 @@ use extra::sync; fn main() { let x = ~sync::RWLock::new(); let mut y = None; - do x.write_cond |cond| { + x.write_cond(|cond| { y = Some(cond); - } + }); y.unwrap().wait(); } diff --git a/src/test/compile-fail/sync-rwlock-read-mode-shouldnt-escape.rs b/src/test/compile-fail/sync-rwlock-read-mode-shouldnt-escape.rs index 6ce3869bab224..e71dfc588161f 100644 --- a/src/test/compile-fail/sync-rwlock-read-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/sync-rwlock-read-mode-shouldnt-escape.rs @@ -14,9 +14,9 @@ use extra::sync; fn main() { let x = ~sync::RWLock::new(); let mut y = None; - do x.write_downgrade |write_mode| { + x.write_downgrade(|write_mode| { y = Some(x.downgrade(write_mode)); - } + }) // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).read { } } diff --git a/src/test/compile-fail/sync-rwlock-write-mode-cond-shouldnt-escape.rs b/src/test/compile-fail/sync-rwlock-write-mode-cond-shouldnt-escape.rs index fab16894a655a..cbe5181d46f24 100644 --- a/src/test/compile-fail/sync-rwlock-write-mode-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/sync-rwlock-write-mode-cond-shouldnt-escape.rs @@ -14,10 +14,10 @@ use extra::sync; fn main() { let x = ~sync::RWLock::new(); let mut y = None; - do x.write_downgrade |write_mode| { - do (&write_mode).write_cond |cond| { + x.write_downgrade(|write_mode| { + (&write_mode).write_cond(|cond| { y = Some(cond); - } - } + }) + }); y.unwrap().wait(); } diff --git a/src/test/compile-fail/sync-rwlock-write-mode-shouldnt-escape.rs b/src/test/compile-fail/sync-rwlock-write-mode-shouldnt-escape.rs index 7210fbf37b424..af0149182aeba 100644 --- a/src/test/compile-fail/sync-rwlock-write-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/sync-rwlock-write-mode-shouldnt-escape.rs @@ -14,9 +14,9 @@ use extra::sync; fn main() { let x = ~sync::RWLock::new(); let mut y = None; - do x.write_downgrade |write_mode| { + x.write_downgrade(|write_mode| { y = Some(write_mode); - } + }); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).write { } } diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow.rs b/src/test/run-fail/bug-2470-bounds-check-overflow.rs index 36f05a0a73cd1..a476a9727b360 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow.rs @@ -21,7 +21,7 @@ fn main() { // huge). let x = ~[1u,2u,3u]; - do x.as_imm_buf |p, _len| { + x.as_imm_buf(|p, _len| { let base = p as uint; let idx = base / mem::size_of::(); error!("ov1 base = 0x{:x}", base); @@ -32,5 +32,5 @@ fn main() { // This should fail. error!("ov1 0x{:x}", x[idx]); - } + }) } diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 1da5023dce023..c5142897b1d9c 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -30,14 +30,17 @@ impl iterable for ~[A] { fn length>(x: T) -> uint { let mut len = 0; - do x.iterate() |_y| { len += 1; true }; + x.iterate(|_y| { + len += 1; + true + }); return len; } pub fn main() { let x = ~[0,1,2,3]; // Call a method - do x.iterate() |y| { assert!(x[*y] == *y); true }; + x.iterate(|y| { assert!(x[*y] == *y); true }); // Call a parameterized function assert_eq!(length(x.clone()), x.len()); // Call a parameterized function, with type arguments that require @@ -47,7 +50,7 @@ pub fn main() { // Now try it with a type that *needs* to be borrowed let z = [0,1,2,3]; // Call a method - do z.iterate() |y| { assert!(z[*y] == *y); true }; + z.iterate(|y| { assert!(z[*y] == *y); true }); // Call a parameterized function assert_eq!(length::(z), z.len()); } diff --git a/src/test/run-pass/bitv-perf-test.rs b/src/test/run-pass/bitv-perf-test.rs index dcdab0edc3aae..dca0efd94fab5 100644 --- a/src/test/run-pass/bitv-perf-test.rs +++ b/src/test/run-pass/bitv-perf-test.rs @@ -20,5 +20,5 @@ fn bitv_test() { } pub fn main() { - do 10000.times || {bitv_test()}; + 10000.times(|| bitv_test()); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs index e65116f214743..f2149e23210cc 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn main() { - let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0]; +fn add(x: proc(f64) -> f64) -> f64 { + x(10.0) +} +pub fn main() { // Trailing expressions don't require parentheses: - let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0; + let y = do add |x| { x + 10.0 } + 10.0; - assert_eq!(y, 15.0); + assert_eq!(y, 30.0); } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs index 0d82e294caf22..2cdf0a1ffe1f1 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn f(_: proc()) -> proc(proc() -> uint) { + proc(_: proc() -> uint) {} +} + pub fn main() { - fn f(i: || -> uint) -> uint { i() } - let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0]; - let z = do do v.iter().fold(f) |x, _y| { x } { 22u }; - assert_eq!(z, 22u); + do do f {} { 20 }; } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-call.rs b/src/test/run-pass/block-arg-can-be-followed-by-call.rs index 1bb16f6041eec..544367bdfa9d5 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-call.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-call.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn f(_: proc()) -> proc(uint) -> uint { + proc(x: uint) { x } +} + pub fn main() { - fn f(i: uint) -> uint { i } - let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0]; - let z = do v.iter().fold(f) |x, _y| { x } (22u); + let z = do f {} (22u); assert_eq!(z, 22u); } diff --git a/src/test/run-pass/block-arg-in-parentheses.rs b/src/test/run-pass/block-arg-in-parentheses.rs index fcd6a8d7c85e5..083217132de11 100644 --- a/src/test/run-pass/block-arg-in-parentheses.rs +++ b/src/test/run-pass/block-arg-in-parentheses.rs @@ -8,28 +8,31 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn w_semi(v: ~[int]) -> int { +fn f(_: proc(int, int) -> int) -> int { + 10 +} + +fn w_semi() { // the semicolon causes compiler not to // complain about the ignored return value: - do v.iter().fold(0) |x,y| { x+*y }; - -10 + do f |x, y| { x+y }; } -fn w_paren1(v: ~[int]) -> int { - (do v.iter().fold(0) |x,y| { x+*y }) - 10 +fn w_paren1() -> int { + (do f |x, y| { x+y }) - 10 } -fn w_paren2(v: ~[int]) -> int { - (do v.iter().fold(0) |x,y| { x+*y} - 10) +fn w_paren2() -> int { + (do f |x, y| { x+y } - 10) } -fn w_ret(v: ~[int]) -> int { - return do v.iter().fold(0) |x,y| { x+*y } - 10; +fn w_ret() -> int { + return do f |x, y| { x+y } - 10; } pub fn main() { - assert_eq!(w_semi(~[0, 1, 2, 3]), -10); - assert_eq!(w_paren1(~[0, 1, 2, 3]), -4); - assert_eq!(w_paren2(~[0, 1, 2, 3]), -4); - assert_eq!(w_ret(~[0, 1, 2, 3]), -4); + w_semi(); + w_paren1(); + w_paren2(); + w_ret(); } diff --git a/src/test/run-pass/block-arg-used-as-any.rs b/src/test/run-pass/block-arg-used-as-any.rs index f05eb8e30b17c..87a6cbd6fc2f3 100644 --- a/src/test/run-pass/block-arg-used-as-any.rs +++ b/src/test/run-pass/block-arg-used-as-any.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn call_any(f: || -> uint) -> uint { +fn call_any(f: proc() -> uint) -> uint { return f(); } diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 0608285db1e8e..afe7747457a8c 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -8,6 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn inty(fun: proc(int) -> int) -> int { + fun(100) +} + +fn booly(fun: proc(bool) -> bool) -> bool { + fun(true) +} + // Check usage and precedence of block arguments in expressions: pub fn main() { let v = ~[-1.0f64, 0.0, 1.0, 2.0, 3.0]; @@ -18,28 +26,27 @@ pub fn main() { } // Usable at all: - let mut any_negative = do v.iter().any |e| { e.is_negative() }; - assert!(any_negative); + do inty |x| { x }; // Higher precedence than assignments: - any_negative = do v.iter().any |e| { e.is_negative() }; - assert!(any_negative); + let result = do inty |e| { e }; + assert_eq!(result, 100); // Higher precedence than unary operations: - let abs_v = do v.iter().map |e| { e.abs() }.collect::<~[f64]>(); - assert!(do abs_v.iter().all |e| { e.is_positive() }); - assert!(!do abs_v.iter().any |e| { e.is_negative() }); + let stringy = do inty |e| { e }.to_str(); + assert!(do booly |_| { true }); + assert!(!do booly |_| { false }); // Usable in funny statement-like forms: - if !do v.iter().any |e| { e.is_positive() } { + if !do booly |_| { true } { assert!(false); } - match do v.iter().all |e| { e.is_negative() } { + match do booly |_| { false } { true => { fail!("incorrect answer."); } false => { } } match 3 { - _ if do v.iter().any |e| { e.is_negative() } => { + _ if do booly |_| { true } => { } _ => { fail!("wrong answer."); @@ -48,15 +55,19 @@ pub fn main() { // Lower precedence than binary operations: - let w = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0; - let y = do v.iter().fold(0.0) |x, y| { x + *y } + 10.0; - let z = 10.0 + do v.iter().fold(0.0) |x, y| { x + *y }; + let w = do inty |_| { 10 } + 10; + let y = do inty |_| { 10 } + 10; + let z = 10 + do inty |_| { 10 }; assert_eq!(w, y); assert_eq!(y, z); // In the tail of a block - let w = - if true { do abs_v.iter().any |e| { e.is_positive() } } - else { false }; + let w = if true { + do booly |_| { + true + } + } else { + false + }; assert!(w); } diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index dae10ed6d3917..f108d6cad6fbe 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -18,11 +18,11 @@ fn borrow(x: &int, f: |x: &int|) { } fn test1(x: @~int) { - do borrow(&*(*x).clone()) |p| { + borrow(&*(*x).clone(), |p| { let x_a = ptr::to_unsafe_ptr(&**x); assert!((x_a as uint) != borrow::to_uint(p)); assert_eq!(unsafe{*x_a}, *p); - } + }) } pub fn main() { diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index 7b4c4247a353b..542a8251f712c 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -30,10 +30,10 @@ pub fn main() { add_int(ints, 22); add_int(ints, 44); - do iter_ints(ints) |i| { + iter_ints(ints, |i| { error!("int = {}", *i); true - }; + }); error!("ints={:?}", ints); } diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs index bc8eeb5cd4178..506d777013cd2 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -23,7 +23,7 @@ struct F { f: ~int } pub fn main() { let mut x = @F {f: ~3}; - do borrow(x.f) |b_x| { + borrow(x.f, |b_x| { assert_eq!(*b_x, 3); assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x))); x = @F {f: ~4}; @@ -32,5 +32,5 @@ pub fn main() { ptr::to_unsafe_ptr(&(*b_x)) as uint); assert_eq!(*b_x, 3); assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); - } + }) } diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 3ff30192efed8..d7f7a8e47a230 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -23,7 +23,7 @@ struct F { f: ~int } pub fn main() { let mut x = ~@F{f: ~3}; - do borrow(x.f) |b_x| { + borrow(x.f, |b_x| { assert_eq!(*b_x, 3); assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x))); *x = @F{f: ~4}; @@ -32,5 +32,5 @@ pub fn main() { ptr::to_unsafe_ptr(&(*b_x)) as uint); assert_eq!(*b_x, 3); assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); - } + }) } diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs index e83621d6bb280..feea06cd69a18 100644 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -21,7 +21,7 @@ fn borrow(x: &int, f: |x: &int|) { pub fn main() { let mut x = @3; - do borrow(x) |b_x| { + borrow(x, |b_x| { assert_eq!(*b_x, 3); assert_eq!(ptr::to_unsafe_ptr(&(*x)), ptr::to_unsafe_ptr(&(*b_x))); x = @22; @@ -30,5 +30,5 @@ pub fn main() { ptr::to_unsafe_ptr(&(*b_x)) as uint); assert_eq!(*b_x, 3); assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x))); - } + }) } diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs index 6041fa977f5c3..d131a529f1a36 100644 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -23,7 +23,7 @@ struct F { f: ~int } pub fn main() { let mut x = @F {f: ~3}; - do borrow((*x).f) |b_x| { + borrow((*x).f, |b_x| { assert_eq!(*b_x, 3); assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x))); x = @F {f: ~4}; @@ -32,5 +32,5 @@ pub fn main() { ptr::to_unsafe_ptr(&(*b_x)) as uint); assert_eq!(*b_x, 3); assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x))); - } + }) } diff --git a/src/test/run-pass/cci_impl_exe.rs b/src/test/run-pass/cci_impl_exe.rs index b85d53991eafe..fd24b7cfe953a 100644 --- a/src/test/run-pass/cci_impl_exe.rs +++ b/src/test/run-pass/cci_impl_exe.rs @@ -18,11 +18,11 @@ pub fn main() { //let bt0 = sys::frame_address(); //info!("%?", bt0); - do 3u.to(10u) |i| { + 3u.to(10u, |i| { println!("{}", i); //let bt1 = sys::frame_address(); //info!("%?", bt1); //assert!(bt0 == bt1); - } + }) } diff --git a/src/test/run-pass/cci_iter_exe.rs b/src/test/run-pass/cci_iter_exe.rs index ea313a48bb3ca..938956a18b61f 100644 --- a/src/test/run-pass/cci_iter_exe.rs +++ b/src/test/run-pass/cci_iter_exe.rs @@ -16,8 +16,8 @@ extern mod cci_iter_lib; pub fn main() { //let bt0 = sys::rusti::frame_address(1u32); //info!("%?", bt0); - do cci_iter_lib::iter([1, 2, 3]) |i| { + cci_iter_lib::iter([1, 2, 3], |i| { println!("{}", *i); //assert!(bt0 == sys::rusti::frame_address(2u32)); - } + }) } diff --git a/src/test/run-pass/cci_no_inline_exe.rs b/src/test/run-pass/cci_no_inline_exe.rs index 53c67e4802be1..e2532667560ef 100644 --- a/src/test/run-pass/cci_no_inline_exe.rs +++ b/src/test/run-pass/cci_no_inline_exe.rs @@ -22,12 +22,12 @@ pub fn main() { // actually working. //let bt0 = sys::frame_address(); //info!("%?", bt0); - do iter(~[1u, 2u, 3u]) |i| { + iter(~[1u, 2u, 3u], |i| { println!("{}", i); //let bt1 = sys::frame_address(); //info!("%?", bt1); //assert!(bt0 != bt1); - } + }) } diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs index a24d11a89b056..07d9fb95dcb55 100644 --- a/src/test/run-pass/core-run-destroy.rs +++ b/src/test/run-pass/core-run-destroy.rs @@ -40,9 +40,9 @@ fn test_destroy_twice() { let mut p = run::Process::new(PROG, [], run::ProcessOptions::new()); p.destroy(); // this shouldnt crash... - do io::io_error::cond.trap(|_| {}).inside { + io::io_error::cond.trap(|_| {}).inside(|| { p.destroy(); // ...and nor should this (and nor should the destructor) - } + }) } fn test_destroy_actually_kills(force: bool) { diff --git a/src/test/run-pass/deriving-encodable-decodable.rs b/src/test/run-pass/deriving-encodable-decodable.rs index 5812800259b86..5f3cebed66777 100644 --- a/src/test/run-pass/deriving-encodable-decodable.rs +++ b/src/test/run-pass/deriving-encodable-decodable.rs @@ -71,9 +71,9 @@ pub fn main() { roundtrip::(); roundtrip::(); - do 20.times { + 20.times(|| { roundtrip::(); roundtrip::(); roundtrip::>(); - } + }) } diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs index 39a86c0ae3fd6..9a28ed7008827 100644 --- a/src/test/run-pass/deriving-rand.rs +++ b/src/test/run-pass/deriving-rand.rs @@ -34,10 +34,10 @@ enum D { fn main() { // check there's no segfaults - do 20.times { + 20.times(|| { rand::random::(); rand::random::(); rand::random::(); rand::random::(); - } + }) } diff --git a/src/test/run-pass/do-empty-args.rs b/src/test/run-pass/do-empty-args.rs index 0078294eb89d5..56ba2ffddbb4b 100644 --- a/src/test/run-pass/do-empty-args.rs +++ b/src/test/run-pass/do-empty-args.rs @@ -11,7 +11,7 @@ // no-reformat // Testing various forms of `do` with empty arg lists -fn f(_f: || -> bool) -> bool { +fn f(_f: proc() -> bool) -> bool { true } diff --git a/src/test/run-pass/do-no-args.rs b/src/test/run-pass/do-no-args.rs index eb6a4a3db5421..0df5c82ab077f 100644 --- a/src/test/run-pass/do-no-args.rs +++ b/src/test/run-pass/do-no-args.rs @@ -10,9 +10,9 @@ // Testing that we can drop the || in do exprs -fn f(_f: || -> bool) -> bool { true } +fn f(_f: proc() -> bool) -> bool { true } -fn d(_f: ||) { } +fn d(_f: proc()) { } pub fn main() { do d { } diff --git a/src/test/run-pass/do-pure.rs b/src/test/run-pass/do-pure.rs deleted file mode 100644 index 85bb84c6061ac..0000000000000 --- a/src/test/run-pass/do-pure.rs +++ /dev/null @@ -1,20 +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. - -fn f(_f: ||) { -} - -fn g() { - // `f || { }` is considered pure, so `do f { }` should be too - do f { } -} - -pub fn main() { -} diff --git a/src/test/run-pass/do-stack.rs b/src/test/run-pass/do-stack.rs deleted file mode 100644 index fddf3b15c78da..0000000000000 --- a/src/test/run-pass/do-stack.rs +++ /dev/null @@ -1,15 +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. - -fn f(f: |int|) { f(10) } - -pub fn main() { - do f() |i| { assert!(i == 10) } -} diff --git a/src/test/run-pass/do1.rs b/src/test/run-pass/do1.rs index fddf3b15c78da..bdbad74b32095 100644 --- a/src/test/run-pass/do1.rs +++ b/src/test/run-pass/do1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: |int|) { f(10) } +fn f(f: proc(int)) { f(10) } pub fn main() { do f() |i| { assert!(i == 10) } diff --git a/src/test/run-pass/do2.rs b/src/test/run-pass/do2.rs index 1bfb10a9f7568..f509f7b454d35 100644 --- a/src/test/run-pass/do2.rs +++ b/src/test/run-pass/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: |int| -> int) -> int { f(10) } +fn f(f: proc(int) -> int) -> int { f(10) } pub fn main() { assert_eq!(do f() |i| { i }, 10); diff --git a/src/test/run-pass/do3.rs b/src/test/run-pass/do3.rs index c08842a45ce77..cdba14f1deda4 100644 --- a/src/test/run-pass/do3.rs +++ b/src/test/run-pass/do3.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: |int| -> int) -> int { f(10) } +fn f(f: proc(int) -> int) -> int { f(10) } pub fn main() { assert_eq!(do f |i| { i }, 10); diff --git a/src/test/run-pass/extern-stress.rs b/src/test/run-pass/extern-stress.rs index 21706848c81cf..6ef196ccd41fc 100644 --- a/src/test/run-pass/extern-stress.rs +++ b/src/test/run-pass/extern-stress.rs @@ -40,9 +40,9 @@ fn count(n: uint) -> uint { } pub fn main() { - do 100u.times { + 100u.times(|| { do task::spawn { assert_eq!(count(5u), 16u); }; - } + }) } diff --git a/src/test/run-pass/extern-yield.rs b/src/test/run-pass/extern-yield.rs index 45841e22896d7..1d2f52d8c2eb6 100644 --- a/src/test/run-pass/extern-yield.rs +++ b/src/test/run-pass/extern-yield.rs @@ -37,11 +37,11 @@ fn count(n: uint) -> uint { } pub fn main() { - do 10u.times { + 10u.times(|| { do task::spawn { let result = count(5u); info!("result = {}", result); assert_eq!(result, 16u); }; - } + }) } diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index 1f63bd68d34f7..9646c6b6eb79d 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -16,9 +16,9 @@ fn two(it: |int|) { it(0); it(1); } pub fn main() { let mut a: ~[int] = ~[-1, -1, -1, -1]; let mut p: int = 0; - do two |i| { - do two |j| { a[p] = 10 * i + j; p += 1; } - } + two(|i| { + two(|j| { a[p] = 10 * i + j; p += 1; }) + }); assert_eq!(a[0], 0); assert_eq!(a[1], 1); assert_eq!(a[2], 10); diff --git a/src/test/run-pass/foreach-put-structured.rs b/src/test/run-pass/foreach-put-structured.rs index 91468841e0923..7011088fa5d44 100644 --- a/src/test/run-pass/foreach-put-structured.rs +++ b/src/test/run-pass/foreach-put-structured.rs @@ -19,13 +19,13 @@ fn pairs(it: |(int, int)|) { pub fn main() { let mut i: int = 10; let mut j: int = 0; - do pairs() |p| { + pairs(|p| { let (_0, _1) = p; info!("{}", _0); info!("{}", _1); assert_eq!(_0 + 10, i); i += 1; j = _1; - }; + }); assert_eq!(j, 45); } diff --git a/src/test/run-pass/foreach-simple-outer-slot.rs b/src/test/run-pass/foreach-simple-outer-slot.rs index 34b131893269a..81e9ac1b80876 100644 --- a/src/test/run-pass/foreach-simple-outer-slot.rs +++ b/src/test/run-pass/foreach-simple-outer-slot.rs @@ -13,7 +13,7 @@ pub fn main() { let mut sum: int = 0; - do first_ten |i| { info!("main"); info!("{}", i); sum = sum + i; } + first_ten(|i| { info!("main"); info!("{}", i); sum = sum + i; }); info!("sum"); info!("{}", sum); assert_eq!(sum, 45); diff --git a/src/test/run-pass/foreign-fn-linkname.rs b/src/test/run-pass/foreign-fn-linkname.rs index d05680651f7dd..aeba5c0ec97e1 100644 --- a/src/test/run-pass/foreign-fn-linkname.rs +++ b/src/test/run-pass/foreign-fn-linkname.rs @@ -22,11 +22,11 @@ mod libc { fn strlen(str: ~str) -> uint { // C string is terminated with a zero - do str.with_c_str |buf| { + str.with_c_str(|buf| { unsafe { libc::my_strlen(buf) as uint } - } + }) } pub fn main() { diff --git a/src/test/run-pass/issue-1458.rs b/src/test/run-pass/issue-1458.rs deleted file mode 100644 index ce5c932f8da2e..0000000000000 --- a/src/test/run-pass/issue-1458.rs +++ /dev/null @@ -1,22 +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. - -fn plus_one(f: || -> int) -> int { - return f() + 1; -} - -fn ret_plus_one() -> extern fn(|| -> int) -> int { - return plus_one; -} - -pub fn main() { - let z = do (ret_plus_one()) || { 2 }; - assert_eq!(z, 3); -} diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index 110bceced82a1..d8c12d8511c32 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -19,9 +19,7 @@ impl Drop for socket { impl socket { pub fn set_identity(&self) { - do closure { - setsockopt_bytes(self.sock.clone()) - } + closure(|| setsockopt_bytes(self.sock.clone())) } } diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 2d590f25af1d1..f3c74cd929596 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -59,9 +59,9 @@ fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, extra::jso { &extra::json::List(ref interfaces) => { - do interfaces.map |interface| { + interfaces.map(|interface| { add_interface(store, managed_ip.clone(), (*interface).clone()) - } + }) } _ => { diff --git a/src/test/run-pass/issue-3211.rs b/src/test/run-pass/issue-3211.rs index 5e89cb2dd3676..3d8300010d9d5 100644 --- a/src/test/run-pass/issue-3211.rs +++ b/src/test/run-pass/issue-3211.rs @@ -1,8 +1,6 @@ pub fn main() { let mut x = 0; - do 4096.times { - x += 1; - } + 4096.times(|| x += 1); assert_eq!(x, 4096); println!("x = {}", x); } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 50d6a3ae6b8db..4bb89e2cf1711 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -64,11 +64,9 @@ impl Drop for AsciiArt { fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt { // Use an anonymous function to build a vector of vectors containing // blank characters for each position in our canvas. - let lines = do vec::build(Some(height)) |push| { - do height.times { - push(vec::from_elem(width, '.')); - } - }; + let lines = vec::build(Some(height), |push| { + height.times(|| push(vec::from_elem(width, '.'))) + }); // Rust code often returns values by omitting the trailing semi-colon // instead of using an explicit return statement. @@ -101,7 +99,7 @@ impl AsciiArt { impl ToStr for AsciiArt { fn to_str(&self) -> ~str { // Convert each line into a string. - let lines = do self.lines.map |line| {str::from_chars(*line)}; + let lines = self.lines.map(|line| str::from_chars(*line)); // Concatenate the lines together using a new-line. lines.connect("\n") diff --git a/src/test/run-pass/issue-4401.rs b/src/test/run-pass/issue-4401.rs index ab38d7650dad3..a6041c79eac1b 100644 --- a/src/test/run-pass/issue-4401.rs +++ b/src/test/run-pass/issue-4401.rs @@ -1,8 +1,6 @@ pub fn main() { let mut count = 0; - do 999_999.times() { - count += 1; - } + 999_999.times(|| count += 1); assert_eq!(count, 999_999); println!("{}", count); } diff --git a/src/test/run-pass/issue-5321-immediates-with-bare-self.rs b/src/test/run-pass/issue-5321-immediates-with-bare-self.rs index 3f1dc2f6986f6..4a0236b2da8d0 100644 --- a/src/test/run-pass/issue-5321-immediates-with-bare-self.rs +++ b/src/test/run-pass/issue-5321-immediates-with-bare-self.rs @@ -14,9 +14,7 @@ trait Fooable { impl Fooable for uint { fn yes(self) { - do self.times { - println("yes"); - } + self.times(|| println("yes")); } } diff --git a/src/test/run-pass/issue-6153.rs b/src/test/run-pass/issue-6153.rs index f7d0316880a4d..989a8e5f9c2c4 100644 --- a/src/test/run-pass/issue-6153.rs +++ b/src/test/run-pass/issue-6153.rs @@ -15,6 +15,6 @@ fn swap(f: |~[int]| -> ~[int]) -> ~[int] { pub fn main() { let v = swap(|mut x| { x.push(4); x }); - let w = do swap |mut x| { x.push(4); x }; + let w = swap(|mut x| { x.push(4); x }); assert_eq!(v, w); } diff --git a/src/test/run-pass/match-ref-binding-in-guard-3256.rs b/src/test/run-pass/match-ref-binding-in-guard-3256.rs index e1d2f0e1c4847..de4da6e3b06d7 100644 --- a/src/test/run-pass/match-ref-binding-in-guard-3256.rs +++ b/src/test/run-pass/match-ref-binding-in-guard-3256.rs @@ -15,7 +15,7 @@ pub fn main() { let x = Some(unstable::sync::Exclusive::new(true)); match x { Some(ref z) if z.with(|b| *b) => { - do z.with |b| { assert!(*b); } + z.with(|b| assert!(*b)); }, _ => fail!() } diff --git a/src/test/run-pass/newlambdas.rs b/src/test/run-pass/newlambdas.rs index 1835514c0d1fe..043136fdad995 100644 --- a/src/test/run-pass/newlambdas.rs +++ b/src/test/run-pass/newlambdas.rs @@ -17,6 +17,6 @@ fn g(_g: ||) { } pub fn main() { assert_eq!(f(10, |a| a), 10); g(||()); - assert_eq!(do f(10) |a| { a }, 10); - do g() { } + assert_eq!(f(10, |a| a), 10); + g(||{}); } diff --git a/src/test/run-pass/once-move-out-on-stack.rs b/src/test/run-pass/once-move-out-on-stack.rs index 645948f142625..9995edf5998e4 100644 --- a/src/test/run-pass/once-move-out-on-stack.rs +++ b/src/test/run-pass/once-move-out-on-stack.rs @@ -23,8 +23,8 @@ fn foo(blk: once ||) { fn main() { let x = arc::Arc::new(true); - do foo { + foo(|| { assert!(*x.get()); util::ignore(x); - } + }) } diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 96081d30275fb..6e5aa1aaf8b69 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -37,16 +37,12 @@ impl ptr_visit_adaptor { #[inline(always)] pub fn bump(&mut self, sz: uint) { - do self.inner.move_ptr() |p| { - ((p as uint) + sz) as *c_void - }; + self.inner.move_ptr(|p| ((p as uint) + sz) as *c_void) } #[inline(always)] pub fn align(&mut self, a: uint) { - do self.inner.move_ptr() |p| { - align(p as uint, a) as *c_void - }; + self.inner.move_ptr(|p| align(p as uint, a) as *c_void) } #[inline(always)] @@ -501,15 +497,11 @@ impl TyVisitor for my_visitor { fn visit_bot(&mut self) -> bool { true } fn visit_nil(&mut self) -> bool { true } fn visit_bool(&mut self) -> bool { - do self.get::() |b| { - self.vals.push(b.to_str()); - }; + self.get::(|b| self.vals.push(b.to_str())); true } fn visit_int(&mut self) -> bool { - do self.get::() |i| { - self.vals.push(i.to_str()); - }; + self.get::(|i| self.vals.push(i.to_str())); true } fn visit_i8(&mut self) -> bool { true } diff --git a/src/test/run-pass/regions-infer-call-2.rs b/src/test/run-pass/regions-infer-call-2.rs index 061f27972871f..3350c3b65d090 100644 --- a/src/test/run-pass/regions-infer-call-2.rs +++ b/src/test/run-pass/regions-infer-call-2.rs @@ -15,7 +15,7 @@ fn with(f: |x: &int| -> T) -> T { } fn has_one<'a>(x: &'a int) -> int { - do with |y| { takes_two(x, y) } + with(|y| takes_two(x, y)) } pub fn main() { diff --git a/src/test/run-pass/rename-directory.rs b/src/test/run-pass/rename-directory.rs index d20f2bfef3bad..fa4321451db91 100644 --- a/src/test/run-pass/rename-directory.rs +++ b/src/test/run-pass/rename-directory.rs @@ -31,20 +31,20 @@ fn rename_directory() { let test_file = &old_path.join("temp.txt"); /* Write the temp input file */ - let ostream = do test_file.with_c_str |fromp| { - do "w+b".with_c_str |modebuf| { + let ostream = test_file.with_c_str(|fromp| { + "w+b".with_c_str(|modebuf| { libc::fopen(fromp, modebuf) - } - }; + }) + }); assert!((ostream as uint != 0u)); let s = ~"hello"; - do "hello".with_c_str |buf| { + "hello".with_c_str(|buf| { let write_len = libc::fwrite(buf as *libc::c_void, 1u as libc::size_t, (s.len() + 1u) as libc::size_t, ostream); assert_eq!(write_len, (s.len() + 1) as libc::size_t) - } + }); assert_eq!(libc::fclose(ostream), (0u as libc::c_int)); let new_path = tmpdir.join_many(["quux", "blat"]); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index 7b331c4356807..1b7c3a1f52ecc 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -93,9 +93,9 @@ fn check_legs(arc: arc::Arc<~[~Pet:Freeze+Send]>) { } fn check_names(arc: arc::Arc<~[~Pet:Freeze+Send]>) { for pet in arc.get().iter() { - do pet.name |name| { + pet.name(|name| { assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8); - } + }) } } fn check_pedigree(arc: arc::Arc<~[~Pet:Freeze+Send]>) { diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs index 042b5e96bbc08..ff7ffb6dc6f00 100644 --- a/src/test/run-pass/type-params-in-for-each.rs +++ b/src/test/run-pass/type-params-in-for-each.rs @@ -19,9 +19,9 @@ fn range_(lo: uint, hi: uint, it: |uint|) { } fn create_index(_index: ~[S], _hash_fn: extern fn(T) -> uint) { - do range_(0u, 256u) |_i| { + range_(0u, 256u, |_i| { let _bucket: ~[T] = ~[]; - } + }) } pub fn main() { } diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index 06026d58f6005..9cb2f22d38e94 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -26,16 +26,16 @@ pub fn main() { unsafe { // Call with just the named parameter - do "Hello World\n".with_c_str |c| { + "Hello World\n".with_c_str(|c| { check("Hello World\n", |s| sprintf(s, c)); - } + }); // Call with variable number of arguments - do "%d %f %c %s\n".with_c_str |c| { - do check("42 42.500000 a %d %f %c %s\n\n") |s| { + "%d %f %c %s\n".with_c_str(|c| { + check("42 42.500000 a %d %f %c %s\n\n", |s| { sprintf(s, c, 42i, 42.5f64, 'a' as c_int, c); - } - } + }) + }); // Make a function pointer let x: extern "C" unsafe fn(*mut c_char, *c_char, ...) -> c_int = sprintf; @@ -43,16 +43,16 @@ pub fn main() { // A function that takes a function pointer unsafe fn call(p: extern "C" unsafe fn(*mut c_char, *c_char, ...) -> c_int) { // Call with just the named parameter via fn pointer - do "Hello World\n".with_c_str |c| { + "Hello World\n".with_c_str(|c| { check("Hello World\n", |s| p(s, c)); - } + }); // Call with variable number of arguments - do "%d %f %c %s\n".with_c_str |c| { - do check("42 42.500000 a %d %f %c %s\n\n") |s| { + "%d %f %c %s\n".with_c_str(|c| { + check("42 42.500000 a %d %f %c %s\n\n", |s| { p(s, c, 42i, 42.5f64, 'a' as c_int, c); - } - } + }) + }); } // Pass sprintf directly diff --git a/src/test/run-pass/writealias.rs b/src/test/run-pass/writealias.rs index 2db954d27c10b..8142cafd89e91 100644 --- a/src/test/run-pass/writealias.rs +++ b/src/test/run-pass/writealias.rs @@ -20,7 +20,7 @@ pub fn main() { let x = Some(unstable::sync::Exclusive::new(true)); match x { Some(ref z) if z.with(|b| *b) => { - do z.with |b| { assert!(*b); } + z.with(|b| assert!(*b)); }, _ => fail!() } diff --git a/src/test/run-pass/xc_conditions_client.rs b/src/test/run-pass/xc_conditions_client.rs index 730ed18fbbd45..99df4b771c5ee 100644 --- a/src/test/run-pass/xc_conditions_client.rs +++ b/src/test/run-pass/xc_conditions_client.rs @@ -33,8 +33,8 @@ use xc_conditions::trouble; // there's no cross-crate-ness to test in that case. pub fn main() { - do oops::cond.trap(|_i| 12345).inside { + oops::cond.trap(|_i| 12345).inside(|| { let x = trouble(); assert_eq!(x,12345); - } + }) } diff --git a/src/test/run-pass/xc_conditions_client_2.rs b/src/test/run-pass/xc_conditions_client_2.rs index 9666c037449f1..b3164f1f0aa5d 100644 --- a/src/test/run-pass/xc_conditions_client_2.rs +++ b/src/test/run-pass/xc_conditions_client_2.rs @@ -15,7 +15,5 @@ extern mod xc_conditions_2; use xcc = xc_conditions_2; pub fn main() { - do xcc::oops::cond.trap(|_| 1).inside { - xcc::oops::cond.raise(1); - } + xcc::oops::cond.trap(|_| 1).inside(|| xcc::oops::cond.raise(1)); } diff --git a/src/test/run-pass/xc_conditions_client_4.rs b/src/test/run-pass/xc_conditions_client_4.rs index 69ddb3701b099..e8eea00e49249 100644 --- a/src/test/run-pass/xc_conditions_client_4.rs +++ b/src/test/run-pass/xc_conditions_client_4.rs @@ -25,8 +25,8 @@ impl xcc::Thunk for SThunk { } pub fn main() { - do xcc::oops::cond.trap(|_| xcc::Red).inside { + xcc::oops::cond.trap(|_| xcc::Red).inside(|| { let t = SThunk { x : 10 }; assert_eq!(xcc::callback(t), xcc::Red) - } + }) } diff --git a/src/test/run-pass/xcrate-static-addresses.rs b/src/test/run-pass/xcrate-static-addresses.rs index 7eb4adfd06757..2ea8ab864e162 100644 --- a/src/test/run-pass/xcrate-static-addresses.rs +++ b/src/test/run-pass/xcrate-static-addresses.rs @@ -21,8 +21,8 @@ pub fn main() { // Previously this fail'd because there were two addresses that were being // used when declaring constants. - do other::test::cond.trap(|_| { - }).inside { + other::test::cond.trap(|_| { + }).inside(|| { other::raise(); - } + }) } From 38efa17bb8b9c1077e7b8cd9d67da08dec3f0bda Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Nov 2013 19:20:48 -0800 Subject: [PATCH 09/12] test: Remove all remaining non-procedure uses of `do`. --- doc/rust.md | 30 +-- doc/tutorial-conditions.md | 20 +- doc/tutorial-tasks.md | 4 +- doc/tutorial.md | 33 +-- src/libextra/arena.rs | 8 +- src/libextra/base64.rs | 12 +- src/libextra/bitv.rs | 72 +++--- src/libextra/comm.rs | 4 +- src/libextra/container.rs | 16 +- src/libextra/dlist.rs | 48 ++-- src/libextra/flate.rs | 12 +- src/libextra/hex.rs | 8 +- src/libextra/json.rs | 32 +-- src/libextra/num/bigint.rs | 16 +- src/libextra/ringbuf.rs | 20 +- src/libextra/sort.rs | 40 +-- src/libextra/sync.rs | 232 +++++++++--------- src/libextra/task_pool.rs | 4 +- src/libextra/treemap.rs | 16 +- src/libextra/uuid.rs | 12 +- src/librustpkg/tests.rs | 2 +- src/librustuv/lib.rs | 4 +- src/libsyntax/util/parser_testing.rs | 16 +- src/test/bench/core-map.rs | 37 ++- src/test/bench/core-set.rs | 24 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 8 +- src/test/bench/msgsend-ring-rw-arcs.rs | 8 +- src/test/bench/rt-messaging-ping-pong.rs | 13 +- src/test/bench/rt-spawn-rate.rs | 4 +- src/test/bench/shootout-binarytrees.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/bench/shootout-meteor.rs | 2 +- src/test/bench/sudoku.rs | 6 +- src/test/bench/task-perf-one-million.rs | 8 +- 34 files changed, 386 insertions(+), 393 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index bfc18a8473bc3..4fca2b33696eb 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -2703,22 +2703,16 @@ A `loop` expression is only permitted in the body of a loop. do_expr : "do" expr [ '|' ident_list '|' ] ? '{' block '}' ; ~~~~ -A _do expression_ provides a more-familiar block-syntax for a [lambda expression](#lambda-expressions), -including a special translation of [return expressions](#return-expressions) inside the supplied block. - -Any occurrence of a [return expression](#return-expressions) -inside this `block` expression is rewritten -as a reference to an (anonymous) flag set in the caller's environment, -which is checked on return from the `expr` and, if set, -causes a corresponding return from the caller. -In this way, the meaning of `return` statements in language built-in control blocks is preserved, -if they are rewritten using lambda functions and `do` expressions as abstractions. - -The optional `ident_list` and `block` provided in a `do` expression are parsed as though they constitute a lambda expression; +A _do expression_ provides a more-familiar block syntax +for invoking a function and passing it a newly-created a procedure. + +The optional `ident_list` and `block` provided in a `do` expression are parsed +as though they constitute a procedure expression; if the `ident_list` is missing, an empty `ident_list` is implied. -The lambda expression is then provided as a _trailing argument_ -to the outermost [call](#call-expressions) or [method call](#method-call-expressions) expression +The procedure expression is then provided as a _trailing argument_ +to the outermost [call](#call-expressions) or +[method call](#method-call-expressions) expression in the `expr` following `do`. If the `expr` is a [path expression](#path-expressions), it is parsed as though it is a call expression. If the `expr` is a [field expression](#field-expressions), it is parsed as though it is a method call expression. @@ -2726,10 +2720,10 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug In this example, both calls to `f` are equivalent: ~~~~ -# fn f(f: |int|) { } +# fn f(f: proc(int)) { } # fn g(i: int) { } -f(|j| g(j)); +f(proc(j) { g(j) }); do f |j| { g(j); @@ -2739,10 +2733,10 @@ do f |j| { In this example, both calls to the (binary) function `k` are equivalent: ~~~~ -# fn k(x:int, f: |int|) { } +# fn k(x:int, f: proc(int)) { } # fn l(i: int) { } -k(3, |j| l(j)); +k(3, proc(j) { l(j) }); do k(3) |j| { l(j); diff --git a/doc/tutorial-conditions.md b/doc/tutorial-conditions.md index 15b4a430ec1c7..2fb35fce9c46a 100644 --- a/doc/tutorial-conditions.md +++ b/doc/tutorial-conditions.md @@ -457,7 +457,7 @@ condition! { fn main() { // Trap the condition: - do malformed_line::cond.trap(|_| (-1,-1)).inside { + malformed_line::cond.trap(|_| (-1,-1)).inside(|| { // The protected logic. let pairs = read_int_pairs(); @@ -465,7 +465,7 @@ fn main() { println!("{:4.4d}, {:4.4d}", a, b); } - } + }) } fn read_int_pairs() -> ~[(int,int)] { @@ -535,7 +535,7 @@ condition! { fn main() { // Trap the condition and return `None` - do malformed_line::cond.trap(|_| None).inside { + malformed_line::cond.trap(|_| None).inside(|| { // The protected logic. let pairs = read_int_pairs(); @@ -543,7 +543,7 @@ fn main() { println!("{:4.4d}, {:4.4d}", a, b); } - } + }) } fn read_int_pairs() -> ~[(int,int)] { @@ -631,7 +631,7 @@ condition! { fn main() { // Trap the condition and return `UsePreviousLine` - do malformed_line::cond.trap(|_| UsePreviousLine).inside { + malformed_line::cond.trap(|_| UsePreviousLine).inside(|| { // The protected logic. let pairs = read_int_pairs(); @@ -639,7 +639,7 @@ fn main() { println!("{:4.4d}, {:4.4d}", a, b); } - } + }) } fn read_int_pairs() -> ~[(int,int)] { @@ -758,10 +758,10 @@ condition! { fn main() { // Trap the `malformed_int` condition and return -1 - do malformed_int::cond.trap(|_| -1).inside { + malformed_int::cond.trap(|_| -1).inside(|| { // Trap the `malformed_line` condition and return `UsePreviousLine` - do malformed_line::cond.trap(|_| UsePreviousLine).inside { + malformed_line::cond.trap(|_| UsePreviousLine).inside(|| { // The protected logic. let pairs = read_int_pairs(); @@ -769,8 +769,8 @@ fn main() { println!("{:4.4d}, {:4.4d}", a, b); } - } - } + }) + }) } // Parse an int; if parsing fails, call the condition handler and diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 04a3bfe9c2a4e..3017bc8b7ea01 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -253,13 +253,13 @@ might look like the example below. # use std::vec; // Create a vector of ports, one for each child task -let ports = do vec::from_fn(3) |init_val| { +let ports = vec::from_fn(3, |init_val| { let (port, chan) = stream(); do spawn { chan.send(some_expensive_computation(init_val)); } port -}; +}); // Wait on each port, accumulating the results let result = ports.iter().fold(0, |accum, port| accum + port.recv() ); diff --git a/doc/tutorial.md b/doc/tutorial.md index 4e6fd9e18d257..1559033a582aa 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1439,19 +1439,14 @@ call_twice(function); ## Do syntax -The `do` expression provides a way to treat higher-order functions -(functions that take closures as arguments) as control structures. +The `do` expression makes it easier to call functions that take procedures +as arguments. -Consider this function that iterates over a vector of -integers, passing in a pointer to each integer in the vector: +Consider this function that takes a procedure: ~~~~ -fn each(v: &[int], op: |v: &int|) { - let mut n = 0; - while n < v.len() { - op(&v[n]); - n += 1; - } +fn call_it(op: proc(v: int)) { + op(10) } ~~~~ @@ -1460,26 +1455,24 @@ argument, we can write it in a way that has a pleasant, block-like structure. ~~~~ -# fn each(v: &[int], op: |v: &int|) { } -# fn do_some_work(i: &int) { } -each([1, 2, 3], |n| { - do_some_work(n); +# fn call_it(op: proc(v: int)) { } +call_it(proc(n) { + println(n.to_str()); }); ~~~~ This is such a useful pattern that Rust has a special form of function -call that can be written more like a built-in control structure: +call for these functions. ~~~~ -# fn each(v: &[int], op: |v: &int|) { } -# fn do_some_work(i: &int) { } -do each([1, 2, 3]) |n| { - do_some_work(n); +# fn call_it(op: proc(v: int)) { } +do call_it() |n| { + println(n.to_str()); } ~~~~ The call is prefixed with the keyword `do` and, instead of writing the -final closure inside the argument list, it appears outside of the +final procedure inside the argument list, it appears outside of the parentheses, where it looks more like a typical block of code. diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 7da9ac2aed80b..8aa89f86642a5 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -297,14 +297,14 @@ fn test_arena_destructors_fail() { for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it // doesn't leak. - do arena.alloc { @i }; + arena.alloc(|| { @i }); // Allocate something with funny size and alignment, to keep // things interesting. - do arena.alloc { [0u8, 1u8, 2u8] }; + arena.alloc(|| { [0u8, 1u8, 2u8] }); } // Now, fail while allocating - do arena.alloc::<@int> { + arena.alloc::<@int>(|| { // Now fail. fail!(); - }; + }); } diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index cfcd508e4d45f..94e3917a7ecdf 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -317,20 +317,20 @@ mod test { use std::rand::{task_rng, random, Rng}; use std::vec; - do 1000.times { + 1000.times(|| { let times = task_rng().gen_range(1u, 100); let v = vec::from_fn(times, |_| random::()); assert_eq!(v.to_base64(STANDARD).from_base64().unwrap(), v); - } + }) } #[bench] pub fn bench_to_base64(bh: & mut BenchHarness) { let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \ ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; - do bh.iter { + bh.iter(|| { s.as_bytes().to_base64(STANDARD); - } + }); bh.bytes = s.len() as u64; } @@ -339,9 +339,9 @@ mod test { let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \ ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let b = s.as_bytes().to_base64(STANDARD); - do bh.iter { + bh.iter(|| { b.from_base64(); - } + }); bh.bytes = b.len() as u64; } diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 306a2abca5506..09137d6bb7451 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -1362,18 +1362,18 @@ mod tests { fn test_small_clear() { let mut b = Bitv::new(14, true); b.clear(); - do b.ones |i| { + b.ones(|i| { fail!("found 1 at {:?}", i) - }; + }); } #[test] fn test_big_clear() { let mut b = Bitv::new(140, true); b.clear(); - do b.ones |i| { + b.ones(|i| { fail!("found 1 at {:?}", i) - }; + }); } #[test] @@ -1408,11 +1408,11 @@ mod tests { let mut i = 0; let expected = [3, 5, 11, 77]; - do a.intersection(&b) |x| { + a.intersection(&b, |x| { assert_eq!(*x, expected[i]); i += 1; true - }; + }); assert_eq!(i, expected.len()); } @@ -1432,11 +1432,11 @@ mod tests { let mut i = 0; let expected = [1, 5, 500]; - do a.difference(&b) |x| { + a.difference(&b, |x| { assert_eq!(*x, expected[i]); i += 1; true - }; + }); assert_eq!(i, expected.len()); } @@ -1458,11 +1458,11 @@ mod tests { let mut i = 0; let expected = [1, 5, 11, 14, 220]; - do a.symmetric_difference(&b) |x| { + a.symmetric_difference(&b, |x| { assert_eq!(*x, expected[i]); i += 1; true - }; + }); assert_eq!(i, expected.len()); } @@ -1487,11 +1487,11 @@ mod tests { let mut i = 0; let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160]; - do a.union(&b) |x| { + a.union(&b, |x| { assert_eq!(*x, expected[i]); i += 1; true - }; + }); assert_eq!(i, expected.len()); } @@ -1538,27 +1538,27 @@ mod tests { fn bench_uint_small(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = 0 as uint; - do b.iter { + b.iter(|| { bitv |= (1 << ((r.next_u32() as uint) % uint::bits)); - } + }) } #[bench] fn bench_small_bitv_small(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = SmallBitv::new(uint::bits); - do b.iter { + b.iter(|| { bitv.set((r.next_u32() as uint) % uint::bits, true); - } + }) } #[bench] fn bench_big_bitv_small(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = BigBitv::new(~[0]); - do b.iter { + b.iter(|| { bitv.set((r.next_u32() as uint) % uint::bits, true); - } + }) } #[bench] @@ -1567,87 +1567,87 @@ mod tests { let mut storage = ~[]; storage.grow(BENCH_BITS / uint::bits, &0u); let mut bitv = BigBitv::new(storage); - do b.iter { + b.iter(|| { bitv.set((r.next_u32() as uint) % BENCH_BITS, true); - } + }) } #[bench] fn bench_bitv_big(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = Bitv::new(BENCH_BITS, false); - do b.iter { + b.iter(|| { bitv.set((r.next_u32() as uint) % BENCH_BITS, true); - } + }) } #[bench] fn bench_bitv_small(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = Bitv::new(uint::bits, false); - do b.iter { + b.iter(|| { bitv.set((r.next_u32() as uint) % uint::bits, true); - } + }) } #[bench] fn bench_bitv_set_small(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = BitvSet::new(); - do b.iter { + b.iter(|| { bitv.insert((r.next_u32() as uint) % uint::bits); - } + }) } #[bench] fn bench_bitv_set_big(b: &mut BenchHarness) { let mut r = rng(); let mut bitv = BitvSet::new(); - do b.iter { + b.iter(|| { bitv.insert((r.next_u32() as uint) % BENCH_BITS); - } + }) } #[bench] fn bench_bitv_big_union(b: &mut BenchHarness) { let mut b1 = Bitv::new(BENCH_BITS, false); let b2 = Bitv::new(BENCH_BITS, false); - do b.iter { + b.iter(|| { b1.union(&b2); - } + }) } #[bench] fn bench_btv_small_iter(b: &mut BenchHarness) { let bitv = Bitv::new(uint::bits, false); - do b.iter { + b.iter(|| { let mut _sum = 0; for pres in bitv.iter() { _sum += pres as uint; } - } + }) } #[bench] fn bench_bitv_big_iter(b: &mut BenchHarness) { let bitv = Bitv::new(BENCH_BITS, false); - do b.iter { + b.iter(|| { let mut _sum = 0; for pres in bitv.iter() { _sum += pres as uint; } - } + }) } #[bench] fn bench_bitvset_iter(b: &mut BenchHarness) { let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS, |idx| {idx % 3 == 0})); - do b.iter { + b.iter(|| { let mut _sum = 0; for idx in bitv.iter() { _sum += idx; } - } + }) } } diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index d24f285ced21e..42287736ffa5f 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -167,9 +167,9 @@ mod test { do run_in_uv_task { let (port, chan) = rendezvous(); do spawn { - do 1000000.times { chan.send(()) } + 1000000.times(|| { chan.send(()) }) } - do 1000000.times { port.recv() } + 1000000.times(|| { port.recv() }) } } diff --git a/src/libextra/container.rs b/src/libextra/container.rs index cbc2f08679bb6..0ba00510ed8b5 100644 --- a/src/libextra/container.rs +++ b/src/libextra/container.rs @@ -58,11 +58,11 @@ pub mod bench { } // measure - do bh.iter { + bh.iter(|| { let k = rng.gen::() % n; map.insert(k, 1); map.remove(&k); - } + }) } pub fn insert_seq_n>(n: uint, @@ -76,11 +76,11 @@ pub mod bench { // measure let mut i = 1; - do bh.iter { + bh.iter(|| { map.insert(i, 1); map.remove(&i); i = (i + 2) % n; - } + }) } pub fn find_rand_n>(n: uint, @@ -98,10 +98,10 @@ pub mod bench { // measure let mut i = 0; - do bh.iter { + bh.iter(|| { map.find(&(keys[i])); i = (i + 1) % n; - } + }) } pub fn find_seq_n>(n: uint, @@ -114,9 +114,9 @@ pub mod bench { // measure let mut i = 0; - do bh.iter { + bh.iter(|| { map.find(&i); i = (i + 1) % n; - } + }) } } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index a261a2483052f..22109c98dc863 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -1031,11 +1031,11 @@ mod tests { #[test] fn test_fuzz() { - do 25.times { + 25.times(|| { fuzz_test(3); fuzz_test(16); fuzz_test(189); - } + }) } #[cfg(test)] @@ -1078,43 +1078,43 @@ mod tests { #[bench] fn bench_collect_into(b: &mut test::BenchHarness) { let v = &[0, ..64]; - do b.iter { + b.iter(|| { let _: DList = v.iter().map(|x| *x).collect(); - } + }) } #[bench] fn bench_push_front(b: &mut test::BenchHarness) { let mut m: DList = DList::new(); - do b.iter { + b.iter(|| { m.push_front(0); - } + }) } #[bench] fn bench_push_back(b: &mut test::BenchHarness) { let mut m: DList = DList::new(); - do b.iter { + b.iter(|| { m.push_back(0); - } + }) } #[bench] fn bench_push_back_pop_back(b: &mut test::BenchHarness) { let mut m: DList = DList::new(); - do b.iter { + b.iter(|| { m.push_back(0); m.pop_back(); - } + }) } #[bench] fn bench_push_front_pop_front(b: &mut test::BenchHarness) { let mut m: DList = DList::new(); - do b.iter { + b.iter(|| { m.push_front(0); m.pop_front(); - } + }) } #[bench] @@ -1122,9 +1122,9 @@ mod tests { let mut m: DList = DList::new(); m.push_front(0); m.push_front(1); - do b.iter { + b.iter(|| { m.rotate_forward(); - } + }) } #[bench] @@ -1132,41 +1132,41 @@ mod tests { let mut m: DList = DList::new(); m.push_front(0); m.push_front(1); - do b.iter { + b.iter(|| { m.rotate_backward(); - } + }) } #[bench] fn bench_iter(b: &mut test::BenchHarness) { let v = &[0, ..128]; let m: DList = v.iter().map(|&x|x).collect(); - do b.iter { + b.iter(|| { assert!(m.iter().len() == 128); - } + }) } #[bench] fn bench_iter_mut(b: &mut test::BenchHarness) { let v = &[0, ..128]; let mut m: DList = v.iter().map(|&x|x).collect(); - do b.iter { + b.iter(|| { assert!(m.mut_iter().len() == 128); - } + }) } #[bench] fn bench_iter_rev(b: &mut test::BenchHarness) { let v = &[0, ..128]; let m: DList = v.iter().map(|&x|x).collect(); - do b.iter { + b.iter(|| { assert!(m.rev_iter().len() == 128); - } + }) } #[bench] fn bench_iter_mut_rev(b: &mut test::BenchHarness) { let v = &[0, ..128]; let mut m: DList = v.iter().map(|&x|x).collect(); - do b.iter { + b.iter(|| { assert!(m.mut_rev_iter().len() == 128); - } + }) } } diff --git a/src/libextra/flate.rs b/src/libextra/flate.rs index 1a295010dc4dd..3d1d0c91e317d 100644 --- a/src/libextra/flate.rs +++ b/src/libextra/flate.rs @@ -108,15 +108,15 @@ mod tests { fn test_flate_round_trip() { let mut r = rand::rng(); let mut words = ~[]; - do 20.times { + 20.times(|| { let range = r.gen_range(1u, 10); words.push(r.gen_vec::(range)); - } - do 20.times { + }); + 20.times(|| { let mut input = ~[]; - do 2000.times { + 2000.times(|| { input.push_all(r.choose(words)); - } + }); debug!("de/inflate of {} bytes of random word-sequences", input.len()); let cmp = deflate_bytes(input); @@ -125,7 +125,7 @@ mod tests { input.len(), cmp.len(), 100.0 * ((cmp.len() as f64) / (input.len() as f64))); assert_eq!(input, out); - } + }); } #[test] diff --git a/src/libextra/hex.rs b/src/libextra/hex.rs index 714fc4d8253f9..5a1d1308f8cda 100644 --- a/src/libextra/hex.rs +++ b/src/libextra/hex.rs @@ -174,9 +174,9 @@ mod tests { pub fn bench_to_hex(bh: & mut BenchHarness) { let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \ ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; - do bh.iter { + bh.iter(|| { s.as_bytes().to_hex(); - } + }); bh.bytes = s.len() as u64; } @@ -185,9 +185,9 @@ mod tests { let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \ ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let b = s.as_bytes().to_hex(); - do bh.iter { + bh.iter(|| { b.from_hex(); - } + }); bh.bytes = b.len() as u64; } } diff --git a/src/libextra/json.rs b/src/libextra/json.rs index cb138099cbced..c30963568286f 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -1521,33 +1521,33 @@ mod tests { fn test_write_enum() { let animal = Dog; assert_eq!( - do with_str_writer |wr| { + with_str_writer(|wr| { let mut encoder = Encoder(wr); animal.encode(&mut encoder); - }, + }), ~"\"Dog\"" ); assert_eq!( - do with_str_writer |wr| { + with_str_writer(|wr| { let mut encoder = PrettyEncoder(wr); animal.encode(&mut encoder); - }, + }), ~"\"Dog\"" ); let animal = Frog(~"Henry", 349); assert_eq!( - do with_str_writer |wr| { + with_str_writer(|wr| { let mut encoder = Encoder(wr); animal.encode(&mut encoder); - }, + }), ~"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}" ); assert_eq!( - do with_str_writer |wr| { + with_str_writer(|wr| { let mut encoder = PrettyEncoder(wr); animal.encode(&mut encoder); - }, + }), ~"\ [\n \ \"Frog\",\n \ @@ -1560,33 +1560,33 @@ mod tests { #[test] fn test_write_some() { let value = Some(~"jodhpurs"); - let s = do with_str_writer |wr| { + let s = with_str_writer(|wr| { let mut encoder = Encoder(wr); value.encode(&mut encoder); - }; + }); assert_eq!(s, ~"\"jodhpurs\""); let value = Some(~"jodhpurs"); - let s = do with_str_writer |wr| { + let s = with_str_writer(|wr| { let mut encoder = PrettyEncoder(wr); value.encode(&mut encoder); - }; + }); assert_eq!(s, ~"\"jodhpurs\""); } #[test] fn test_write_none() { let value: Option<~str> = None; - let s = do with_str_writer |wr| { + let s = with_str_writer(|wr| { let mut encoder = Encoder(wr); value.encode(&mut encoder); - }; + }); assert_eq!(s, ~"null"); - let s = do with_str_writer |wr| { + let s = with_str_writer(|wr| { let mut encoder = Encoder(wr); value.encode(&mut encoder); - }; + }); assert_eq!(s, ~"null"); } diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 5b3de10b8b08f..a37a0c39e304d 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -2615,19 +2615,27 @@ mod bench { #[bench] fn factorial_100(bh: &mut BenchHarness) { - bh.iter(|| factorial(100)); + bh.iter(|| { + factorial(100); + }); } #[bench] fn fib_100(bh: &mut BenchHarness) { - bh.iter(|| fib(100)); + bh.iter(|| { + fib(100); + }); } #[bench] fn to_str(bh: &mut BenchHarness) { let fac = factorial(100); let fib = fib(100); - bh.iter(|| fac.to_str()); - bh.iter(|| fib.to_str()); + bh.iter(|| { + fac.to_str(); + }); + bh.iter(|| { + fib.to_str(); + }); } } diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index e7032db5a9195..f6bf6c21335f8 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -499,35 +499,35 @@ mod tests { #[bench] fn bench_new(b: &mut test::BenchHarness) { - do b.iter { + b.iter(|| { let _: RingBuf = RingBuf::new(); - } + }) } #[bench] fn bench_push_back(b: &mut test::BenchHarness) { let mut deq = RingBuf::new(); - do b.iter { + b.iter(|| { deq.push_back(0); - } + }) } #[bench] fn bench_push_front(b: &mut test::BenchHarness) { let mut deq = RingBuf::new(); - do b.iter { + b.iter(|| { deq.push_front(0); - } + }) } #[bench] fn bench_grow(b: &mut test::BenchHarness) { let mut deq = RingBuf::new(); - do b.iter { - do 65.times { + b.iter(|| { + 65.times(|| { deq.push_front(1); - } - } + }) + }) } #[deriving(Clone, Eq)] diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index 175eaa2a8db81..5d5696d778ffc 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -828,7 +828,7 @@ mod test_qsort { let expected = ~[1, 2, 3]; - do quick_sort(names) |x, y| { *x < *y }; + quick_sort(names, |x, y| *x < *y); let immut_names = names; @@ -968,9 +968,9 @@ mod test_tim_sort { #[cfg(unix)] fn crash_test() { let mut rng = rand::rng(); - let mut arr = do vec::from_fn(1000) |_i| { + let mut arr = vec::from_fn(1000, |_i| { CVal { val: rng.gen() } - }; + }); tim_sort(arr); fail!("Guarantee the fail"); @@ -991,9 +991,9 @@ mod test_tim_sort { #[test] fn test_bad_Ord_impl() { let mut rng = rand::rng(); - let mut arr = do vec::from_fn(500) |_i| { + let mut arr = vec::from_fn(500, |_i| { DVal { val: rng.gen() } - }; + }); tim_sort(arr); } @@ -1024,14 +1024,14 @@ mod big_tests { fn multiplyVec(arr: &[T], num: uint) -> ~[T] { let size = arr.len(); - let res = do vec::from_fn(num) |i| { + let res = vec::from_fn(num, |i| { arr[i % size].clone() - }; + }); res } fn makeRange(n: uint) -> ~[uint] { - let one = do vec::from_fn(n) |i| { i }; + let one = vec::from_fn(n, |i| i); let mut two = one.clone(); two.reverse(); vec::append(two, one) @@ -1050,9 +1050,9 @@ mod big_tests { for i in range(lo, hi) { let n = 1 << i; - let mut arr: ~[f64] = do vec::from_fn(n) |_i| { + let mut arr: ~[f64] = vec::from_fn(n, |_i| { rng.gen() - }; + }); tim_sort(arr); // *sort isSorted(arr); @@ -1064,11 +1064,11 @@ mod big_tests { tim_sort(arr); // /sort isSorted(arr); - do 3.times { + 3.times(|| { let i1 = rng.gen_range(0u, n); let i2 = rng.gen_range(0u, n); arr.swap(i1, i2); - } + }); tim_sort(arr); // 3sort isSorted(arr); @@ -1083,10 +1083,10 @@ mod big_tests { tim_sort(arr); // +sort isSorted(arr); - do (n/100).times { + (n/100).times(|| { let idx = rng.gen_range(0u, n); arr[idx] = rng.gen(); - } + }); tim_sort(arr); isSorted(arr); @@ -1121,9 +1121,9 @@ mod big_tests { for i in range(lo, hi) { let n = 1 << i; - let arr: ~[@f64] = do vec::from_fn(n) |_i| { + let arr: ~[@f64] = vec::from_fn(n, |_i| { @rng.gen() - }; + }); let mut arr = arr; tim_sort(arr); // *sort @@ -1136,11 +1136,11 @@ mod big_tests { tim_sort(arr); // /sort isSorted(arr); - do 3.times { + 3.times(|| { let i1 = rng.gen_range(0u, n); let i2 = rng.gen_range(0u, n); arr.swap(i1, i2); - } + }); tim_sort(arr); // 3sort isSorted(arr); @@ -1155,10 +1155,10 @@ mod big_tests { tim_sort(arr); // +sort isSorted(arr); - do (n/100).times { + (n/100).times(|| { let idx = rng.gen_range(0u, n); arr[idx] = @rng.gen(); - } + }); tim_sort(arr); isSorted(arr); diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index f87ba4ed6a3e0..0d5368695b79c 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -571,15 +571,15 @@ impl RWLock { * # Example * * ```rust - * do lock.write_downgrade |mut write_token| { - * do write_token.write_cond |condvar| { + * lock.write_downgrade(|mut write_token| { + * write_token.write_cond(|condvar| { * ... exclusive access ... - * } + * }); * let read_token = lock.downgrade(write_token); - * do read_token.read { + * read_token.read(|| { * ... shared access ... - * } - * } + * }) + * }) * ``` */ pub fn write_downgrade(&self, blk: |v: RWLockWriteMode| -> U) -> U { @@ -698,20 +698,20 @@ mod tests { #[test] fn test_sem_basic() { let s = Semaphore::new(1); - do s.access { } + s.access(|| { }) } #[test] fn test_sem_as_mutex() { let s = Semaphore::new(1); let s2 = s.clone(); do task::spawn { - do s2.access { - do 5.times { task::deschedule(); } - } - } - do s.access { - do 5.times { task::deschedule(); } + s2.access(|| { + 5.times(|| { task::deschedule(); }) + }) } + s.access(|| { + 5.times(|| { task::deschedule(); }) + }) } #[test] fn test_sem_as_cvar() { @@ -723,7 +723,7 @@ mod tests { s2.acquire(); c.send(()); } - do 5.times { task::deschedule(); } + 5.times(|| { task::deschedule(); }); s.release(); let _ = p.recv(); @@ -732,7 +732,7 @@ mod tests { let s = Semaphore::new(0); let s2 = s.clone(); do task::spawn { - do 5.times { task::deschedule(); } + 5.times(|| { task::deschedule(); }); s2.release(); let _ = p.recv(); } @@ -748,15 +748,15 @@ mod tests { let (p1,c1) = comm::stream(); let (p2,c2) = comm::stream(); do task::spawn { - do s2.access { + s2.access(|| { let _ = p2.recv(); c1.send(()); - } + }) } - do s.access { + s.access(|| { c2.send(()); let _ = p1.recv(); - } + }) } #[test] fn test_sem_runtime_friendly_blocking() { @@ -767,16 +767,16 @@ mod tests { let s2 = s.clone(); let (p, c) = comm::stream(); let child_data = Cell::new((s2, c)); - do s.access { + s.access(|| { let (s2, c) = child_data.take(); do task::spawn { c.send(()); - do s2.access { } + s2.access(|| { }); c.send(()); } let _ = p.recv(); // wait for child to come alive - do 5.times { task::deschedule(); } // let the child contend - } + 5.times(|| { task::deschedule(); }); // let the child contend + }); let _ = p.recv(); // wait for child to be done } } @@ -809,13 +809,13 @@ mod tests { } fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) { - do n.times { - do m.lock { + n.times(|| { + m.lock(|| { let oldval = *sharedstate; task::deschedule(); *sharedstate = oldval + 1; - } - } + }) + }) } } #[test] @@ -823,31 +823,31 @@ mod tests { let m = Mutex::new(); // Child wakes up parent - do m.lock_cond |cond| { + m.lock_cond(|cond| { let m2 = m.clone(); do task::spawn { - do m2.lock_cond |cond| { + m2.lock_cond(|cond| { let woken = cond.signal(); assert!(woken); - } + }) } cond.wait(); - } + }); // Parent wakes up child let (port,chan) = comm::stream(); let m3 = m.clone(); do task::spawn { - do m3.lock_cond |cond| { + m3.lock_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); - } + }) } let _ = port.recv(); // Wait until child gets in the mutex - do m.lock_cond |cond| { + m.lock_cond(|cond| { let woken = cond.signal(); assert!(woken); - } + }); let _ = port.recv(); // Wait until child wakes up } #[cfg(test)] @@ -855,25 +855,25 @@ mod tests { let m = Mutex::new(); let mut ports = ~[]; - do num_waiters.times { + num_waiters.times(|| { let mi = m.clone(); let (port, chan) = comm::stream(); ports.push(port); do task::spawn { - do mi.lock_cond |cond| { + mi.lock_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); - } + }) } - } + }); // wait until all children get in the mutex for port in ports.iter() { let _ = port.recv(); } - do m.lock_cond |cond| { + m.lock_cond(|cond| { let num_woken = cond.broadcast(); assert_eq!(num_woken, num_waiters); - } + }); // wait until all children wake up for port in ports.iter() { let _ = port.recv(); } } @@ -890,11 +890,11 @@ mod tests { let m = Mutex::new(); let m2 = m.clone(); do task::try { - do m.lock_cond |_x| { } + m.lock_cond(|_x| { }) }; - do m2.lock_cond |cond| { + m2.lock_cond(|cond| { assert!(!cond.signal()); - } + }) } #[test] fn test_mutex_killed_simple() { @@ -903,13 +903,13 @@ mod tests { let m2 = m.clone(); let result: result::Result<(), ~Any> = do task::try { - do m2.lock { + m2.lock(|| { fail!(); - } + }) }; assert!(result.is_err()); // child task must have finished by the time try returns - do m.lock { } + m.lock(|| { }) } #[ignore(reason = "linked failure")] #[test] @@ -926,17 +926,17 @@ mod tests { task::deschedule(); fail!(); } - do m2.lock_cond |cond| { + m2.lock_cond(|cond| { c.send(()); // tell sibling go ahead cond.wait(); // block forever - } + }) }; assert!(result.is_err()); // child task must have finished by the time try returns - do m.lock_cond |cond| { + m.lock_cond(|cond| { let woken = cond.signal(); assert!(!woken); - } + }) } #[ignore(reason = "linked failure")] #[test] @@ -949,30 +949,30 @@ mod tests { let result: result::Result<(), ~Any> = do task::try { let mut sibling_convos = ~[]; - do 2.times { + 2.times(|| { let (p, c) = comm::stream(); let c = Cell::new(c); sibling_convos.push(p); let mi = m2.clone(); // spawn sibling task do task::spawn { // linked - do mi.lock_cond |cond| { + mi.lock_cond(|cond| { let c = c.take(); c.send(()); // tell sibling to go ahead - do (|| { + (|| { cond.wait(); // block forever - }).finally { + }).finally(|| { error!("task unwinding and sending"); c.send(()); error!("task unwinding and done sending"); - } - } + }) + }) } - } + }); for p in sibling_convos.iter() { let _ = p.recv(); // wait for sibling to get in the mutex } - do m2.lock { } + m2.lock(|| { }); c.send(sibling_convos); // let parent wait on all children fail!(); }; @@ -980,24 +980,24 @@ mod tests { // child task must have finished by the time try returns let r = p.recv(); for p in r.iter() { p.recv(); } // wait on all its siblings - do m.lock_cond |cond| { + m.lock_cond(|cond| { let woken = cond.broadcast(); assert_eq!(woken, 0); - } + }) } #[test] fn test_mutex_cond_signal_on_0() { // Tests that signal_on(0) is equivalent to signal(). let m = Mutex::new(); - do m.lock_cond |cond| { + m.lock_cond(|cond| { let m2 = m.clone(); do task::spawn { - do m2.lock_cond |cond| { + m2.lock_cond(|cond| { cond.signal_on(0); - } + }) } cond.wait(); - } + }) } #[test] fn test_mutex_different_conds() { @@ -1006,17 +1006,17 @@ mod tests { let m2 = m.clone(); let (p, c) = comm::stream(); do task::spawn { - do m2.lock_cond |cond| { + m2.lock_cond(|cond| { c.send(()); cond.wait_on(1); - } + }) } let _ = p.recv(); - do m.lock_cond |cond| { + m.lock_cond(|cond| { if !cond.signal_on(0) { fail!(); // success; punt sibling awake. } - } + }) }; assert!(result.is_err()); } @@ -1024,17 +1024,17 @@ mod tests { fn test_mutex_no_condvars() { let result = do task::try { let m = Mutex::new_with_condvars(0); - do m.lock_cond |cond| { cond.wait(); } + m.lock_cond(|cond| { cond.wait(); }) }; assert!(result.is_err()); let result = do task::try { let m = Mutex::new_with_condvars(0); - do m.lock_cond |cond| { cond.signal(); } + m.lock_cond(|cond| { cond.signal(); }) }; assert!(result.is_err()); let result = do task::try { let m = Mutex::new_with_condvars(0); - do m.lock_cond |cond| { cond.broadcast(); } + m.lock_cond(|cond| { cond.broadcast(); }) }; assert!(result.is_err()); } @@ -1049,14 +1049,14 @@ mod tests { Read => x.read(blk), Write => x.write(blk), Downgrade => - do x.write_downgrade |mode| { - do mode.write { blk() }; - }, + x.write_downgrade(|mode| { + mode.write(|| { blk() }); + }), DowngradeRead => - do x.write_downgrade |mode| { + x.write_downgrade(|mode| { let mode = x.downgrade(mode); - do mode.read { blk() }; - }, + mode.read(|| { blk() }); + }), } } #[cfg(test)] @@ -1086,13 +1086,13 @@ mod tests { fn access_shared(sharedstate: &mut int, x: &RWLock, mode: RWLockMode, n: uint) { - do n.times { - do lock_rwlock_in_mode(x, mode) { + n.times(|| { + lock_rwlock_in_mode(x, mode, || { let oldval = *sharedstate; task::deschedule(); *sharedstate = oldval + 1; - } - } + }) + }) } } #[test] @@ -1122,24 +1122,24 @@ mod tests { if !make_mode2_go_first { let _ = p2.recv(); // parent sends to us once it locks, or ... } - do lock_rwlock_in_mode(&x2, mode2) { + lock_rwlock_in_mode(&x2, mode2, || { if make_mode2_go_first { c1.send(()); // ... we send to it once we lock } let _ = p2.recv(); c1.send(()); - } + }) } if make_mode2_go_first { let _ = p1.recv(); // child sends to us once it locks, or ... } - do lock_rwlock_in_mode(x, mode1) { + lock_rwlock_in_mode(x, mode1, || { if !make_mode2_go_first { c2.send(()); // ... we send to it once we lock } c2.send(()); let _ = p1.recv(); - } + }) } #[test] fn test_rwlock_readers_and_readers() { @@ -1154,16 +1154,16 @@ mod tests { fn test_rwlock_downgrade_unlock() { // Tests that downgrade can unlock the lock in both modes let x = RWLock::new(); - do lock_rwlock_in_mode(&x, Downgrade) { } + lock_rwlock_in_mode(&x, Downgrade, || { }); test_rwlock_handshake(&x, Read, Read, false); let y = RWLock::new(); - do lock_rwlock_in_mode(&y, DowngradeRead) { } + lock_rwlock_in_mode(&y, DowngradeRead, || { }); test_rwlock_exclusion(&y, Write, Write); } #[test] fn test_rwlock_read_recursive() { let x = RWLock::new(); - do x.read { do x.read { } } + x.read(|| { x.read(|| { }) }) } #[test] fn test_rwlock_cond_wait() { @@ -1171,34 +1171,34 @@ mod tests { let x = RWLock::new(); // Child wakes up parent - do x.write_cond |cond| { + x.write_cond(|cond| { let x2 = x.clone(); do task::spawn { - do x2.write_cond |cond| { + x2.write_cond(|cond| { let woken = cond.signal(); assert!(woken); - } + }) } cond.wait(); - } + }); // Parent wakes up child let (port, chan) = comm::stream(); let x3 = x.clone(); do task::spawn { - do x3.write_cond |cond| { + x3.write_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); - } + }) } let _ = port.recv(); // Wait until child gets in the rwlock - do x.read { } // Must be able to get in as a reader in the meantime - do x.write_cond |cond| { // Or as another writer + x.read(|| { }); // Must be able to get in as a reader in the meantime + x.write_cond(|cond| { // Or as another writer let woken = cond.signal(); assert!(woken); - } + }); let _ = port.recv(); // Wait until child wakes up - do x.read { } // Just for good measure + x.read(|| { }); // Just for good measure } #[cfg(test)] fn test_rwlock_cond_broadcast_helper(num_waiters: uint, @@ -1207,35 +1207,35 @@ mod tests { // Much like the mutex broadcast test. Downgrade-enabled. fn lock_cond(x: &RWLock, downgrade: bool, blk: |c: &Condvar|) { if downgrade { - do x.write_downgrade |mode| { - do mode.write_cond |c| { blk(c) } - } + x.write_downgrade(|mode| { + mode.write_cond(|c| { blk(c) }); + }); } else { - do x.write_cond |c| { blk(c) } + x.write_cond(|c| { blk(c) }); } } let x = RWLock::new(); let mut ports = ~[]; - do num_waiters.times { + num_waiters.times(|| { let xi = x.clone(); let (port, chan) = comm::stream(); ports.push(port); do task::spawn { - do lock_cond(&xi, dg1) |cond| { + lock_cond(&xi, dg1, |cond| { chan.send(()); cond.wait(); chan.send(()); - } + }) } - } + }); // wait until all children get in the mutex for port in ports.iter() { let _ = port.recv(); } - do lock_cond(&x, dg2) |cond| { + lock_cond(&x, dg2, |cond| { let num_woken = cond.broadcast(); assert_eq!(num_woken, num_waiters); - } + }); // wait until all children wake up for port in ports.iter() { let _ = port.recv(); } } @@ -1257,13 +1257,13 @@ mod tests { let x2 = x.clone(); let result: result::Result<(), ~Any> = do task::try || { - do lock_rwlock_in_mode(&x2, mode1) { + lock_rwlock_in_mode(&x2, mode1, || { fail!(); - } + }) }; assert!(result.is_err()); // child task must have finished by the time try returns - do lock_rwlock_in_mode(&x, mode2) { } + lock_rwlock_in_mode(&x, mode2, || { }) } #[test] fn test_rwlock_reader_killed_writer() { @@ -1301,12 +1301,12 @@ mod tests { // Tests that you can't downgrade with a different rwlock's token. let x = RWLock::new(); let y = RWLock::new(); - do x.write_downgrade |xwrite| { + x.write_downgrade(|xwrite| { let mut xopt = Some(xwrite); - do y.write_downgrade |_ywrite| { + y.write_downgrade(|_ywrite| { y.downgrade(xopt.take_unwrap()); error!("oops, y.downgrade(x) should have failed!"); - } - } + }) + }) } } diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 1bb07a396ffda..d6eed24ef8d44 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -102,7 +102,7 @@ fn test_task_pool() { g }; let mut pool = TaskPool::new(4, Some(SingleThreaded), f); - do 8.times { + 8.times(|| { pool.execute(|i| println!("Hello from thread {}!", *i)); - } + }) } diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 05bca853e3bb5..cf63c63c942a1 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -1027,8 +1027,8 @@ mod test_treemap { let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(&[42]); - do 3.times { - do 90.times { + 3.times(|| { + 90.times(|| { let k = rng.gen(); let v = rng.gen(); if !ctrl.iter().any(|x| x == &(k, v)) { @@ -1037,16 +1037,16 @@ mod test_treemap { check_structure(&map); check_equal(ctrl, &map); } - } + }); - do 30.times { + 30.times(|| { let r = rng.gen_range(0, ctrl.len()); let (key, _) = ctrl.remove(r); assert!(map.remove(&key)); check_structure(&map); check_equal(ctrl, &map); - } - } + }); + }) } #[test] @@ -1414,11 +1414,11 @@ mod test_set { for y in b.iter() { assert!(set_b.insert(*y)) } let mut i = 0; - do f(&set_a, &set_b) |x| { + f(&set_a, &set_b, |x| { assert_eq!(*x, expected[i]); i += 1; true - }; + }); assert_eq!(i, expected.len()); } diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs index be26d1b935134..d40eef732f112 100644 --- a/src/libextra/uuid.rs +++ b/src/libextra/uuid.rs @@ -811,24 +811,24 @@ mod bench { #[bench] pub fn create_uuids(bh: &mut BenchHarness) { - do bh.iter { + bh.iter(|| { Uuid::new_v4(); - } + }) } #[bench] pub fn uuid_to_str(bh: &mut BenchHarness) { let u = Uuid::new_v4(); - do bh.iter { + bh.iter(|| { u.to_str(); - } + }) } #[bench] pub fn parse_str(bh: &mut BenchHarness) { let s = "urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4"; - do bh.iter { + bh.iter(|| { Uuid::parse_string(s); - } + }) } } diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 7413e7847b4ce..86c0fb2768016 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -384,7 +384,7 @@ fn executable_exists(repo: &Path, short_name: &str) -> bool { fn test_executable_exists(repo: &Path, short_name: &str) -> bool { debug!("test_executable_exists: repo = {}, short_name = {}", repo.display(), short_name); let exec = built_test_in_workspace(&PkgId::new(short_name), repo); - exec.map_default(false, |exec| exec.exists() && is_rwx(&exec)); + exec.map_default(false, |exec| exec.exists() && is_rwx(&exec)) } fn remove_executable_file(p: &PkgId, workspace: &Path) { diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 205a2d20e9214..1f06f87c9de6e 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -392,11 +392,11 @@ fn local_loop() -> &'static mut Loop { unsafe { cast::transmute(Local::borrow(|sched: &mut Scheduler| { let mut io = None; - do sched.event_loop.io |i| { + sched.event_loop.io(|i| { let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) = cast::transmute(i); io = Some(uvio); - } + }); io.unwrap() }).uv_loop()) } diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 3a2a8b10c9666..2d13cdb9bbb7f 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -48,9 +48,9 @@ fn with_error_checking_parse(s: @str, f: |&mut Parser| -> T) -> T { // parse a string, return a crate. pub fn string_to_crate (source_str : @str) -> ast::Crate { - do with_error_checking_parse(source_str) |p| { + with_error_checking_parse(source_str, |p| { p.parse_crate_mod() - } + }) } // parse a string, return a crate and the ParseSess @@ -61,23 +61,23 @@ pub fn string_to_crate_and_sess (source_str : @str) -> (ast::Crate,@mut ParseSes // parse a string, return an expr pub fn string_to_expr (source_str : @str) -> @ast::Expr { - do with_error_checking_parse(source_str) |p| { + with_error_checking_parse(source_str, |p| { p.parse_expr() - } + }) } // parse a string, return an item pub fn string_to_item (source_str : @str) -> Option<@ast::item> { - do with_error_checking_parse(source_str) |p| { + with_error_checking_parse(source_str, |p| { p.parse_item(~[]) - } + }) } // parse a string, return a stmt pub fn string_to_stmt(source_str : @str) -> @ast::Stmt { - do with_error_checking_parse(source_str) |p| { + with_error_checking_parse(source_str, |p| { p.parse_stmt(~[]) - } + }) } // parse a string, return a pat. Uses "irrefutable"... which doesn't diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 3cfe615b9c019..ca7dc238e2e81 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -29,66 +29,65 @@ fn timed(label: &str, f: ||) { fn ascending>(map: &mut M, n_keys: uint) { println(" Ascending integers:"); - do timed("insert") { + timed("insert", || { for i in range(0u, n_keys) { map.insert(i, i + 1); } - } + }); - do timed("search") { + timed("search", || { for i in range(0u, n_keys) { assert_eq!(map.find(&i).unwrap(), &(i + 1)); } - } + }); - do timed("remove") { + timed("remove", || { for i in range(0, n_keys) { assert!(map.remove(&i)); } - } + }); } fn descending>(map: &mut M, n_keys: uint) { println(" Descending integers:"); - do timed("insert") { + timed("insert", || { for i in range(0, n_keys).invert() { map.insert(i, i + 1); } - } + }); - do timed("search") { + timed("search", || { for i in range(0, n_keys).invert() { assert_eq!(map.find(&i).unwrap(), &(i + 1)); } - } + }); - do timed("remove") { + timed("remove", || { for i in range(0, n_keys) { assert!(map.remove(&i)); } - } + }); } fn vector>(map: &mut M, n_keys: uint, dist: &[uint]) { - - do timed("insert") { + timed("insert", || { for i in range(0u, n_keys) { map.insert(dist[i], i + 1); } - } + }); - do timed("search") { + timed("search", || { for i in range(0u, n_keys) { assert_eq!(map.find(&dist[i]).unwrap(), &(i + 1)); } - } + }); - do timed("remove") { + timed("remove", || { for i in range(0u, n_keys) { assert!(map.remove(&dist[i])); } - } + }); } fn main() { diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index f9a3618d2abb6..ff3ab37b29cb9 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -43,7 +43,7 @@ impl Results { rand_cap: uint, f: || -> T) { { let mut set = f(); - do timed(&mut self.sequential_ints) { + timed(&mut self.sequential_ints, || { for i in range(0u, num_keys) { set.insert(i); } @@ -51,16 +51,16 @@ impl Results { for i in range(0u, num_keys) { assert!(set.contains(&i)); } - } + }) } { let mut set = f(); - do timed(&mut self.random_ints) { + timed(&mut self.random_ints, || { for _ in range(0, num_keys) { set.insert(rng.gen::() % rand_cap); } - } + }) } { @@ -69,11 +69,11 @@ impl Results { set.insert(i); } - do timed(&mut self.delete_ints) { + timed(&mut self.delete_ints, || { for i in range(0u, num_keys) { assert!(set.remove(&i)); } - } + }) } } @@ -85,7 +85,7 @@ impl Results { f: || -> T) { { let mut set = f(); - do timed(&mut self.sequential_strings) { + timed(&mut self.sequential_strings, || { for i in range(0u, num_keys) { set.insert(i.to_str()); } @@ -93,17 +93,17 @@ impl Results { for i in range(0u, num_keys) { assert!(set.contains(&i.to_str())); } - } + }) } { let mut set = f(); - do timed(&mut self.random_strings) { + timed(&mut self.random_strings, || { for _ in range(0, num_keys) { let s = rng.gen::().to_str(); set.insert(s); } - } + }) } { @@ -111,11 +111,11 @@ impl Results { for i in range(0u, num_keys) { set.insert(i.to_str()); } - do timed(&mut self.delete_strings) { + timed(&mut self.delete_strings, || { for i in range(0u, num_keys) { assert!(set.remove(&i.to_str())); } - } + }) } } } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index f3b78ecd30c67..facd8a3bd74e6 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -29,20 +29,20 @@ type pipe = arc::MutexArc<~[uint]>; fn send(p: &pipe, msg: uint) { unsafe { - do p.access_cond |state, cond| { + p.access_cond(|state, cond| { state.push(msg); cond.signal(); - } + }) } } fn recv(p: &pipe) -> uint { unsafe { - do p.access_cond |state, cond| { + p.access_cond(|state, cond| { while state.is_empty() { cond.wait(); } state.pop() - } + }) } } diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 47b1e5903280e..2ce3a373f8b33 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -28,18 +28,18 @@ use std::uint; type pipe = arc::RWArc<~[uint]>; fn send(p: &pipe, msg: uint) { - do p.write_cond |state, cond| { + p.write_cond(|state, cond| { state.push(msg); cond.signal(); - } + }) } fn recv(p: &pipe) -> uint { - do p.write_cond |state, cond| { + p.write_cond(|state, cond| { while state.is_empty() { cond.wait(); } state.pop() - } + }) } fn init() -> (pipe,pipe) { diff --git a/src/test/bench/rt-messaging-ping-pong.rs b/src/test/bench/rt-messaging-ping-pong.rs index ec796713c21d1..715043d5be686 100644 --- a/src/test/bench/rt-messaging-ping-pong.rs +++ b/src/test/bench/rt-messaging-ping-pong.rs @@ -37,26 +37,25 @@ fn ping_pong_bench(n: uint, m: uint) { do spawntask_later() || { let chan = ca.take(); let port = pb.take(); - do n.times { + n.times(|| { chan.send(()); port.recv(); - } + }) } do spawntask_later() || { let chan = cb.take(); let port = pa.take(); - do n.times { + n.times(|| { port.recv(); chan.send(()); - } + }) } } - do m.times { + m.times(|| { run_pair(n) - } - + }) } diff --git a/src/test/bench/rt-spawn-rate.rs b/src/test/bench/rt-spawn-rate.rs index 6693e2e198533..e057d6862e6a9 100644 --- a/src/test/bench/rt-spawn-rate.rs +++ b/src/test/bench/rt-spawn-rate.rs @@ -26,8 +26,8 @@ fn main() { 100000 }; - do n.times { + n.times(|| { do spawn || {}; - } + }) } diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 1be66efb20355..d2241a0ddee52 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -28,11 +28,11 @@ fn item_check(t: &Tree) -> int { fn bottom_up_tree<'r>(arena: &'r Arena, item: int, depth: int) -> &'r Tree<'r> { if depth > 0 { - do arena.alloc { + arena.alloc(|| { Node(bottom_up_tree(arena, 2 * item - 1, depth - 1), bottom_up_tree(arena, 2 * item, depth - 1), item) - } + }) } else {arena.alloc(|| Nil)} } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 853b4eaba9d68..5045e9c58d925 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -169,7 +169,7 @@ fn main() { let sizes = ~[1u,2,3,4,6,12,18]; let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>())); let mut from_child = ~[]; - let to_child = do sizes.iter().zip(streams.mut_iter()).map |(sz, stream_ref)| { + let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| { let sz = *sz; let stream = util::replace(stream_ref, None); let (from_child_, to_parent_) = stream.unwrap(); @@ -183,7 +183,7 @@ fn main() { } to_child - }.collect::<~[Chan<~[u8]>]>(); + }).collect::<~[Chan<~[u8]>]>(); // latch stores true after we've started diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 7621d5d7b087f..5685b489072f1 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -18,7 +18,7 @@ fn iterate<'a, T>(x: T, f: 'a |&T| -> T) -> Iterate<'a, T> { Iterate {f: f, next: x} } struct Iterate<'self, T> { - priv f: &'self |&T| -> T, + priv f: 'self |&T| -> T, priv next: T } impl<'self, T> Iterator for Iterate<'self, T> { diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index f3465a9bc7e45..497b6a392a539 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -51,9 +51,9 @@ impl Sudoku { } pub fn from_vec(vec: &[[u8, ..9], ..9]) -> Sudoku { - let g = do vec::from_fn(9u) |i| { - do vec::from_fn(9u) |j| { vec[i][j] } - }; + let g = vec::from_fn(9u, |i| { + vec::from_fn(9u, |j| { vec[i][j] }) + }); return Sudoku::new(g) } diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 9e04ad65eb239..cdbec1784b98e 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -19,13 +19,13 @@ use std::vec; fn calc(children: uint, parent_wait_chan: &Chan>>) { - let wait_ports: ~[Port>>] = do vec::from_fn(children) |_| { + let wait_ports: ~[Port>>] = vec::from_fn(children, |_| { let (wait_port, wait_chan) = stream::>>(); do task::spawn { calc(children / 2, &wait_chan); } wait_port - }; + }); let child_start_chans: ~[Chan>] = wait_ports.move_iter().map(|port| port.recv()).collect(); @@ -35,11 +35,11 @@ fn calc(children: uint, parent_wait_chan: &Chan>>) { let parent_result_chan: Chan = start_port.recv(); let child_sum_ports: ~[Port] = - do child_start_chans.move_iter().map |child_start_chan| { + child_start_chans.move_iter().map(|child_start_chan| { let (child_sum_port, child_sum_chan) = stream::(); child_start_chan.send(child_sum_chan); child_sum_port - }.collect(); + }).collect(); let sum = child_sum_ports.move_iter().fold(0, |sum, sum_port| sum + sum_port.recv() ); From 749ee53c6d23ae1467568d6e0280a4f59e4e952b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Nov 2013 23:36:52 -0800 Subject: [PATCH 10/12] librustc: Make `||` lambdas not infer to `proc`s --- doc/tutorial-tasks.md | 4 +-- src/compiletest/compiletest.rs | 6 ++-- src/libextra/future.rs | 6 ++-- src/libextra/task_pool.rs | 6 ++-- src/libextra/test.rs | 14 ++++----- src/librustc/lib.rs | 4 +-- src/librustc/middle/typeck/check/mod.rs | 9 ++++-- src/librustpkg/lib.rs | 4 +-- src/librustpkg/package_source.rs | 2 +- src/librustuv/net.rs | 4 +-- src/libstd/io/net/unix.rs | 12 ++++---- src/libstd/rt/local.rs | 10 +++---- src/libstd/rt/mod.rs | 6 ++-- src/libstd/rt/sched.rs | 9 ++++-- src/libstd/rt/task.rs | 6 ++-- src/libstd/rt/test.rs | 29 +++++++++++-------- src/libstd/task/mod.rs | 10 +++---- src/libstd/task/spawn.rs | 2 +- src/test/bench/shootout-pfib.rs | 2 +- src/test/bench/task-perf-spawnalot.rs | 2 +- .../borrowck-loan-blocks-move-cc.rs | 2 +- .../compile-fail/borrowck-move-by-capture.rs | 2 +- .../borrowck-move-moved-value-into-closure.rs | 4 +-- src/test/compile-fail/kindck-nonsendable-1.rs | 6 ++-- src/test/run-fail/unwind-box-fn-unique.rs | 2 +- src/test/run-pass/block-arg-call-as.rs | 2 +- .../run-pass/borrowck-move-by-capture-ok.rs | 2 +- src/test/run-pass/cap-clause-move.rs | 4 +-- src/test/run-pass/child-outlives-parent.rs | 2 +- src/test/run-pass/cleanup-copy-mode.rs | 2 +- src/test/run-pass/clone-with-exterior.rs | 2 +- src/test/run-pass/comm.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/issue-3424.rs | 2 +- src/test/run-pass/issue-3609.rs | 12 ++++---- src/test/run-pass/ivec-tag.rs | 2 +- src/test/run-pass/newlambdas-ret-infer.rs | 2 +- src/test/run-pass/newlambdas-ret-infer2.rs | 2 +- src/test/run-pass/operator-overloading.rs | 2 +- src/test/run-pass/sendfn-spawn-with-fn-arg.rs | 4 +-- src/test/run-pass/spawn-fn.rs | 6 ++-- src/test/run-pass/spawn-types.rs | 2 +- src/test/run-pass/spawn.rs | 2 +- src/test/run-pass/spawn2.rs | 2 +- src/test/run-pass/spawning-with-debug.rs | 2 +- src/test/run-pass/swap-overlapping.rs | 2 +- src/test/run-pass/task-comm-0.rs | 2 +- src/test/run-pass/task-comm-1.rs | 2 +- src/test/run-pass/task-comm-10.rs | 2 +- src/test/run-pass/task-comm-11.rs | 2 +- src/test/run-pass/task-comm-13.rs | 2 +- src/test/run-pass/task-comm-14.rs | 2 +- src/test/run-pass/task-comm-15.rs | 2 +- src/test/run-pass/task-comm-17.rs | 2 +- src/test/run-pass/task-comm-3.rs | 2 +- src/test/run-pass/task-life-0.rs | 2 +- src/test/run-pass/task-spawn-move-and-copy.rs | 2 +- src/test/run-pass/tempfile.rs | 6 ++-- src/test/run-pass/terminate-in-initializer.rs | 4 +-- src/test/run-pass/threads.rs | 2 +- src/test/run-pass/uniq-cc-generic.rs | 2 +- src/test/run-pass/uniq-cc.rs | 2 +- src/test/run-pass/unique-send-2.rs | 2 +- src/test/run-pass/unwind-resource.rs | 2 +- 64 files changed, 139 insertions(+), 126 deletions(-) diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 3017bc8b7ea01..41cd796325c32 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -76,7 +76,7 @@ fn print_message() { println("I am running in a different task!"); } spawn(print_message); // Print something more profound in a different task using a lambda expression -spawn( || println("I am also running in a different task!") ); +spawn(proc() println("I am also running in a different task!") ); // The canonical way to spawn is using `do` notation do spawn { @@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 { 12586269025 } -let mut delayed_fib = extra::future::Future::spawn (|| fib(50) ); +let mut delayed_fib = extra::future::Future::spawn(proc() fib(50)); make_a_sandwich(); println!("fib(50) = {:?}", delayed_fib.get()) ~~~ diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 65f733cf1dec3..0f39b29c60a9e 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -333,7 +333,7 @@ pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { let config = Cell::new((*config).clone()); // FIXME (#9639): This needs to handle non-utf8 paths let testfile = Cell::new(testfile.as_str().unwrap().to_owned()); - test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) + test::DynTestFn(proc() { runtest::run(config.take(), testfile.take()) }) } pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn { @@ -341,5 +341,7 @@ pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::Test let config = Cell::new((*config).clone()); // FIXME (#9639): This needs to handle non-utf8 paths let testfile = Cell::new(testfile.as_str().unwrap().to_owned()); - test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) }) + test::DynMetricFn(proc(mm) { + runtest::run_metrics(config.take(), testfile.take(), mm) + }) } diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 8d365c5a5204c..5fd720c501801 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -161,7 +161,7 @@ mod test { #[test] fn test_from_fn() { - let mut f = Future::from_fn(|| ~"brail"); + let mut f = Future::from_fn(proc() ~"brail"); assert_eq!(f.get(), ~"brail"); } @@ -185,14 +185,14 @@ mod test { #[test] fn test_spawn() { - let mut f = Future::spawn(|| ~"bale"); + let mut f = Future::spawn(proc() ~"bale"); assert_eq!(f.get(), ~"bale"); } #[test] #[should_fail] fn test_futurefail() { - let mut f = Future::spawn(|| fail!()); + let mut f = Future::spawn(proc() fail!()); let _x: ~str = f.get(); } diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index d6eed24ef8d44..bda6935643f04 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -57,7 +57,7 @@ impl TaskPool { let (port, chan) = comm::stream::>(); let init_fn = init_fn_factory(); - let task_body: proc() = || { + let task_body: proc() = proc() { let local_data = init_fn(i); loop { match port.recv() { @@ -98,11 +98,11 @@ impl TaskPool { #[test] fn test_task_pool() { let f: || -> proc(uint) -> uint = || { - let g: proc(uint) -> uint = |i| i; + let g: proc(uint) -> uint = proc(i) i; g }; let mut pool = TaskPool::new(4, Some(SingleThreaded), f); 8.times(|| { - pool.execute(|i| println!("Hello from thread {}!", *i)); + pool.execute(proc(i) println!("Hello from thread {}!", *i)); }) } diff --git a/src/libextra/test.rs b/src/libextra/test.rs index c94cb196bea6b..16e9ea8ece48c 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -912,7 +912,7 @@ pub fn run_test(force_ignore: bool, return; } DynTestFn(f) => run_test_inner(desc, monitor_ch, f), - StaticTestFn(f) => run_test_inner(desc, monitor_ch, || f()) + StaticTestFn(f) => run_test_inner(desc, monitor_ch, proc() f()) } } @@ -1209,7 +1209,7 @@ mod tests { ignore: true, should_fail: false }, - testfn: DynTestFn(|| f()), + testfn: DynTestFn(proc() f()), }; let (p, ch) = stream(); let ch = SharedChan::new(ch); @@ -1227,7 +1227,7 @@ mod tests { ignore: true, should_fail: false }, - testfn: DynTestFn(|| f()), + testfn: DynTestFn(proc() f()), }; let (p, ch) = stream(); let ch = SharedChan::new(ch); @@ -1245,7 +1245,7 @@ mod tests { ignore: false, should_fail: true }, - testfn: DynTestFn(|| f()), + testfn: DynTestFn(proc() f()), }; let (p, ch) = stream(); let ch = SharedChan::new(ch); @@ -1263,7 +1263,7 @@ mod tests { ignore: false, should_fail: true }, - testfn: DynTestFn(|| f()), + testfn: DynTestFn(proc() f()), }; let (p, ch) = stream(); let ch = SharedChan::new(ch); @@ -1318,7 +1318,7 @@ mod tests { ignore: true, should_fail: false, }, - testfn: DynTestFn(|| {}), + testfn: DynTestFn(proc() {}), }, TestDescAndFn { desc: TestDesc { @@ -1326,7 +1326,7 @@ mod tests { ignore: false, should_fail: false }, - testfn: DynTestFn(|| {}), + testfn: DynTestFn(proc() {}), }, ]; let filtered = filter_tests(&opts, tests); diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b82bc38fbd964..dc1aa1f41cbfb 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -345,7 +345,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) { task_builder.opts.stack_size = Some(STACK_SIZE); } - match task_builder.try(|| { + match task_builder.try(proc() { let ch = ch_capture.clone(); // The 'diagnostics emitter'. Every error, warning, etc. should // go through this function. @@ -403,6 +403,6 @@ pub fn main() { pub fn main_args(args: &[~str]) -> int { let owned_args = args.to_owned(); - monitor(|demitter| run_compiler(owned_args, demitter)); + monitor(proc(demitter) run_compiler(owned_args, demitter)); 0 } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index b9d6744e53b19..6bd8226258bd6 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2905,8 +2905,13 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, _match::check_match(fcx, expr, discrim, *arms); } ast::ExprFnBlock(ref decl, ref body) => { - check_expr_fn(fcx, expr, None, - decl, body, Vanilla, expected); + check_expr_fn(fcx, + expr, + Some(ast::BorrowedSigil), + decl, + body, + Vanilla, + expected); } ast::ExprProc(ref decl, ref body) => { check_expr_fn(fcx, diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index f40238364f3f5..2308f314b14a1 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -474,7 +474,7 @@ impl CtxMethods for BuildContext { let psp = package_script_path.clone(); let ws = workspace.clone(); let pid = pkgid.clone(); - prep.exec(|exec| { + prep.exec(proc(exec) { let mut pscript = PkgScript::parse(subsysroot.clone(), psp.clone(), &ws, @@ -636,7 +636,7 @@ impl CtxMethods for BuildContext { let sub_target_ex = target_exec.clone(); let sub_target_lib = target_lib.clone(); let sub_build_inputs = build_inputs.to_owned(); - prep.exec(|exe_thing| { + prep.exec(proc(exe_thing) { let mut outputs = ~[]; // Declare all the *inputs* to the declared input too, as inputs for executable in subex.iter() { diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 9d0812efe28d0..b93199e2c6179 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -412,7 +412,7 @@ impl PkgSrc { let sub_deps = deps.clone(); let inputs = inputs_to_discover.map(|&(ref k, ref p)| (k.clone(), p.as_str().unwrap().to_owned())); - prep.exec(|exec| { + prep.exec(proc(exec) { for &(ref kind, ref p) in inputs.iter() { let pth = Path::new(p.clone()); exec.discover_input(*kind, *p, if *kind == ~"file" { diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index cad1ac6709f7b..8372127c67146 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -1092,7 +1092,7 @@ mod test { let handle2 = Cell::new(sched2.make_handle()); let tasksFriendHandle = Cell::new(sched2.make_handle()); - let on_exit: proc(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = proc(exit_status) { handle1.take().send(Shutdown); handle2.take().send(Shutdown); assert!(exit_status.is_success()); @@ -1106,7 +1106,7 @@ mod test { }) } - let test_function: proc() = || { + let test_function: proc() = proc() { let io = unsafe { local_io() }; let addr = next_test_ip4(); let maybe_socket = io.udp_bind(addr); diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index 809473d64c68e..6d2deccaa4cfe 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -214,29 +214,29 @@ mod tests { #[test] fn smoke() { - smalltest(|mut server| { + smalltest(proc(mut server) { let mut buf = [0]; server.read(buf); assert!(buf[0] == 99); - }, |mut client| { + }, proc(mut client) { client.write([99]); }) } #[test] fn read_eof() { - smalltest(|mut server| { + smalltest(proc(mut server) { let mut buf = [0]; assert!(server.read(buf).is_none()); assert!(server.read(buf).is_none()); - }, |_client| { + }, proc(_client) { // drop the client }) } #[test] fn write_begone() { - smalltest(|mut server| { + smalltest(proc(mut server) { let buf = [0]; let mut stop = false; while !stop{ @@ -248,7 +248,7 @@ mod tests { server.write(buf); }) } - }, |_client| { + }, proc(_client) { // drop the client }) } diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index d5b0e384ca291..3e4072e617a4e 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -134,7 +134,7 @@ mod test { do run_in_bare_thread { local_ptr::init_tls_key(); let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); + let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){}); Local::put(task); let task: ~Task = Local::take(); cleanup_task(task); @@ -146,11 +146,11 @@ mod test { do run_in_bare_thread { local_ptr::init_tls_key(); let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); + let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){}); Local::put(task); let task: ~Task = Local::take(); cleanup_task(task); - let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); + let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){}); Local::put(task); let task: ~Task = Local::take(); cleanup_task(task); @@ -163,7 +163,7 @@ mod test { do run_in_bare_thread { local_ptr::init_tls_key(); let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); + let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){}); Local::put(task); unsafe { @@ -179,7 +179,7 @@ mod test { do run_in_bare_thread { local_ptr::init_tls_key(); let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, None, || {}); + let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){}); Local::put(task); let res = Local::borrow(|_task: &mut Task| { diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index ad5c69e9a0c2b..a8b510cbed788 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -340,14 +340,14 @@ fn run_(main: proc(), 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: proc(UnwindResult) = |exit_success| { + let handles = handles; + let on_exit: proc(UnwindResult) = proc(exit_success) { unsafe { assert!(!(*exited_already.get()).swap(true, SeqCst), "the runtime already exited"); } - let mut handles = handles.take(); + let mut handles = handles; for handle in handles.mut_iter() { handle.send(Shutdown); } diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index ccc786242e6eb..9a48fc5132999 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -979,7 +979,7 @@ mod test { assert!(Task::on_appropriate_sched()); }; - let on_exit: proc(UnwindResult) = |exit_status| { + let on_exit: proc(UnwindResult) = proc(exit_status) { rtassert!(exit_status.is_success()) }; task.death.on_exit = Some(on_exit); @@ -1193,12 +1193,15 @@ mod test { let thread = do Thread::start { let mut sched = sched.take(); - let bootstrap_task = ~Task::new_root(&mut sched.stack_pool, None, ||()); + let bootstrap_task = + ~Task::new_root(&mut sched.stack_pool, + None, + proc()()); sched.bootstrap(bootstrap_task); }; let mut stack_pool = StackPool::new(); - let task = ~Task::new_root(&mut stack_pool, None, ||()); + let task = ~Task::new_root(&mut stack_pool, None, proc()()); handle.send(TaskFromFriend(task)); handle.send(Shutdown); diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 569d96ae388d3..68164eb93459a 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -425,7 +425,7 @@ impl Coroutine { fn build_start_wrapper(start: proc()) -> proc() { let start_cell = Cell::new(start); - let wrapper: proc() = || { + let wrapper: proc() = proc() { // First code after swap to this new context. Run our // cleanup job. unsafe { @@ -712,10 +712,10 @@ mod test { #[test] fn unwind() { do run_in_newsched_task() { - let result = spawntask_try(||()); + let result = spawntask_try(proc()()); rtdebug!("trying first assert"); assert!(result.is_ok()); - let result = spawntask_try(|| fail!()); + let result = spawntask_try(proc() fail!()); rtdebug!("trying second assert"); assert!(result.is_err()); } diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index d87eb56a6500e..867d997e98d15 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -83,10 +83,11 @@ 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 exit_handle = sched.make_handle(); - let on_exit: proc(UnwindResult) = |exit_status| { - exit_handle.take().send(Shutdown); + let on_exit: proc(UnwindResult) = proc(exit_status: UnwindResult) { + let mut exit_handle = exit_handle; + exit_handle.send(Shutdown); rtassert!(exit_status.is_success()); }; let mut task = ~Task::new_root(&mut sched.stack_pool, None, f); @@ -99,10 +100,11 @@ 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 exit_handle = sched.make_handle(); - let on_exit: proc(UnwindResult) = |exit_status| { - exit_handle.take().send(Shutdown); + let on_exit: proc(UnwindResult) = proc(exit_status: UnwindResult) { + let mut exit_handle = exit_handle; + exit_handle.send(Shutdown); rtassert!(exit_status.is_success()); }; let mut task = ~Task::new_root(&mut sched.stack_pool, None, f); @@ -244,10 +246,10 @@ pub fn run_in_mt_newsched_task(f: proc()) { scheds.push(sched); } - let handles = Cell::new(handles); - let on_exit: proc(UnwindResult) = |exit_status| { - let mut handles = handles.take(); + let handles = handles; // Work around not being able to capture mut + let on_exit: proc(UnwindResult) = proc(exit_status: UnwindResult) { // Tell schedulers to exit + let mut handles = handles; for handle in handles.mut_iter() { handle.send(Shutdown); } @@ -319,8 +321,9 @@ pub fn spawntask_random(f: proc()) { pub fn spawntask_try(f: proc()) -> Result<(),()> { let (port, chan) = oneshot(); - let chan = Cell::new(chan); - let on_exit: proc(UnwindResult) = |exit_status| chan.take().send(exit_status); + let on_exit: proc(UnwindResult) = proc(exit_status) { + chan.send(exit_status) + }; let mut new_task = Task::build_root(None, f); new_task.death.on_exit = Some(on_exit); @@ -348,7 +351,9 @@ pub fn spawntask_thread(f: proc()) -> Thread { 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, ||{})); + let task = blk(~Task::new_root(&mut sched.stack_pool, + None, + proc() {})); cleanup_task(task); } } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 189f1436d42d7..a587515bb1626 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -280,13 +280,13 @@ impl TaskBuilder { let prev_gen_body = match prev_gen_body { Some(gen) => gen, None => { - let f: proc(proc()) -> proc() = |body| body; + let f: proc(proc()) -> proc() = proc(body) body; f } }; let prev_gen_body = Cell::new(prev_gen_body); let next_gen_body = { - let f: proc(proc()) -> proc() = |body| { + let f: proc(proc()) -> proc() = proc(body) { let prev_gen_body = prev_gen_body.take(); wrapper(prev_gen_body(body)) }; @@ -551,7 +551,7 @@ fn test_add_wrapper() { let ch = Cell::new(ch); do b0.add_wrapper |body| { let ch = Cell::new(ch.take()); - let result: proc() = || { + let result: proc() = proc() { let ch = ch.take(); body(); ch.send(()); @@ -765,7 +765,7 @@ fn test_child_doesnt_ref_parent() { // valgrind-friendly. try this at home, instead..!) static generations: uint = 16; fn child_no(x: uint) -> proc() { - return || { + return proc() { if x < generations { let mut t = task(); t.unwatched(); @@ -783,7 +783,7 @@ fn test_simple_newsched_spawn() { use rt::test::run_in_uv_task; do run_in_uv_task { - spawn(||()) + spawn(proc()()) } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 578839d4542ff..6c1c28c980559 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -180,7 +180,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: proc()) { if opts.notify_chan.is_some() { let notify_chan = opts.notify_chan.take_unwrap(); let notify_chan = Cell::new(notify_chan); - let on_exit: proc(UnwindResult) = |task_result| { + let on_exit: proc(UnwindResult) = proc(task_result) { notify_chan.take().send(task_result) }; task.death.on_exit = Some(on_exit); diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 84426edf3bf55..07e1b149932a0 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -46,7 +46,7 @@ fn fib(n: int) -> int { let (p, ch) = stream(); let ch = SharedChan::new(ch); - let _t = task::spawn(|| pfib(&ch, n) ); + let _t = task::spawn(proc() pfib(&ch, n) ); p.recv() } diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index 80217da60f98e..ef749960eb924 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -33,5 +33,5 @@ fn main() { }; let n = from_str::(args[1]).unwrap(); let mut i = 0u; - while i < n { task::spawn(|| f(n) ); i += 1u; } + while i < n { task::spawn(proc() f(n) ); i += 1u; } } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 7a226b8b67c0b..c935c9deeac1c 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -24,7 +24,7 @@ fn box_imm() { let v = ~3; let _w = &v; - task::spawn(|| { + task::spawn(proc() { info!("v={}", *v); //~^ ERROR cannot move }); diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index aa50f9ac3fee0..ac565e9bfd694 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -3,6 +3,6 @@ pub fn main() { // you get two error reports here. let bar = ~3; let _g = || { //~ ERROR capture of moved value - let _h: proc() -> int = || *bar; //~ ERROR capture of moved value + let _h: proc() -> int = proc() *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 b6ad3ed95a4b4..6e6a779840e76 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 @@ -5,6 +5,6 @@ fn call_f(f: proc() -> int) -> int { fn main() { let t = ~3; - call_f(|| { *t + 1 }); - call_f(|| { *t + 1 }); //~ ERROR capture of moved value + call_f(proc() { *t + 1 }); + call_f(proc() { *t + 1 }); //~ ERROR capture of moved value } diff --git a/src/test/compile-fail/kindck-nonsendable-1.rs b/src/test/compile-fail/kindck-nonsendable-1.rs index 308eb637cd0b9..02c58ba5ee367 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 _: 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` + let _: proc() = proc() foo(x); //~ ERROR does not fulfill `Send` + let _: proc() = proc() foo(x); //~ ERROR does not fulfill `Send` + let _: proc() = proc() foo(x); //~ ERROR does not fulfill `Send` } diff --git a/src/test/run-fail/unwind-box-fn-unique.rs b/src/test/run-fail/unwind-box-fn-unique.rs index b28a2a6f1f032..190d3f17543b4 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: @proc() = @(|| { + let x: @proc() = @(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 70307e1ff0465..5d5a5843a646f 100644 --- a/src/test/run-pass/block-arg-call-as.rs +++ b/src/test/run-pass/block-arg-call-as.rs @@ -19,7 +19,7 @@ fn asBlock(f: || -> uint) -> uint { } pub fn main() { - let x = asSendfn(|| 22u); + let x = asSendfn(proc() 22u); assert_eq!(x, 22u); let x = asBlock(|| 22u); assert_eq!(x, 22u); 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 2f186cc3fba30..5e8a92cd1c236 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: proc() -> int = || *bar; + let h: proc() -> int = proc() *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 c6227fdcc5eff..1fa78628d8ae2 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: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; + let snd_move: proc() -> uint = proc() 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: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; + let lam_move: proc() -> uint = proc() ptr::to_unsafe_ptr(&(*x)) as uint; assert_eq!(lam_move(), y); } diff --git a/src/test/run-pass/child-outlives-parent.rs b/src/test/run-pass/child-outlives-parent.rs index 233a43188468f..a97b81a4e8b9a 100644 --- a/src/test/run-pass/child-outlives-parent.rs +++ b/src/test/run-pass/child-outlives-parent.rs @@ -15,5 +15,5 @@ use std::task; fn child2(_s: ~str) { } pub fn main() { - let _x = task::spawn(|| child2(~"hi")); + let _x = task::spawn(proc() child2(~"hi")); } diff --git a/src/test/run-pass/cleanup-copy-mode.rs b/src/test/run-pass/cleanup-copy-mode.rs index 3b1ccf50544d1..738878527bf8e 100644 --- a/src/test/run-pass/cleanup-copy-mode.rs +++ b/src/test/run-pass/cleanup-copy-mode.rs @@ -15,7 +15,7 @@ use std::task; fn adder(x: @int, y: @int) -> int { return *x + *y; } fn failer() -> @int { fail!(); } pub fn main() { - assert!(task::try(|| { + assert!(task::try(proc() { adder(@2, failer()); () }).is_err()); } diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs index cceb0f353fb3a..6fab709543a0a 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: proc() = || { + let f: proc() = proc() { assert_eq!(z.a, 10); assert_eq!(z.b, 12); }; diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs index 18c6050095f7b..5eb3e247d672c 100644 --- a/src/test/run-pass/comm.rs +++ b/src/test/run-pass/comm.rs @@ -12,7 +12,7 @@ use std::task; pub fn main() { let (p, ch) = stream(); - let _t = task::spawn(|| child(&ch) ); + let _t = task::spawn(proc() child(&ch)); let y = p.recv(); error!("received"); error!("{:?}", y); diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 1716f882dd86e..682ab844a47f1 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -34,7 +34,7 @@ mod map_reduce { for i in inputs.iter() { let ctrl = ctrl.clone(); let i = i.clone(); - task::spawn(|| map_task(ctrl.clone(), i.clone()) ); + task::spawn(proc() map_task(ctrl.clone(), i.clone()) ); } } diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index 0b8fcdfbd8494..02aaee1d01fda 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -21,7 +21,7 @@ type rsrc_loader = proc(path: &Path) -> result::Result<~str, ~str>; fn tester() { - let loader: rsrc_loader = |_path| {result::Ok(~"more blah")}; + let loader: rsrc_loader = proc(_path) {result::Ok(~"more blah")}; let path = path::Path::new("blah"); assert!(loader(&path).is_ok()); diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index b283ba67d59bd..ab641e51960d3 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -14,13 +14,11 @@ enum Msg fn foo(name: ~str, samples_chan: Chan) { do task::spawn { - let callback: SamplesFn = - |buffer| - { - for i in range(0u, buffer.len()) { - error!("{}: {}", i, buffer[i]) - } - }; + let callback: SamplesFn = proc(buffer) { + for i in range(0u, buffer.len()) { + error!("{}: {}", i, buffer[i]) + } + }; samples_chan.send(GetSamples(name.clone(), callback)); }; } diff --git a/src/test/run-pass/ivec-tag.rs b/src/test/run-pass/ivec-tag.rs index 4b76f2f3214d4..c7d5a2f77dae1 100644 --- a/src/test/run-pass/ivec-tag.rs +++ b/src/test/run-pass/ivec-tag.rs @@ -8,7 +8,7 @@ fn producer(c: &Chan<~[u8]>) { pub fn main() { let (p, ch) = stream::<~[u8]>(); - let _prod = task::spawn(|| producer(&ch) ); + let _prod = task::spawn(proc() producer(&ch) ); let _data: ~[u8] = p.recv(); } diff --git a/src/test/run-pass/newlambdas-ret-infer.rs b/src/test/run-pass/newlambdas-ret-infer.rs index e5844785a50f9..84d49820239d2 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() -> proc() { return || (); } +fn unique() -> proc() { return proc() (); } pub fn main() { } diff --git a/src/test/run-pass/newlambdas-ret-infer2.rs b/src/test/run-pass/newlambdas-ret-infer2.rs index ccf1997498be1..86ad53c0228e8 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() -> proc() { || () } +fn unique() -> proc() { proc() () } pub fn main() { } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 5dd8ea96d3738..b27da3912d399 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: proc(int) = |_|(); + let result: proc(int) = proc(_)(); result(p[true]); } 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 91bc8345845d9..963f62a20a048 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -19,12 +19,12 @@ fn test05_start(f: proc(int)) { fn test05() { let three = ~3; - let fn_to_send: proc(int) = |n| { + let fn_to_send: proc(int) = proc(n) { error!("{}", *three + n); // will copy x into the closure assert_eq!(*three, 3); }; let fn_to_send = Cell::new(fn_to_send); - task::spawn(|| { + task::spawn(proc() { test05_start(fn_to_send.take()); }); } diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs index c56991e541f2a..8c9de64687e27 100644 --- a/src/test/run-pass/spawn-fn.rs +++ b/src/test/run-pass/spawn-fn.rs @@ -16,9 +16,9 @@ fn x(s: ~str, n: int) { } pub fn main() { - task::spawn(|| x(~"hello from first spawned fn", 65) ); - task::spawn(|| x(~"hello from second spawned fn", 66) ); - task::spawn(|| x(~"hello from third spawned fn", 67) ); + task::spawn(proc() x(~"hello from first spawned fn", 65) ); + task::spawn(proc() x(~"hello from second spawned fn", 66) ); + task::spawn(proc() x(~"hello from third spawned fn", 67) ); let mut i: int = 30; while i > 0 { i = i - 1; info!("parent sleeping"); task::deschedule(); } } diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs index 111e0df1d6d5c..18459b7a3a312 100644 --- a/src/test/run-pass/spawn-types.rs +++ b/src/test/run-pass/spawn-types.rs @@ -24,5 +24,5 @@ fn iotask(_cx: &ctx, ip: ~str) { pub fn main() { let (_p, ch) = stream::(); - task::spawn(|| iotask(&ch, ~"localhost") ); + task::spawn(proc() iotask(&ch, ~"localhost") ); } diff --git a/src/test/run-pass/spawn.rs b/src/test/run-pass/spawn.rs index 7e486a1129d5a..d95f032e81438 100644 --- a/src/test/run-pass/spawn.rs +++ b/src/test/run-pass/spawn.rs @@ -13,7 +13,7 @@ extern mod extra; use std::task; pub fn main() { - task::spawn(|| child(10) ); + task::spawn(proc() child(10) ); } fn child(i: int) { error!("{}", i); assert!((i == 10)); } diff --git a/src/test/run-pass/spawn2.rs b/src/test/run-pass/spawn2.rs index 81c7483ffef68..8530c583b1654 100644 --- a/src/test/run-pass/spawn2.rs +++ b/src/test/run-pass/spawn2.rs @@ -10,7 +10,7 @@ use std::task; -pub fn main() { task::spawn(|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); } +pub fn main() { task::spawn(proc() child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); } fn child(args: (int, int, int, int, int, int, int, int, int)) { let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args; diff --git a/src/test/run-pass/spawning-with-debug.rs b/src/test/run-pass/spawning-with-debug.rs index f35c5ef022e41..76975d15c1d0c 100644 --- a/src/test/run-pass/spawning-with-debug.rs +++ b/src/test/run-pass/spawning-with-debug.rs @@ -18,5 +18,5 @@ use std::task; fn main() { let mut t = task::task(); t.sched_mode(task::SingleThreaded); - t.spawn(|| ()); + t.spawn(proc() ()); } diff --git a/src/test/run-pass/swap-overlapping.rs b/src/test/run-pass/swap-overlapping.rs index 986a9a8c49c31..42f3089a87a19 100644 --- a/src/test/run-pass/swap-overlapping.rs +++ b/src/test/run-pass/swap-overlapping.rs @@ -18,7 +18,7 @@ pub fn main() { name: DynTestName(~"test"), should_fail: false }, - testfn: DynTestFn(|| ()), + testfn: DynTestFn(proc() ()), }; do_swap(&mut test); } diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index 804b03559fa2f..bcdb56a45fdb3 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -29,7 +29,7 @@ fn test05_start(ch : &Chan) { fn test05() { let (po, ch) = comm::stream(); - task::spawn(|| test05_start(&ch) ); + task::spawn(proc() test05_start(&ch) ); let mut value: int = po.recv(); error!("{}", value); value = po.recv(); diff --git a/src/test/run-pass/task-comm-1.rs b/src/test/run-pass/task-comm-1.rs index d202bac7089b1..830aecfa86cc9 100644 --- a/src/test/run-pass/task-comm-1.rs +++ b/src/test/run-pass/task-comm-1.rs @@ -15,6 +15,6 @@ pub fn main() { test00(); } fn start() { info!("Started / Finished task."); } fn test00() { - task::try(|| start() ); + task::try(proc() start() ); info!("Completing."); } diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 9195208fb96ca..7694891328877 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -31,7 +31,7 @@ fn start(c: &comm::Chan>) { pub fn main() { let (p, ch) = comm::stream(); - let _child = task::spawn(|| start(&ch) ); + let _child = task::spawn(proc() start(&ch) ); let c = p.recv(); c.send(~"A"); diff --git a/src/test/run-pass/task-comm-11.rs b/src/test/run-pass/task-comm-11.rs index 5d1a68e6cc74b..e87809b2e98f1 100644 --- a/src/test/run-pass/task-comm-11.rs +++ b/src/test/run-pass/task-comm-11.rs @@ -22,6 +22,6 @@ fn start(c: &comm::Chan>) { pub fn main() { let (p, ch) = comm::stream(); - let _child = task::spawn(|| start(&ch) ); + let _child = task::spawn(proc() start(&ch) ); let _c = p.recv(); } diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index b039f01bf0cd9..c8234aefbe577 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -23,6 +23,6 @@ fn start(c: &comm::Chan, start: int, number_of_messages: int) { pub fn main() { info!("Check that we don't deadlock."); let (_p, ch) = comm::stream(); - task::try(|| start(&ch, 0, 10) ); + task::try(proc() start(&ch, 0, 10) ); info!("Joined task"); } diff --git a/src/test/run-pass/task-comm-14.rs b/src/test/run-pass/task-comm-14.rs index da9b3703a99f5..8ef7f85e76827 100644 --- a/src/test/run-pass/task-comm-14.rs +++ b/src/test/run-pass/task-comm-14.rs @@ -22,7 +22,7 @@ pub fn main() { while (i > 0) { info!("{}", i); let ch = ch.clone(); - task::spawn({let i = i; || child(i, &ch)}); + task::spawn({let i = i; proc() child(i, &ch)}); i = i - 1; } diff --git a/src/test/run-pass/task-comm-15.rs b/src/test/run-pass/task-comm-15.rs index 394b7e4865429..66b7b4db5bea7 100644 --- a/src/test/run-pass/task-comm-15.rs +++ b/src/test/run-pass/task-comm-15.rs @@ -29,6 +29,6 @@ pub fn main() { // the child's point of view the receiver may die. We should // drop messages on the floor in this case, and not crash! let (p, ch) = comm::stream(); - task::spawn(|| start(&ch, 10)); + task::spawn(proc() start(&ch, 10)); p.recv(); } diff --git a/src/test/run-pass/task-comm-17.rs b/src/test/run-pass/task-comm-17.rs index 47e0a710a125c..4f9285d30b9e0 100644 --- a/src/test/run-pass/task-comm-17.rs +++ b/src/test/run-pass/task-comm-17.rs @@ -20,5 +20,5 @@ fn f() { } pub fn main() { - task::spawn(|| f() ); + task::spawn(proc() f() ); } diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index eb48fa1812d74..030b70924f69c 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -48,7 +48,7 @@ fn test00() { results.push(builder.future_result()); builder.spawn({ let i = i; - || test00_start(&ch, i, number_of_messages) + proc() test00_start(&ch, i, number_of_messages) }); i = i + 1; } diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs index b58fe2aad5805..b60e3f2a4eeba 100644 --- a/src/test/run-pass/task-life-0.rs +++ b/src/test/run-pass/task-life-0.rs @@ -13,7 +13,7 @@ extern mod extra; use std::task; pub fn main() { - task::spawn(|| child(~"Hello") ); + task::spawn(proc() child(~"Hello") ); } fn child(_s: ~str) { diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index 92697054be33b..aeca54c1fb566 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -17,7 +17,7 @@ pub fn main() { let x = ~1; let x_in_parent = ptr::to_unsafe_ptr(&(*x)) as uint; - task::spawn(|| { + task::spawn(proc() { let x_in_child = ptr::to_unsafe_ptr(&(*x)) as uint; ch.send(x_in_child); }); diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index cee2079251a28..3ab0fe1c058d8 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: proc() = || { + let f: proc() = 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: proc() = || { + let f: proc() = proc() { let _tmp = cell.take(); fail!("fail to unwind past `tmp`"); }; @@ -61,7 +61,7 @@ fn test_rm_tempdir() { let path; { - let f: proc() -> TempDir = || { + let f: proc() -> TempDir = proc() { TempDir::new("test_rm_tempdir").unwrap() }; let tmp = task::try(f).expect("test_rm_tmdir"); diff --git a/src/test/run-pass/terminate-in-initializer.rs b/src/test/run-pass/terminate-in-initializer.rs index b630884de86b8..aaedb2d322be1 100644 --- a/src/test/run-pass/terminate-in-initializer.rs +++ b/src/test/run-pass/terminate-in-initializer.rs @@ -25,13 +25,13 @@ fn test_ret() { let _x: @int = return; } fn test_fail() { fn f() { let _x: @int = fail!(); } - task::try(|| f() ); + task::try(proc() f() ); } fn test_fail_indirect() { fn f() -> ! { fail!(); } fn g() { let _x: @int = f(); } - task::try(|| g() ); + task::try(proc() g() ); } pub fn main() { diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs index baa2b363a2393..7df9dac219a1f 100644 --- a/src/test/run-pass/threads.rs +++ b/src/test/run-pass/threads.rs @@ -14,7 +14,7 @@ use std::task; pub fn main() { let mut i = 10; - while i > 0 { task::spawn({let i = i; || child(i)}); i = i - 1; } + while i > 0 { task::spawn({let i = i; proc() child(i)}); i = i - 1; } info!("main thread exiting"); } diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index ada3607beaef5..ebf3da60db8f3 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -23,7 +23,7 @@ struct Pointy { } fn make_uniq_closure(a: A) -> proc() -> uint { - let result: proc() -> uint = || ptr::to_unsafe_ptr(&a) as uint; + let result: proc() -> uint = proc() 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 fc58374d46d61..20b5761e6bdb6 100644 --- a/src/test/run-pass/uniq-cc.rs +++ b/src/test/run-pass/uniq-cc.rs @@ -25,7 +25,7 @@ fn empty_pointy() -> @mut Pointy { return @mut Pointy { a : none, c : ~22, - d : || {}, + d : proc() {}, } } diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index e697af80dcc91..f44802a9b34cf 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -22,7 +22,7 @@ pub fn main() { let mut expected = 0u; for i in range(0u, n) { let ch = ch.clone(); - task::spawn(|| child(&ch, i) ); + task::spawn(proc() child(&ch, i) ); expected += i; } diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs index e2460ba6b0488..2e01eef1c6961 100644 --- a/src/test/run-pass/unwind-resource.rs +++ b/src/test/run-pass/unwind-resource.rs @@ -42,7 +42,7 @@ fn f(c: SharedChan) { pub fn main() { let (p, c) = stream(); let c = SharedChan::new(c); - task::spawn(|| f(c.clone()) ); + task::spawn(proc() f(c.clone())); error!("hiiiiiiiii"); assert!(p.recv()); } From 151b7ed52d76a11a39888931056f1bcc9c45807a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Nov 2013 14:15:32 -0800 Subject: [PATCH 11/12] libstd: Fix Win32 and other bustage. --- src/libstd/condition.rs | 10 +++++----- src/libstd/gc.rs | 8 ++++---- src/libstd/io/native/file.rs | 4 +++- src/libstd/io/native/process.rs | 2 +- src/libstd/num/mod.rs | 2 +- src/libstd/num/uint.rs | 4 ++-- src/libstd/ops.rs | 4 ++-- src/libstd/rand/os.rs | 4 ++-- src/libstd/rt/args.rs | 10 +++++----- src/libstd/vec.rs | 32 ++++++++++++++++---------------- 10 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 80ff104e8303e..e34e94ac10cc5 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -30,14 +30,14 @@ This macro declares an inner module called `my_error` with one static variable, parameters are used for, an example usage of this condition would be: ```rust -do my_error::cond.trap(|raised_int| { +my_error::cond.trap(|raised_int| { // the condition `my_error` was raised on, and the value it raised is stored // in `raised_int`. This closure must return a `~str` type (as specified in // the declaration of the condition if raised_int == 3 { ~"three" } else { ~"oh well" } -}).inside { +}).inside(|| { // The condition handler above is installed for the duration of this block. // That handler will override any previous handler, but the previous handler @@ -50,7 +50,7 @@ do my_error::cond.trap(|raised_int| { println(my_error::cond.raise(3)); // prints "three" println(my_error::cond.raise(4)); // prints "oh well" -} +}) ``` Condition handling is useful in cases where propagating errors is either to @@ -176,9 +176,9 @@ impl<'self, T, U> Trap<'self, T, U> { /// ```rust /// condition! { my_error: int -> int; } /// - /// let result = do my_error::cond.trap(|error| error + 3).inside { + /// let result = my_error::cond.trap(|error| error + 3).inside(|| { /// my_error::cond.raise(4) - /// }; + /// }); /// assert_eq!(result, 7); /// ``` pub fn inside(&self, inner: 'self || -> V) -> V { diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 5fe11d310d467..d3bec8ca6c907 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -61,9 +61,9 @@ mod tests { fn test_clone() { let x = Gc::new(RefCell::new(5)); let y = x.clone(); - do x.borrow().with_mut |inner| { + x.borrow().with_mut(|inner| { *inner = 20; - } + }); assert_eq!(y.borrow().with(|x| *x), 20); } @@ -71,9 +71,9 @@ mod tests { fn test_deep_clone() { let x = Gc::new(RefCell::new(5)); let y = x.deep_clone(); - do x.borrow().with_mut |inner| { + x.borrow().with_mut(|inner| { *inner = 20; - } + }); assert_eq!(y.borrow().with(|x| *x), 5); } diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index c21326262e4c6..9dd6daf66e948 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -576,7 +576,9 @@ pub fn unlink(p: &CString) -> IoResult<()> { #[cfg(windows)] fn os_unlink(p: &CString) -> IoResult<()> { super::mkerr_winbool(unsafe { - as_utf16_p(p.as_str().unwrap(), |buf| libc::DeleteFileW(buf)); + as_utf16_p(p.as_str().unwrap(), |buf| { + libc::DeleteFileW(buf) + }) }) } diff --git a/src/libstd/io/native/process.rs b/src/libstd/io/native/process.rs index ef531c8803c76..038b6ec0ff201 100644 --- a/src/libstd/io/native/process.rs +++ b/src/libstd/io/native/process.rs @@ -499,7 +499,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T { blk.push(0); - blk.as_imm_buf(|p, _len| unsafe { cb(cast::transmute(p)) }); + blk.as_imm_buf(|p, _len| unsafe { cb(cast::transmute(p)) }) } _ => cb(ptr::mut_null()) } diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index aeda3fa1cd193..456011d51720e 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -104,7 +104,7 @@ pub trait Unsigned: Num {} /// use num::Times; /// let ten = 10 as uint; /// let mut accum = 0; -/// do ten.times { accum += 1; } +/// ten.times(|| { accum += 1; }) /// ``` /// pub trait Times { diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index cf7047bd068a0..cf28083bb09b9 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -77,13 +77,13 @@ impl num::Times for uint { #[inline] /// /// A convenience form for basic repetition. Given a uint `x`, - /// `do x.times { ... }` executes the given block x times. + /// `x.times(|| { ... })` executes the given block x times. /// /// Equivalent to `for uint::range(0, x) |_| { ... }`. /// /// Not defined on all integer types to permit unambiguous /// use with integer literals of inferred integer-type as - /// the self-value (eg. `do 100.times { ... }`). + /// the self-value (eg. `100.times(|| { ... })`). /// fn times(&self, it: ||) { let mut i = *self; diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index 62685b5dcd393..cdc63608122a8 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -481,8 +481,8 @@ mod bench { #[bench] fn alloc_obj_with_dtor(bh: &mut BenchHarness) { - do bh.iter { + bh.iter(|| { HasDtor { x : 10 }; - } + }) } } diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index cd90af113ec61..5558b8b33487b 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -111,9 +111,9 @@ impl Rng for OSRng { pbBuffer: *mut BYTE); } - do v.as_mut_buf |ptr, len| { + v.as_mut_buf(|ptr, len| { unsafe {rust_win32_rand_gen(self.hcryptprov, len as DWORD, ptr)} - } + }) } } diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index a173be6435670..82b98fa7f9a09 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -109,16 +109,16 @@ mod imp { fn with_lock(f: || -> T) -> T { static mut lock: Mutex = MUTEX_INIT; - do (|| { + (|| { unsafe { lock.lock(); f() } - }).finally { + }).finally(|| { unsafe { lock.unlock(); } - } + }) } fn get_global_ptr() -> *mut Option<~~[~str]> { @@ -127,9 +127,9 @@ mod imp { // Copied from `os`. unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] { - do vec::from_fn(argc as uint) |i| { + vec::from_fn(argc as uint, |i| { str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int)) - } + }) } #[cfg(test)] diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 9dc4f6ae3771c..22cf57979a1a2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -3894,25 +3894,25 @@ mod bench { #[bench] fn push(bh: &mut BenchHarness) { let mut vec: ~[uint] = ~[0u]; - do bh.iter() { + bh.iter(|| { vec.push(0); - } + }) } #[bench] fn starts_with_same_vector(bh: &mut BenchHarness) { let vec: ~[uint] = vec::from_fn(100, |i| i); - do bh.iter() { + bh.iter(|| { vec.starts_with(vec); - } + }) } #[bench] fn starts_with_single_element(bh: &mut BenchHarness) { let vec: ~[uint] = ~[0u]; - do bh.iter() { + bh.iter(|| { vec.starts_with(vec); - } + }) } #[bench] @@ -3920,25 +3920,25 @@ mod bench { let vec: ~[uint] = vec::from_fn(100, |i| i); let mut match_vec: ~[uint] = vec::from_fn(99, |i| i); match_vec.push(0); - do bh.iter() { + bh.iter(|| { vec.starts_with(match_vec); - } + }) } #[bench] fn ends_with_same_vector(bh: &mut BenchHarness) { let vec: ~[uint] = vec::from_fn(100, |i| i); - do bh.iter() { + bh.iter(|| { vec.ends_with(vec); - } + }) } #[bench] fn ends_with_single_element(bh: &mut BenchHarness) { let vec: ~[uint] = ~[0u]; - do bh.iter() { + bh.iter(|| { vec.ends_with(vec); - } + }) } #[bench] @@ -3946,16 +3946,16 @@ mod bench { let vec: ~[uint] = vec::from_fn(100, |i| i); let mut match_vec: ~[uint] = vec::from_fn(100, |i| i); match_vec[0] = 200; - do bh.iter() { + bh.iter(|| { vec.starts_with(match_vec); - } + }) } #[bench] fn contains_last_element(bh: &mut BenchHarness) { let vec: ~[uint] = vec::from_fn(100, |i| i); - do bh.iter() { + bh.iter(|| { vec.contains(&99u); - } + }) } } From 9521551b4710805674ad6c1755bef4e76784db02 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 24 Nov 2013 11:44:28 -0800 Subject: [PATCH 12/12] librustc: Fix merge fallout. --- src/libextra/json.rs | 4 ++-- src/libextra/sync.rs | 8 ++----- src/libextra/time.rs | 4 ++-- src/librustc/middle/lint.rs | 8 +++---- src/librustc/middle/privacy.rs | 4 ++-- .../testsuite/pass/src/c-dependencies/pkg.rs | 4 ++-- src/librustuv/net.rs | 4 ++-- src/libstd/rc.rs | 22 ------------------- src/libstd/rt/args.rs | 6 ++--- src/libstd/rt/comm.rs | 4 ++-- src/libstd/select.rs | 2 +- src/libstd/unstable/sync.rs | 4 ++-- src/libstd/vec.rs | 4 ++-- src/test/bench/core-set.rs | 2 ++ src/test/bench/shootout-pfib.rs | 4 ++-- src/test/bench/task-perf-spawnalot.rs | 2 +- .../lexical-scope-in-unique-closure.rs | 2 +- .../var-captured-in-sendable-closure.rs | 2 +- src/test/pretty/disamb-stmt-expr.rs | 2 +- src/test/pretty/do1.rs | 2 +- .../borrowck-preserve-box-in-field.rs | 2 ++ .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 ++ src/test/run-pass/borrowck-preserve-box.rs | 2 ++ .../run-pass/borrowck-preserve-expl-deref.rs | 2 ++ 24 files changed, 43 insertions(+), 59 deletions(-) diff --git a/src/libextra/json.rs b/src/libextra/json.rs index c30963568286f..8dcf0a919d37f 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -1983,7 +1983,7 @@ mod tests { } fn check_err>(to_parse: &'static str, expected_error: &str) { use std::task; - let res = task::try(|| { + let res = do task::try { // either fails in `decode` (which is what we want), or // returns Some(error_message)/None if the string was // invalid or valid JSON. @@ -1994,7 +1994,7 @@ mod tests { None } } - }); + }; match res { Ok(Some(parse_error)) => fail!("`{}` is not valid json: {}", to_parse, parse_error), diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 0d5368695b79c..6167a4293806f 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -230,12 +230,8 @@ impl<'self> Condvar<'self> { }).finally(|| { // Reacquire the condvar. match self.order { - Just(lock) => do lock.access { - self.sem.acquire(); - }, - Nothing => { - self.sem.acquire(); - }, + Just(lock) => lock.access(|| self.sem.acquire()), + Nothing => self.sem.acquire(), } }) }) diff --git a/src/libextra/time.rs b/src/libextra/time.rs index fb80ce026257d..1352bfd424f68 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -969,9 +969,9 @@ mod tests { // Windows does not understand "America/Los_Angeles". // PST+08 may look wrong, but not! "PST" indicates // the name of timezone. "+08" means UTC = local + 08. - do "TZ=PST+08".with_c_str |env| { + "TZ=PST+08".with_c_str(|env| { _putenv(env); - } + }) } tzset(); } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 29e28204bd98f..38b7bc0875bfc 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -1204,17 +1204,17 @@ impl<'self> Visitor<()> for Context<'self> { } fn visit_foreign_item(&mut self, it: @ast::foreign_item, _: ()) { - do self.with_lint_attrs(it.attrs) |cx| { + self.with_lint_attrs(it.attrs, |cx| { check_attrs_usage(cx, it.attrs); visit::walk_foreign_item(cx, it, ()); - } + }) } fn visit_view_item(&mut self, i: &ast::view_item, _: ()) { - do self.with_lint_attrs(i.attrs) |cx| { + self.with_lint_attrs(i.attrs, |cx| { check_attrs_usage(cx, i.attrs); visit::walk_view_item(cx, i, ()); - } + }) } fn visit_pat(&mut self, p: &ast::Pat, _: ()) { diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 90bbbaeaf6f74..c2a21905be6d5 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -232,10 +232,10 @@ impl<'self> Visitor<()> for EmbargoVisitor<'self> { _ => true, }; let tr = ty::impl_trait_ref(self.tcx, local_def(item.id)); - let public_trait = do tr.map_default(false) |tr| { + let public_trait = tr.map_default(false, |tr| { !is_local(tr.def_id) || self.exported_items.contains(&tr.def_id.node) - }; + }); if public_ty || public_trait { for method in methods.iter() { diff --git a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs index 180f8cc74cee6..122f80a52f1ca 100644 --- a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs +++ b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs @@ -50,7 +50,7 @@ pub fn main() { prep.declare_input("file", foo_c_name.as_str().unwrap().to_owned(), digest_file_with_date(&foo_c_name)); - let out_path = prep.exec(|exec| { + let out_path = do prep.exec |exec| { let out_path = api::build_library_in_workspace(exec, &mut sub_cx.clone(), "cdep", @@ -60,7 +60,7 @@ pub fn main() { "foo"); let out_p = Path::new(out_path); out_p.as_str().unwrap().to_owned() - }); + }; out_path }); let out_lib_path = Path::new(out_lib_path); diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 8372127c67146..7fb665b858fd7 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -186,9 +186,9 @@ impl TcpWatcher { 0 => { req.defuse(); // uv callback now owns this request let mut cx = Ctx { status: 0, task: None }; - do wait_until_woken_after(&mut cx.task) { + wait_until_woken_after(&mut cx.task, || { req.set_data(&cx); - } + }); match cx.status { 0 => Ok(()), n => Err(UvError(n)), diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 9506a772ee811..f2beea992c67a 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -168,28 +168,6 @@ impl Drop for Rc { } } -impl Clone for RcMut { - /// Return a shallow copy of the reference counted pointer. - #[inline] - fn clone(&self) -> RcMut { - unsafe { - (*self.ptr).count += 1; - RcMut{ptr: self.ptr} - } - } -} - -impl DeepClone for RcMut { - /// Return a deep copy of the reference counted pointer. - #[inline] - fn deep_clone(&self) -> RcMut { - self.with_borrow(|x| { - // FIXME: #6497: should avoid freeze (slow) - unsafe { RcMut::new_unchecked(x.deep_clone()) } - }) - } -} - #[cfg(test)] mod test_rc { use super::*; diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 82b98fa7f9a09..43e8096a8b113 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -150,14 +150,14 @@ mod imp { assert!(take() == Some(expected.clone())); assert!(take() == None); - do (|| { - }).finally { + (|| { + }).finally(|| { // Restore the actual global state. match saved_value { Some(ref args) => put(args.clone()), None => () } - } + }) } } } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 52a6d67cb05fb..06743bce9bf49 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -990,11 +990,11 @@ mod test { #[test] fn recv_a_lot() { // Regression test that we don't run out of stack in scheduler context - run_in_newsched_task(|| { + do run_in_newsched_task { let (port, chan) = stream(); 10000.times(|| { chan.send(()) }); 10000.times(|| { port.recv() }); - }) + } } #[test] diff --git a/src/libstd/select.rs b/src/libstd/select.rs index 9b83c493065d2..43f1c3c529671 100644 --- a/src/libstd/select.rs +++ b/src/libstd/select.rs @@ -76,7 +76,7 @@ pub fn select(ports: &mut [A]) -> uint { let c = Cell::new(c.take()); do sched.event_loop.callback { c.take().send_deferred(()) } - } + }) }).finally(|| { // Unkillable is necessary not because getting killed is dangerous here, // but to force the recv not to use the same kill-flag that we used for diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index 1f243d08243db..03745c2c3485b 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -135,7 +135,7 @@ impl UnsafeArc { /// block; otherwise, an unwrapping task can be killed by linked failure. pub fn unwrap(self) -> T { unsafe { - let mut this = this; + let mut this = self; // The ~ dtor needs to run if this code succeeds. let mut data: ~ArcData = cast::transmute(this.data); // Set up the unwrap protocol. @@ -192,7 +192,7 @@ impl UnsafeArc { cast::forget(data); fail!("Another task is already unwrapping this Arc!"); } - }) + } } /// As unwrap above, but without blocking. Returns 'UnsafeArcSelf(self)' if this is diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 22cf57979a1a2..1d562d648499c 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -863,11 +863,11 @@ pub trait ImmutableVector<'self, T> { /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`, limited to splitting /// at most `n` times. - fn splitn(self, n: uint, pred: |&T| -> bool) -> SplitIterator<'self, T>; + fn splitn(self, n: uint, pred: 'self |&T| -> bool) -> SplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. This starts at the /// end of the vector and works backwards. - fn rsplit(self, pred: |&T| -> bool) -> RSplitIterator<'self, T>; + fn rsplit(self, pred: 'self |&T| -> bool) -> RSplitIterator<'self, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred` limited to splitting /// at most `n` times. This starts at the end of the vector and diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index ff3ab37b29cb9..57205ca2c583d 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -1,3 +1,5 @@ +// xfail-pretty + // 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. diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 07e1b149932a0..da25f1e82eebb 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -37,9 +37,9 @@ fn fib(n: int) -> int { let (pp, cc) = stream(); let cc = SharedChan::new(cc); let ch = cc.clone(); - task::spawn(|| pfib(&ch, n - 1) ); + task::spawn(proc() pfib(&ch, n - 1)); let ch = cc.clone(); - task::spawn(|| pfib(&ch, n - 2) ); + task::spawn(proc() pfib(&ch, n - 2)); c.send(pp.recv() + pp.recv()); } } diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index ef749960eb924..e322aceb5e661 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -15,7 +15,7 @@ use std::uint; fn f(n: uint) { let mut i = 0u; while i < n { - task::try(|| g() ); + task::try(proc() g()); i += 1u; } } 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 da9220322dd74..2c732f9f8501f 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: proc(int) = |x| { + let unique_closure: proc(int) = proc(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 664e377c9fbe9..82618aa1f137c 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: proc() = || { + let closure: proc() = proc() { zzz(); do_something(&constant, &a_struct.a, owned); }; diff --git a/src/test/pretty/disamb-stmt-expr.rs b/src/test/pretty/disamb-stmt-expr.rs index d3d6f1c0e355b..78658a4c12169 100644 --- a/src/test/pretty/disamb-stmt-expr.rs +++ b/src/test/pretty/disamb-stmt-expr.rs @@ -16,5 +16,5 @@ fn id(f: || -> int) -> int { f() } -fn wsucc(_n: int) -> int { (do id || { 1 }) - 0 } +fn wsucc(_n: int) -> int { id(|| { 1 }) - 0 } fn main() { } diff --git a/src/test/pretty/do1.rs b/src/test/pretty/do1.rs index 1fb2359da53ac..cd7a5b29a8af1 100644 --- a/src/test/pretty/do1.rs +++ b/src/test/pretty/do1.rs @@ -12,4 +12,4 @@ fn f(f: |int|) { f(10) } -fn main() { do f |i| { assert!(i == 10) } } +fn main() { f(|i| { assert!(i == 10) }) } diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs index 506d777013cd2..1caf5c033763f 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -1,3 +1,5 @@ +// xfail-pretty + // 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. diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index d7f7a8e47a230..2b8180be00e2e 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -1,3 +1,5 @@ +// xfail-pretty + // 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. diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs index feea06cd69a18..2acaf54f05f43 100644 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -1,3 +1,5 @@ +// xfail-pretty + // 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. diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs index d131a529f1a36..4400b03e31324 100644 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -1,3 +1,5 @@ +// xfail-pretty + // 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.