Skip to content

Commit 3b126e4

Browse files
committed
auto merge of #7274 : thestinger/rust/size_hint, r=huonw
I ran into a weird lifetime bug blocking updating the `collect` method to use `FromIterator`, but everything here works fine.
2 parents fc83d82 + d2e9912 commit 3b126e4

File tree

182 files changed

+886
-884
lines changed

Some content is hidden

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

182 files changed

+886
-884
lines changed

doc/rust.md

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

883883
~~~~ {.xfail-test}
884884
fn iter<T>(seq: &[T], f: &fn(T)) {
885-
for seq.each |elt| { f(elt); }
885+
for seq.iter().advance |elt| { f(elt); }
886886
}
887887
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
888888
let mut acc = ~[];
889-
for seq.each |elt| { acc.push(f(elt)); }
889+
for seq.iter().advance |elt| { acc.push(f(elt)); }
890890
acc
891891
}
892892
~~~~
@@ -2329,7 +2329,7 @@ An example of a for loop over the contents of a vector:
23292329
23302330
let v: &[foo] = &[a, b, c];
23312331
2332-
for v.each |e| {
2332+
for v.iter().advance |e| {
23332333
bar(*e);
23342334
}
23352335
~~~~

doc/tutorial.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ assert!(!crayons.is_empty());
13961396
13971397
// Iterate over a vector, obtaining a pointer to each element
13981398
// (`for` is explained in the next section)
1399-
for crayons.each |crayon| {
1399+
for crayons.iter().advance |crayon| {
14001400
let delicious_crayon_wax = unwrap_crayon(*crayon);
14011401
eat_crayon_wax(delicious_crayon_wax);
14021402
}
@@ -2119,7 +2119,7 @@ generic types.
21192119
~~~~
21202120
# trait Printable { fn print(&self); }
21212121
fn print_all<T: Printable>(printable_things: ~[T]) {
2122-
for printable_things.each |thing| {
2122+
for printable_things.iter().advance |thing| {
21232123
thing.print();
21242124
}
21252125
}
@@ -2165,7 +2165,7 @@ However, consider this function:
21652165
trait Drawable { fn draw(&self); }
21662166
21672167
fn draw_all<T: Drawable>(shapes: ~[T]) {
2168-
for shapes.each |shape| { shape.draw(); }
2168+
for shapes.iter().advance |shape| { shape.draw(); }
21692169
}
21702170
# let c: Circle = new_circle();
21712171
# draw_all(~[c]);
@@ -2180,7 +2180,7 @@ an _object_.
21802180
~~~~
21812181
# trait Drawable { fn draw(&self); }
21822182
fn draw_all(shapes: &[@Drawable]) {
2183-
for shapes.each |shape| { shape.draw(); }
2183+
for shapes.iter().advance |shape| { shape.draw(); }
21842184
}
21852185
~~~~
21862186

src/compiletest/compiletest.rc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
208208
debug!("making tests from %s",
209209
config.src_base.to_str());
210210
let mut tests = ~[];
211-
for os::list_dir_path(&config.src_base).each |file| {
211+
let dirs = os::list_dir_path(&config.src_base);
212+
for dirs.iter().advance |file| {
212213
let file = copy *file;
213214
debug!("inspecting file %s", file.to_str());
214215
if is_test(config, file) {
@@ -230,11 +231,11 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
230231

231232
let mut valid = false;
232233

233-
for valid_extensions.each |ext| {
234+
for valid_extensions.iter().advance |ext| {
234235
if name.ends_with(*ext) { valid = true; }
235236
}
236237

237-
for invalid_prefixes.each |pre| {
238+
for invalid_prefixes.iter().advance |pre| {
238239
if name.starts_with(*pre) { valid = false; }
239240
}
240241

src/compiletest/runtest.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn check_error_patterns(props: &TestProps,
327327
fatal_ProcRes(fmt!("error pattern '%s' not found!",
328328
missing_patterns[0]), ProcRes);
329329
} else {
330-
for missing_patterns.each |pattern| {
330+
for missing_patterns.iter().advance |pattern| {
331331
error(fmt!("error pattern '%s' not found!", *pattern));
332332
}
333333
fatal_ProcRes(~"multiple error patterns not found", ProcRes);
@@ -757,7 +757,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
757757
runargs.push(fmt!("%s", config.adb_test_dir));
758758
runargs.push(fmt!("%s", prog_short));
759759

760-
for args.args.each |tv| {
760+
for args.args.iter().advance |tv| {
761761
runargs.push(tv.to_owned());
762762
}
763763

@@ -822,7 +822,8 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
822822
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
823823
let tstr = aux_output_dir_name(config, testfile).to_str();
824824

825-
for os::list_dir_path(&Path(tstr)).each |file| {
825+
let dirs = os::list_dir_path(&Path(tstr));
826+
for dirs.iter().advance |file| {
826827

827828
if (file.filetype() == Some(~".so")) {
828829

src/libextra/arc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ mod tests {
517517

518518
use arc::*;
519519

520+
use core::vec;
520521
use core::cell::Cell;
521522
use core::comm;
522523
use core::task;
@@ -725,7 +726,7 @@ mod tests {
725726
}
726727

727728
// Wait for children to pass their asserts
728-
for children.each |r| {
729+
for children.iter().advance |r| {
729730
r.recv();
730731
}
731732

@@ -790,7 +791,7 @@ mod tests {
790791
assert_eq!(*state, 42);
791792
*state = 31337;
792793
// send to other readers
793-
for reader_convos.each |x| {
794+
for vec::each(reader_convos) |x| {
794795
match *x {
795796
(ref rc, _) => rc.send(()),
796797
}
@@ -799,7 +800,7 @@ mod tests {
799800
let read_mode = arc.downgrade(write_mode);
800801
do (&read_mode).read |state| {
801802
// complete handshake with other readers
802-
for reader_convos.each |x| {
803+
for vec::each(reader_convos) |x| {
803804
match *x {
804805
(_, ref rp) => rp.recv(),
805806
}

src/libextra/fileinput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ mod test {
421421
fn make_file(path : &Path, contents: &[~str]) {
422422
let file = io::file_writer(path, [io::Create, io::Truncate]).get();
423423
424-
for contents.each |&str| {
424+
for contents.iter().advance |&str| {
425425
file.write_str(str);
426426
file.write_char('\n');
427427
}

src/libextra/getopts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
295295
}
296296
}
297297
let mut name_pos = 0;
298-
for names.each() |nm| {
298+
for names.iter().advance() |nm| {
299299
name_pos += 1;
300300
let optid = match find_opt(opts, copy *nm) {
301301
Some(id) => id,
@@ -373,7 +373,7 @@ pub fn opt_count(mm: &Matches, nm: &str) -> uint {
373373

374374
/// Returns true if any of several options were matched
375375
pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
376-
for names.each |nm| {
376+
for names.iter().advance |nm| {
377377
match find_opt(mm.opts, mkname(*nm)) {
378378
Some(id) if !mm.vals[id].is_empty() => return true,
379379
_ => (),
@@ -400,7 +400,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
400400
* option took an argument
401401
*/
402402
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
403-
for names.each |nm| {
403+
for names.iter().advance |nm| {
404404
match opt_val(mm, *nm) {
405405
Val(ref s) => return copy *s,
406406
_ => ()

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ mod tests {
13851385
fn mk_object(items: &[(~str, Json)]) -> Json {
13861386
let mut d = ~HashMap::new();
13871387

1388-
for items.each |item| {
1388+
for items.iter().advance |item| {
13891389
match *item {
13901390
(ref key, ref value) => { d.insert(copy *key, copy *value); },
13911391
}

src/libextra/net_ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ mod test {
426426
let results = result::unwrap(ga_result);
427427
debug!("test_get_addr: Number of results for %s: %?",
428428
localhost_name, results.len());
429-
for results.each |r| {
429+
for results.iter().advance |r| {
430430
let ipv_prefix = match *r {
431431
Ipv4(_) => ~"IPv4",
432432
Ipv6(_) => ~"IPv6"

src/libextra/net_url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
210210
for m.each |key, values| {
211211
let key = encode_plus(*key);
212212

213-
for values.each |value| {
213+
for values.iter().advance |value| {
214214
if first {
215215
first = false;
216216
} else {
@@ -342,7 +342,7 @@ fn query_from_str(rawquery: &str) -> Query {
342342

343343
pub fn query_to_str(query: &Query) -> ~str {
344344
let mut strvec = ~[];
345-
for query.each |kv| {
345+
for query.iter().advance |kv| {
346346
match kv {
347347
&(ref k, ref v) => {
348348
strvec.push(fmt!("%s=%s",

0 commit comments

Comments
 (0)