Skip to content

Commit 17bf45d

Browse files
committed
test: Remove all remaining non-procedure uses of do.
1 parent e7b2574 commit 17bf45d

35 files changed

+390
-397
lines changed

doc/rust.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,33 +2703,27 @@ A `loop` expression is only permitted in the body of a loop.
27032703
do_expr : "do" expr [ '|' ident_list '|' ] ? '{' block '}' ;
27042704
~~~~
27052705

2706-
A _do expression_ provides a more-familiar block-syntax for a [lambda expression](#lambda-expressions),
2707-
including a special translation of [return expressions](#return-expressions) inside the supplied block.
2708-
2709-
Any occurrence of a [return expression](#return-expressions)
2710-
inside this `block` expression is rewritten
2711-
as a reference to an (anonymous) flag set in the caller's environment,
2712-
which is checked on return from the `expr` and, if set,
2713-
causes a corresponding return from the caller.
2714-
In this way, the meaning of `return` statements in language built-in control blocks is preserved,
2715-
if they are rewritten using lambda functions and `do` expressions as abstractions.
2716-
2717-
The optional `ident_list` and `block` provided in a `do` expression are parsed as though they constitute a lambda expression;
2706+
A _do expression_ provides a more-familiar block syntax
2707+
for invoking a function and passing it a newly-created a procedure.
2708+
2709+
The optional `ident_list` and `block` provided in a `do` expression are parsed
2710+
as though they constitute a procedure expression;
27182711
if the `ident_list` is missing, an empty `ident_list` is implied.
27192712

2720-
The lambda expression is then provided as a _trailing argument_
2721-
to the outermost [call](#call-expressions) or [method call](#method-call-expressions) expression
2713+
The procedure expression is then provided as a _trailing argument_
2714+
to the outermost [call](#call-expressions) or
2715+
[method call](#method-call-expressions) expression
27222716
in the `expr` following `do`.
27232717
If the `expr` is a [path expression](#path-expressions), it is parsed as though it is a call expression.
27242718
If the `expr` is a [field expression](#field-expressions), it is parsed as though it is a method call expression.
27252719

27262720
In this example, both calls to `f` are equivalent:
27272721

27282722
~~~~
2729-
# fn f(f: |int|) { }
2723+
# fn f(f: proc(int)) { }
27302724
# fn g(i: int) { }
27312725
2732-
f(|j| g(j));
2726+
f(proc(j) { g(j) });
27332727
27342728
do f |j| {
27352729
g(j);
@@ -2739,10 +2733,10 @@ do f |j| {
27392733
In this example, both calls to the (binary) function `k` are equivalent:
27402734

27412735
~~~~
2742-
# fn k(x:int, f: |int|) { }
2736+
# fn k(x:int, f: proc(int)) { }
27432737
# fn l(i: int) { }
27442738
2745-
k(3, |j| l(j));
2739+
k(3, proc(j) { l(j) });
27462740
27472741
do k(3) |j| {
27482742
l(j);

doc/tutorial-conditions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,15 @@ condition! {
457457
458458
fn main() {
459459
// Trap the condition:
460-
do malformed_line::cond.trap(|_| (-1,-1)).inside {
460+
malformed_line::cond.trap(|_| (-1,-1)).inside(|| {
461461
462462
// The protected logic.
463463
let pairs = read_int_pairs();
464464
for &(a,b) in pairs.iter() {
465465
println!("{:4.4d}, {:4.4d}", a, b);
466466
}
467467
468-
}
468+
})
469469
}
470470
471471
fn read_int_pairs() -> ~[(int,int)] {
@@ -535,15 +535,15 @@ condition! {
535535
536536
fn main() {
537537
// Trap the condition and return `None`
538-
do malformed_line::cond.trap(|_| None).inside {
538+
malformed_line::cond.trap(|_| None).inside(|| {
539539
540540
// The protected logic.
541541
let pairs = read_int_pairs();
542542
for &(a,b) in pairs.iter() {
543543
println!("{:4.4d}, {:4.4d}", a, b);
544544
}
545545
546-
}
546+
})
547547
}
548548
549549
fn read_int_pairs() -> ~[(int,int)] {
@@ -631,15 +631,15 @@ condition! {
631631
632632
fn main() {
633633
// Trap the condition and return `UsePreviousLine`
634-
do malformed_line::cond.trap(|_| UsePreviousLine).inside {
634+
malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {
635635
636636
// The protected logic.
637637
let pairs = read_int_pairs();
638638
for &(a,b) in pairs.iter() {
639639
println!("{:4.4d}, {:4.4d}", a, b);
640640
}
641641
642-
}
642+
})
643643
}
644644
645645
fn read_int_pairs() -> ~[(int,int)] {
@@ -758,19 +758,19 @@ condition! {
758758
759759
fn main() {
760760
// Trap the `malformed_int` condition and return -1
761-
do malformed_int::cond.trap(|_| -1).inside {
761+
malformed_int::cond.trap(|_| -1).inside(|| {
762762
763763
// Trap the `malformed_line` condition and return `UsePreviousLine`
764-
do malformed_line::cond.trap(|_| UsePreviousLine).inside {
764+
malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {
765765
766766
// The protected logic.
767767
let pairs = read_int_pairs();
768768
for &(a,b) in pairs.iter() {
769769
println!("{:4.4d}, {:4.4d}", a, b);
770770
}
771771
772-
}
773-
}
772+
})
773+
})
774774
}
775775
776776
// Parse an int; if parsing fails, call the condition handler and

doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ might look like the example below.
253253
# use std::vec;
254254
255255
// Create a vector of ports, one for each child task
256-
let ports = do vec::from_fn(3) |init_val| {
256+
let ports = vec::from_fn(3, |init_val| {
257257
let (port, chan) = stream();
258258
do spawn {
259259
chan.send(some_expensive_computation(init_val));
260260
}
261261
port
262-
};
262+
});
263263
264264
// Wait on each port, accumulating the results
265265
let result = ports.iter().fold(0, |accum, port| accum + port.recv() );

doc/tutorial.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,19 +1439,14 @@ call_twice(function);
14391439
14401440
## Do syntax
14411441
1442-
The `do` expression provides a way to treat higher-order functions
1443-
(functions that take closures as arguments) as control structures.
1442+
The `do` expression makes it easier to call functions that take procedures
1443+
as arguments.
14441444
1445-
Consider this function that iterates over a vector of
1446-
integers, passing in a pointer to each integer in the vector:
1445+
Consider this function that takes a procedure:
14471446
14481447
~~~~
1449-
fn each(v: &[int], op: |v: &int|) {
1450-
let mut n = 0;
1451-
while n < v.len() {
1452-
op(&v[n]);
1453-
n += 1;
1454-
}
1448+
fn call_it(op: proc(v: int)) {
1449+
op(10)
14551450
}
14561451
~~~~
14571452
@@ -1460,26 +1455,24 @@ argument, we can write it in a way that has a pleasant, block-like
14601455
structure.
14611456
14621457
~~~~
1463-
# fn each(v: &[int], op: |v: &int|) { }
1464-
# fn do_some_work(i: &int) { }
1465-
each([1, 2, 3], |n| {
1466-
do_some_work(n);
1458+
# fn call_it(op: proc(v: int)) { }
1459+
call_it(proc(n) {
1460+
println(n.to_str());
14671461
});
14681462
~~~~
14691463
14701464
This is such a useful pattern that Rust has a special form of function
1471-
call that can be written more like a built-in control structure:
1465+
call for these functions.
14721466
14731467
~~~~
1474-
# fn each(v: &[int], op: |v: &int|) { }
1475-
# fn do_some_work(i: &int) { }
1476-
do each([1, 2, 3]) |n| {
1477-
do_some_work(n);
1468+
# fn call_it(op: proc(v: int)) { }
1469+
do call_it() |n| {
1470+
println(n.to_str());
14781471
}
14791472
~~~~
14801473
14811474
The call is prefixed with the keyword `do` and, instead of writing the
1482-
final closure inside the argument list, it appears outside of the
1475+
final procedure inside the argument list, it appears outside of the
14831476
parentheses, where it looks more like a typical block of
14841477
code.
14851478

src/libextra/arena.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ fn test_arena_destructors_fail() {
297297
for i in range(0u, 10) {
298298
// Arena allocate something with drop glue to make sure it
299299
// doesn't leak.
300-
do arena.alloc { @i };
300+
arena.alloc(|| { @i });
301301
// Allocate something with funny size and alignment, to keep
302302
// things interesting.
303-
do arena.alloc { [0u8, 1u8, 2u8] };
303+
arena.alloc(|| { [0u8, 1u8, 2u8] });
304304
}
305305
// Now, fail while allocating
306-
do arena.alloc::<@int> {
306+
arena.alloc::<@int>(|| {
307307
// Now fail.
308308
fail!();
309-
};
309+
});
310310
}

src/libextra/base64.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,20 @@ mod test {
317317
use std::rand::{task_rng, random, Rng};
318318
use std::vec;
319319
320-
do 1000.times {
320+
1000.times(|| {
321321
let times = task_rng().gen_range(1u, 100);
322322
let v = vec::from_fn(times, |_| random::<u8>());
323323
assert_eq!(v.to_base64(STANDARD).from_base64().unwrap(), v);
324-
}
324+
})
325325
}
326326
327327
#[bench]
328328
pub fn bench_to_base64(bh: & mut BenchHarness) {
329329
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
330330
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
331-
do bh.iter {
331+
bh.iter(|| {
332332
s.as_bytes().to_base64(STANDARD);
333-
}
333+
});
334334
bh.bytes = s.len() as u64;
335335
}
336336
@@ -339,9 +339,9 @@ mod test {
339339
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
340340
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
341341
let b = s.as_bytes().to_base64(STANDARD);
342-
do bh.iter {
342+
bh.iter(|| {
343343
b.from_base64();
344-
}
344+
});
345345
bh.bytes = b.len() as u64;
346346
}
347347

0 commit comments

Comments
 (0)