Skip to content

Commit e9a1869

Browse files
committed
auto merge of #10581 : pcwalton/rust/dedo, r=pcwalton
r? @alexcrichton
2 parents 9f9efae + 9521551 commit e9a1869

File tree

524 files changed

+4211
-4485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

524 files changed

+4211
-4485
lines changed

doc/po/ja/rust.md.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5383,7 +5383,7 @@ msgstr ""
53835383
#. type: Plain text
53845384
#: doc/rust.md:2849
53855385
msgid ""
5386-
"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = "
5386+
"type Binop<'self> = 'self |int,int| -> int; let bo: Binop = add; x = "
53875387
"bo(5,7); ~~~~~~~~"
53885388
msgstr ""
53895389

doc/po/rust.md.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5370,7 +5370,7 @@ msgstr ""
53705370
#. type: Plain text
53715371
#: doc/rust.md:2849
53725372
msgid ""
5373-
"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = "
5373+
"type Binop<'self> = 'self |int,int| -> int; let bo: Binop = add; x = "
53745374
"bo(5,7); ~~~~~~~~"
53755375
msgstr ""
53765376

doc/rust.md

Lines changed: 13 additions & 19 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);
@@ -3194,7 +3188,7 @@ fn add(x: int, y: int) -> int {
31943188
31953189
let mut x = add(5,7);
31963190
3197-
type Binop<'self> = &'self fn(int,int) -> int;
3191+
type Binop<'self> = 'self |int,int| -> int;
31983192
let bo: Binop = add;
31993193
x = bo(5,7);
32003194
~~~~

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn print_message() { println("I am running in a different task!"); }
7676
spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
79-
spawn( || println("I am also running in a different task!") );
79+
spawn(proc() println("I am also running in a different task!") );
8080
8181
// The canonical way to spawn is using `do` notation
8282
do spawn {
@@ -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() );
@@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 {
278278
12586269025
279279
}
280280
281-
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
281+
let mut delayed_fib = extra::future::Future::spawn(proc() fib(50));
282282
make_a_sandwich();
283283
println!("fib(50) = {:?}", delayed_fib.get())
284284
~~~

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/compiletest/compiletest.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
266266
let file = file.clone();
267267
debug!("inspecting file {}", file.display());
268268
if is_test(config, &file) {
269-
let t = do make_test(config, &file) {
269+
let t = make_test(config, &file, || {
270270
match config.mode {
271271
mode_codegen => make_metrics_test_closure(config, &file),
272272
_ => make_test_closure(config, &file)
273273
}
274-
};
274+
});
275275
tests.push(t)
276276
}
277277
}
@@ -301,8 +301,8 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
301301
return valid;
302302
}
303303

304-
pub fn make_test(config: &config, testfile: &Path,
305-
f: &fn()->test::TestFn) -> test::TestDescAndFn {
304+
pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
305+
-> test::TestDescAndFn {
306306
test::TestDescAndFn {
307307
desc: test::TestDesc {
308308
name: make_test_name(config, testfile),
@@ -333,13 +333,15 @@ pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
333333
let config = Cell::new((*config).clone());
334334
// FIXME (#9639): This needs to handle non-utf8 paths
335335
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
336-
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
336+
test::DynTestFn(proc() { runtest::run(config.take(), testfile.take()) })
337337
}
338338

339339
pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
340340
use std::cell::Cell;
341341
let config = Cell::new((*config).clone());
342342
// FIXME (#9639): This needs to handle non-utf8 paths
343343
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
344-
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
344+
test::DynMetricFn(proc(mm) {
345+
runtest::run_metrics(config.take(), testfile.take(), mm)
346+
})
345347
}

src/compiletest/header.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
3939
let mut pp_exact = None;
4040
let mut debugger_cmds = ~[];
4141
let mut check_lines = ~[];
42-
do iter_header(testfile) |ln| {
42+
iter_header(testfile, |ln| {
4343
match parse_error_pattern(ln) {
4444
Some(ep) => error_patterns.push(ep),
4545
None => ()
@@ -74,7 +74,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
7474
};
7575

7676
true
77-
};
77+
});
7878
return TestProps {
7979
error_patterns: error_patterns,
8080
compile_flags: compile_flags,
@@ -91,18 +91,18 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
9191
~"xfail-" + util::get_os(config.target)
9292
}
9393
94-
let val = do iter_header(testfile) |ln| {
94+
let val = iter_header(testfile, |ln| {
9595
if parse_name_directive(ln, "xfail-test") { false }
9696
else if parse_name_directive(ln, xfail_target(config)) { false }
9797
else if config.mode == common::mode_pretty &&
9898
parse_name_directive(ln, "xfail-pretty") { false }
9999
else { true }
100-
};
100+
});
101101

102102
!val
103103
}
104104

105-
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
105+
fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
106106
use std::io::buffered::BufferedReader;
107107
use std::io::File;
108108

@@ -143,7 +143,7 @@ fn parse_check_line(line: &str) -> Option<~str> {
143143
}
144144

145145
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
146-
do parse_name_value_directive(line, ~"exec-env").map |nv| {
146+
parse_name_value_directive(line, ~"exec-env").map(|nv| {
147147
// nv is either FOO or FOO=BAR
148148
let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
149149

@@ -155,7 +155,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
155155
}
156156
n => fail!("Expected 1 or 2 strings, not {}", n)
157157
}
158-
}
158+
})
159159
}
160160

161161
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
2222
assert!(prog.ends_with(".exe"));
2323
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";
2424

25-
env = do env.map() |pair| {
25+
env = env.map(|pair| {
2626
let (k,v) = (*pair).clone();
2727
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
2828
else { (k,v) }
29-
};
29+
});
3030
if prog.ends_with("rustc.exe") {
3131
env.push((~"RUST_THREADS", ~"1"));
3232
}

src/compiletest/runtest.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ fn check_error_patterns(props: &TestProps,
427427
testfile: &Path,
428428
ProcRes: &ProcRes) {
429429
if props.error_patterns.is_empty() {
430-
do testfile.display().with_str |s| {
430+
testfile.display().with_str(|s| {
431431
fatal(~"no error pattern specified in " + s);
432-
}
432+
})
433433
}
434434
435435
if ProcRes.status.success() {
@@ -730,9 +730,12 @@ fn compose_and_run(config: &config, testfile: &Path,
730730
prog, args, procenv, input);
731731
}
732732
733-
fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str],
734-
xform: &fn(&config, (&Path)) -> Path,
735-
testfile: &Path) -> ProcArgs {
733+
fn make_compile_args(config: &config,
734+
props: &TestProps,
735+
extras: ~[~str],
736+
xform: |&config, &Path| -> Path,
737+
testfile: &Path)
738+
-> ProcArgs {
736739
let xform_file = xform(config, testfile);
737740
// FIXME (#9639): This needs to handle non-utf8 paths
738741
let mut args = ~[testfile.as_str().unwrap().to_owned(),

0 commit comments

Comments
 (0)