Skip to content

Commit 5c6069c

Browse files
committed
auto merge of #8184 : thestinger/rust/retreat, r=huonw
2 parents 1b018dd + 1fc4db2 commit 5c6069c

File tree

257 files changed

+1312
-1314
lines changed

Some content is hidden

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

257 files changed

+1312
-1314
lines changed

doc/po/rust.md.pot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,11 +1792,11 @@ msgstr ""
17921792
msgid ""
17931793
"~~~~ {.xfail-test}\n"
17941794
"fn iter<T>(seq: &[T], f: &fn(T)) {\n"
1795-
" for seq.iter().advance |elt| { f(elt); }\n"
1795+
" foreach elt in seq.iter() { f(elt); }\n"
17961796
"}\n"
17971797
"fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {\n"
17981798
" let mut acc = ~[];\n"
1799-
" for seq.iter().advance |elt| { acc.push(f(elt)); }\n"
1799+
" foreach elt in seq.iter() { acc.push(f(elt)); }\n"
18001800
" acc\n"
18011801
"}\n"
18021802
"~~~~\n"
@@ -4570,7 +4570,7 @@ msgstr ""
45704570
#: doc/rust.md:2405
45714571
#, no-wrap
45724572
msgid ""
4573-
"for v.iter().advance |e| {\n"
4573+
"foreach e in v.iter() {\n"
45744574
" bar(*e);\n"
45754575
"}\n"
45764576
"~~~~\n"

doc/po/tutorial-container.md.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ msgstr ""
376376
#, no-wrap
377377
msgid ""
378378
"// print out all the elements in the vector\n"
379-
"for xs.iter().advance |x| {\n"
379+
"foreach x in xs.iter() {\n"
380380
" println(x.to_str())\n"
381381
"}\n"
382382
msgstr ""
@@ -386,7 +386,7 @@ msgstr ""
386386
#, no-wrap
387387
msgid ""
388388
"// print out all but the first 3 elements in the vector\n"
389-
"for xs.iter().skip(3).advance |x| {\n"
389+
"foreach x in xs.iter().skip(3) {\n"
390390
" println(x.to_str())\n"
391391
"}\n"
392392
"~~~\n"
@@ -418,7 +418,7 @@ msgstr ""
418418
#, no-wrap
419419
msgid ""
420420
"// print out the pairs of elements up to (&3, &\"baz\")\n"
421-
"for it.advance |(x, y)| {\n"
421+
"foreach (x, y) in it {\n"
422422
" println(fmt!(\"%d %s\", *x, *y));\n"
423423
msgstr ""
424424

@@ -487,7 +487,7 @@ msgid ""
487487
" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n"
488488
" let (lower, _) = iterator.size_hint();\n"
489489
" let mut xs = with_capacity(lower);\n"
490-
" for iterator.advance |x| {\n"
490+
" foreach x in iterator {\n"
491491
" xs.push(x);\n"
492492
" }\n"
493493
" xs\n"
@@ -587,7 +587,7 @@ msgstr ""
587587
#, no-wrap
588588
msgid ""
589589
"// prints `5`, `4` and `3`\n"
590-
"for it.invert().advance |&x| {\n"
590+
"foreach &x in it.invert() {\n"
591591
" println(fmt!(\"%?\", x))\n"
592592
"}\n"
593593
"~~~\n"

doc/po/tutorial-tasks.md.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ msgstr ""
587587
#, no-wrap
588588
msgid ""
589589
" let mut final_res = 0f64;\n"
590-
" for futures.mut_iter().advance |ft| {\n"
590+
" foreach ft in futures.mut_iter() {\n"
591591
" final_res += ft.get();\n"
592592
" }\n"
593593
" println(fmt!(\"^2/6 is not far from : %?\", final_res));\n"

doc/po/tutorial.md.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ msgstr ""
25012501
msgid ""
25022502
"// Iterate over a vector, obtaining a pointer to each element\n"
25032503
"// (`for` is explained in the next section)\n"
2504-
"for crayons.iter().advance |crayon| {\n"
2504+
"foreach crayon in crayons.iter() {\n"
25052505
" let delicious_crayon_wax = unwrap_crayon(*crayon);\n"
25062506
" eat_crayon_wax(delicious_crayon_wax);\n"
25072507
"}\n"
@@ -3101,7 +3101,7 @@ msgid ""
31013101
"~~~~\n"
31023102
"fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {\n"
31033103
" let mut accumulator = ~[];\n"
3104-
" for vector.iter().advance |element| {\n"
3104+
" foreach element in vector.iter() {\n"
31053105
" accumulator.push(function(element));\n"
31063106
" }\n"
31073107
" return accumulator;\n"
@@ -3570,7 +3570,7 @@ msgid ""
35703570
"~~~~\n"
35713571
"# trait Printable { fn print(&self); }\n"
35723572
"fn print_all<T: Printable>(printable_things: ~[T]) {\n"
3573-
" for printable_things.iter().advance |thing| {\n"
3573+
" foreach thing in printable_things.iter() {\n"
35743574
" thing.print();\n"
35753575
" }\n"
35763576
"}\n"
@@ -3650,7 +3650,7 @@ msgstr ""
36503650
#, no-wrap
36513651
msgid ""
36523652
"fn draw_all<T: Drawable>(shapes: ~[T]) {\n"
3653-
" for shapes.iter().advance |shape| { shape.draw(); }\n"
3653+
" foreach shape in shapes.iter() { shape.draw(); }\n"
36543654
"}\n"
36553655
"# let c: Circle = new_circle();\n"
36563656
"# draw_all(~[c]);\n"
@@ -3673,7 +3673,7 @@ msgid ""
36733673
"~~~~\n"
36743674
"# trait Drawable { fn draw(&self); }\n"
36753675
"fn draw_all(shapes: &[@Drawable]) {\n"
3676-
" for shapes.iter().advance |shape| { shape.draw(); }\n"
3676+
" foreach shape in shapes.iter() { shape.draw(); }\n"
36773677
"}\n"
36783678
"~~~~\n"
36793679
msgstr ""

doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,11 @@ the function name.
880880

881881
~~~~ {.xfail-test}
882882
fn iter<T>(seq: &[T], f: &fn(T)) {
883-
for seq.iter().advance |elt| { f(elt); }
883+
foreach elt in seq.iter() { f(elt); }
884884
}
885885
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
886886
let mut acc = ~[];
887-
for seq.iter().advance |elt| { acc.push(f(elt)); }
887+
foreach elt in seq.iter() { acc.push(f(elt)); }
888888
acc
889889
}
890890
~~~~
@@ -2378,7 +2378,7 @@ An example of a for loop over the contents of a vector:
23782378
23792379
let v: &[foo] = &[a, b, c];
23802380
2381-
for v.iter().advance |e| {
2381+
foreach e in v.iter() {
23822382
bar(*e);
23832383
}
23842384
~~~~

doc/tutorial-container.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,19 @@ dropped when they become unnecessary.
164164
165165
## For loops
166166
167-
The `for` loop syntax is currently in transition, and will switch from the old
168-
closure-based iteration protocol to iterator objects. For now, the `advance`
169-
adaptor is required as a compatibility shim to use iterators with for loops.
167+
The `foreach` keyword is transitional, and is going to replace the current
168+
obsolete `for` loop.
170169
171170
~~~
172171
let xs = [2, 3, 5, 7, 11, 13, 17];
173172

174173
// print out all the elements in the vector
175-
for xs.iter().advance |x| {
174+
foreach x in xs.iter() {
176175
println(x.to_str())
177176
}
178177

179178
// print out all but the first 3 elements in the vector
180-
for xs.iter().skip(3).advance |x| {
179+
foreach x in xs.iter().skip(3) {
181180
println(x.to_str())
182181
}
183182
~~~
@@ -193,7 +192,7 @@ let ys = ["foo", "bar", "baz", "foobar"];
193192
let mut it = xs.iter().zip(ys.iter());
194193

195194
// print out the pairs of elements up to (&3, &"baz")
196-
for it.advance |(x, y)| {
195+
foreach (x, y) in it {
197196
printfln!("%d %s", *x, *y);
198197

199198
if *x == 3 {
@@ -230,7 +229,7 @@ impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
230229
pub fn from_iterator(iterator: &mut T) -> ~[A] {
231230
let (lower, _) = iterator.size_hint();
232231
let mut xs = with_capacity(lower);
233-
for iterator.advance |x| {
232+
foreach x in iterator {
234233
xs.push(x);
235234
}
236235
xs
@@ -301,7 +300,7 @@ printfln!("%?", it.next()); // prints `Some(&2)`
301300
printfln!("%?", it.next_back()); // prints `Some(&6)`
302301

303302
// prints `5`, `4` and `3`
304-
for it.invert().advance |&x| {
303+
foreach &x in it.invert() {
305304
printfln!("%?", x)
306305
}
307306
~~~
@@ -320,7 +319,7 @@ let mut it = xs.iter().chain_(ys.iter()).transform(|&x| x * 2);
320319
printfln!("%?", it.next()); // prints `Some(2)`
321320

322321
// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`
323-
for it.invert().advance |x| {
322+
foreach x in it.invert() {
324323
printfln!("%?", x);
325324
}
326325
~~~

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn main() {
327327
let mut futures = vec::from_fn(1000, |ind| do extra::future::spawn { partial_sum(ind) });
328328
329329
let mut final_res = 0f64;
330-
for futures.mut_iter().advance |ft| {
330+
foreach ft in futures.mut_iter() {
331331
final_res += ft.get();
332332
}
333333
println(fmt!("π^2/6 is not far from : %?", final_res));

doc/tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ assert!(!crayons.is_empty());
13981398
13991399
// Iterate over a vector, obtaining a pointer to each element
14001400
// (`for` is explained in the next section)
1401-
for crayons.iter().advance |crayon| {
1401+
foreach crayon in crayons.iter() {
14021402
let delicious_crayon_wax = unwrap_crayon(*crayon);
14031403
eat_crayon_wax(delicious_crayon_wax);
14041404
}
@@ -1749,7 +1749,7 @@ of `vector`:
17491749
~~~~
17501750
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
17511751
let mut accumulator = ~[];
1752-
for vector.iter().advance |element| {
1752+
foreach element in vector.iter() {
17531753
accumulator.push(function(element));
17541754
}
17551755
return accumulator;
@@ -2027,7 +2027,7 @@ generic types.
20272027
~~~~
20282028
# trait Printable { fn print(&self); }
20292029
fn print_all<T: Printable>(printable_things: ~[T]) {
2030-
for printable_things.iter().advance |thing| {
2030+
foreach thing in printable_things.iter() {
20312031
thing.print();
20322032
}
20332033
}
@@ -2073,7 +2073,7 @@ However, consider this function:
20732073
trait Drawable { fn draw(&self); }
20742074
20752075
fn draw_all<T: Drawable>(shapes: ~[T]) {
2076-
for shapes.iter().advance |shape| { shape.draw(); }
2076+
foreach shape in shapes.iter() { shape.draw(); }
20772077
}
20782078
# let c: Circle = new_circle();
20792079
# draw_all(~[c]);
@@ -2088,7 +2088,7 @@ an _object_.
20882088
~~~~
20892089
# trait Drawable { fn draw(&self); }
20902090
fn draw_all(shapes: &[@Drawable]) {
2091-
for shapes.iter().advance |shape| { shape.draw(); }
2091+
foreach shape in shapes.iter() { shape.draw(); }
20922092
}
20932093
~~~~
20942094

src/compiletest/compiletest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
243243
config.src_base.to_str());
244244
let mut tests = ~[];
245245
let dirs = os::list_dir_path(&config.src_base);
246-
for dirs.iter().advance |file| {
246+
foreach file in dirs.iter() {
247247
let file = file.clone();
248248
debug!("inspecting file %s", file.to_str());
249249
if is_test(config, &file) {
@@ -271,11 +271,11 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
271271

272272
let mut valid = false;
273273

274-
for valid_extensions.iter().advance |ext| {
274+
foreach ext in valid_extensions.iter() {
275275
if name.ends_with(*ext) { valid = true; }
276276
}
277277

278-
for invalid_prefixes.iter().advance |pre| {
278+
foreach pre in invalid_prefixes.iter() {
279279
if name.starts_with(*pre) { valid = false; }
280280
}
281281

src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn run(lib_path: &str,
5656
err_fd: None
5757
});
5858

59-
for input.iter().advance |input| {
59+
foreach input in input.iter() {
6060
proc.input().write_str(*input);
6161
}
6262
let output = proc.finish_with_output();

src/compiletest/runtest.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
283283
// check if each line in props.check_lines appears in the
284284
// output (in order)
285285
let mut i = 0u;
286-
for ProcRes.stdout.line_iter().advance |line| {
286+
foreach line in ProcRes.stdout.line_iter() {
287287
if check_lines[i].trim() == line.trim() {
288288
i += 1u;
289289
}
@@ -313,7 +313,7 @@ fn check_error_patterns(props: &TestProps,
313313
let mut next_err_idx = 0u;
314314
let mut next_err_pat = &props.error_patterns[next_err_idx];
315315
let mut done = false;
316-
for ProcRes.stderr.line_iter().advance |line| {
316+
foreach line in ProcRes.stderr.line_iter() {
317317
if line.contains(*next_err_pat) {
318318
debug!("found error pattern %s", *next_err_pat);
319319
next_err_idx += 1u;
@@ -333,7 +333,7 @@ fn check_error_patterns(props: &TestProps,
333333
fatal_ProcRes(fmt!("error pattern '%s' not found!",
334334
missing_patterns[0]), ProcRes);
335335
} else {
336-
for missing_patterns.iter().advance |pattern| {
336+
foreach pattern in missing_patterns.iter() {
337337
error(fmt!("error pattern '%s' not found!", *pattern));
338338
}
339339
fatal_ProcRes(~"multiple error patterns not found", ProcRes);
@@ -386,9 +386,9 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
386386
// filename:line1:col1: line2:col2: *warning:* msg
387387
// where line1:col1: is the starting point, line2:col2:
388388
// is the ending point, and * represents ANSI color codes.
389-
for ProcRes.stderr.line_iter().advance |line| {
389+
foreach line in ProcRes.stderr.line_iter() {
390390
let mut was_expected = false;
391-
for expected_errors.iter().enumerate().advance |(i, ee)| {
391+
foreach (i, ee) in expected_errors.iter().enumerate() {
392392
if !found_flags[i] {
393393
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
394394
prefixes[i], ee.kind, ee.msg, line);
@@ -559,7 +559,7 @@ fn compose_and_run_compiler(
559559
let extra_link_args = ~[~"-L",
560560
aux_output_dir_name(config, testfile).to_str()];
561561

562-
for props.aux_builds.iter().advance |rel_ab| {
562+
foreach rel_ab in props.aux_builds.iter() {
563563
let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
564564
let aux_args =
565565
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
@@ -786,7 +786,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
786786
runargs.push(fmt!("%s", config.adb_test_dir));
787787
runargs.push(fmt!("%s", prog_short));
788788

789-
for args.args.iter().advance |tv| {
789+
foreach tv in args.args.iter() {
790790
runargs.push(tv.to_owned());
791791
}
792792

@@ -803,7 +803,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
803803
Some(~""));
804804

805805
let mut exitcode : int = 0;
806-
for exitcode_out.iter().advance |c| {
806+
foreach c in exitcode_out.iter() {
807807
if !c.is_digit() { break; }
808808
exitcode = exitcode * 10 + match c {
809809
'0' .. '9' => c as int - ('0' as int),
@@ -852,7 +852,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
852852
let tstr = aux_output_dir_name(config, testfile).to_str();
853853

854854
let dirs = os::list_dir_path(&Path(tstr));
855-
for dirs.iter().advance |file| {
855+
foreach file in dirs.iter() {
856856

857857
if (file.filetype() == Some(~".so")) {
858858

src/libextra/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ mod tests {
789789
}
790790
791791
// Wait for children to pass their asserts
792-
for children.iter().advance |r| {
792+
foreach r in children.iter() {
793793
r.recv();
794794
}
795795

src/libextra/base64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'self> FromBase64 for &'self [u8] {
206206
let mut modulus = 0;
207207

208208
let mut it = self.iter();
209-
for it.advance |&byte| {
209+
foreach &byte in it {
210210
let ch = byte as char;
211211
let val = byte as u32;
212212

0 commit comments

Comments
 (0)