Skip to content

Commit 02be4e8

Browse files
committed
---
yaml --- r: 90093 b: refs/heads/master c: 7920772 h: refs/heads/master i: 90091: 4dccde9 v: v3
1 parent d31aaa3 commit 02be4e8

File tree

534 files changed

+4615
-4674
lines changed

Some content is hidden

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

534 files changed

+4615
-4674
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 18687a92ae6b79eb221706db7b7390330b2f7a21
2+
refs/heads/master: 792077274cb02894e059c6cc73b998223e549cbb
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8

trunk/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 |int,int| -> int; let bo: Binop = add; x = "
5386+
"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = "
53875387
"bo(5,7); ~~~~~~~~"
53885388
msgstr ""
53895389

trunk/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 |int,int| -> int; let bo: Binop = add; x = "
5373+
"type Binop<'self> = &'self fn(int,int) -> int; let bo: Binop = add; x = "
53745374
"bo(5,7); ~~~~~~~~"
53755375
msgstr ""
53765376

trunk/doc/rust.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,8 +1754,6 @@ names are effectively reserved. Some significant attributes include:
17541754
* The `deriving` attribute, for automatically generating
17551755
implementations of certain traits.
17561756
* The `static_assert` attribute, for asserting that a static bool is true at compiletime
1757-
* The `thread_local` attribute, for defining a `static mut` as a thread-local. Note that this is
1758-
only a low-level building block, and is not local to a *task*, nor does it provide safety.
17591757

17601758
Other attributes may be added or removed during development of the language.
17611759

@@ -2705,27 +2703,33 @@ A `loop` expression is only permitted in the body of a loop.
27052703
do_expr : "do" expr [ '|' ident_list '|' ] ? '{' block '}' ;
27062704
~~~~
27072705

2708-
A _do expression_ provides a more-familiar block syntax
2709-
for invoking a function and passing it a newly-created a procedure.
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.
27102708

2711-
The optional `ident_list` and `block` provided in a `do` expression are parsed
2712-
as though they constitute a procedure expression;
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;
27132718
if the `ident_list` is missing, an empty `ident_list` is implied.
27142719

2715-
The procedure expression is then provided as a _trailing argument_
2716-
to the outermost [call](#call-expressions) or
2717-
[method call](#method-call-expressions) expression
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
27182722
in the `expr` following `do`.
27192723
If the `expr` is a [path expression](#path-expressions), it is parsed as though it is a call expression.
27202724
If the `expr` is a [field expression](#field-expressions), it is parsed as though it is a method call expression.
27212725

27222726
In this example, both calls to `f` are equivalent:
27232727

27242728
~~~~
2725-
# fn f(f: proc(int)) { }
2729+
# fn f(f: |int|) { }
27262730
# fn g(i: int) { }
27272731
2728-
f(proc(j) { g(j) });
2732+
f(|j| g(j));
27292733
27302734
do f |j| {
27312735
g(j);
@@ -2735,10 +2739,10 @@ do f |j| {
27352739
In this example, both calls to the (binary) function `k` are equivalent:
27362740

27372741
~~~~
2738-
# fn k(x:int, f: proc(int)) { }
2742+
# fn k(x:int, f: |int|) { }
27392743
# fn l(i: int) { }
27402744
2741-
k(3, proc(j) { l(j) });
2745+
k(3, |j| l(j));
27422746
27432747
do k(3) |j| {
27442748
l(j);
@@ -3190,7 +3194,7 @@ fn add(x: int, y: int) -> int {
31903194
31913195
let mut x = add(5,7);
31923196
3193-
type Binop<'self> = 'self |int,int| -> int;
3197+
type Binop<'self> = &'self fn(int,int) -> int;
31943198
let bo: Binop = add;
31953199
x = bo(5,7);
31963200
~~~~

trunk/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-
malformed_line::cond.trap(|_| (-1,-1)).inside(|| {
460+
do 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-
malformed_line::cond.trap(|_| None).inside(|| {
538+
do 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-
malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {
634+
do 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-
malformed_int::cond.trap(|_| -1).inside(|| {
761+
do malformed_int::cond.trap(|_| -1).inside {
762762
763763
// Trap the `malformed_line` condition and return `UsePreviousLine`
764-
malformed_line::cond.trap(|_| UsePreviousLine).inside(|| {
764+
do 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

trunk/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(proc() println("I am also running in a different task!") );
79+
spawn( || 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 = vec::from_fn(3, |init_val| {
256+
let ports = do 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(proc() fib(50));
281+
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
282282
make_a_sandwich();
283283
println!("fib(50) = {:?}", delayed_fib.get())
284284
~~~

trunk/doc/tutorial.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,14 +1439,19 @@ call_twice(function);
14391439
14401440
## Do syntax
14411441
1442-
The `do` expression makes it easier to call functions that take procedures
1443-
as arguments.
1442+
The `do` expression provides a way to treat higher-order functions
1443+
(functions that take closures as arguments) as control structures.
14441444
1445-
Consider this function that takes a procedure:
1445+
Consider this function that iterates over a vector of
1446+
integers, passing in a pointer to each integer in the vector:
14461447
14471448
~~~~
1448-
fn call_it(op: proc(v: int)) {
1449-
op(10)
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+
}
14501455
}
14511456
~~~~
14521457
@@ -1455,24 +1460,26 @@ argument, we can write it in a way that has a pleasant, block-like
14551460
structure.
14561461
14571462
~~~~
1458-
# fn call_it(op: proc(v: int)) { }
1459-
call_it(proc(n) {
1460-
println(n.to_str());
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);
14611467
});
14621468
~~~~
14631469
14641470
This is such a useful pattern that Rust has a special form of function
1465-
call for these functions.
1471+
call that can be written more like a built-in control structure:
14661472
14671473
~~~~
1468-
# fn call_it(op: proc(v: int)) { }
1469-
do call_it() |n| {
1470-
println(n.to_str());
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);
14711478
}
14721479
~~~~
14731480
14741481
The call is prefixed with the keyword `do` and, instead of writing the
1475-
final procedure inside the argument list, it appears outside of the
1482+
final closure inside the argument list, it appears outside of the
14761483
parentheses, where it looks more like a typical block of
14771484
code.
14781485

trunk/src/compiletest/compiletest.rs

Lines changed: 6 additions & 8 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 = make_test(config, &file, || {
269+
let t = do 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, f: || -> test::TestFn)
305-
-> test::TestDescAndFn {
304+
pub fn make_test(config: &config, testfile: &Path,
305+
f: &fn()->test::TestFn) -> test::TestDescAndFn {
306306
test::TestDescAndFn {
307307
desc: test::TestDesc {
308308
name: make_test_name(config, testfile),
@@ -333,15 +333,13 @@ 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(proc() { runtest::run(config.take(), testfile.take()) })
336+
test::DynTestFn(|| { 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(proc(mm) {
345-
runtest::run_metrics(config.take(), testfile.take(), mm)
346-
})
344+
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
347345
}

trunk/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-
iter_header(testfile, |ln| {
42+
do 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 = iter_header(testfile, |ln| {
94+
let val = do 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: |&str| -> bool) -> bool {
105+
fn iter_header(testfile: &Path, it: &fn(&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-
parse_name_value_directive(line, ~"exec-env").map(|nv| {
146+
do 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> {

trunk/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 = env.map(|pair| {
25+
env = do 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
}

0 commit comments

Comments
 (0)