Skip to content

Commit

Permalink
auto merge of #7274 : thestinger/rust/size_hint, r=huonw
Browse files Browse the repository at this point in the history
I ran into a weird lifetime bug blocking updating the `collect` method to use `FromIterator`, but everything here works fine.
  • Loading branch information
bors committed Jun 23, 2013
2 parents fc83d82 + d2e9912 commit 3b126e4
Show file tree
Hide file tree
Showing 182 changed files with 886 additions and 884 deletions.
6 changes: 3 additions & 3 deletions doc/rust.md
Expand Up @@ -882,11 +882,11 @@ the function name.

~~~~ {.xfail-test}
fn iter<T>(seq: &[T], f: &fn(T)) {
for seq.each |elt| { f(elt); }
for seq.iter().advance |elt| { f(elt); }
}
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
let mut acc = ~[];
for seq.each |elt| { acc.push(f(elt)); }
for seq.iter().advance |elt| { acc.push(f(elt)); }
acc
}
~~~~
Expand Down Expand Up @@ -2329,7 +2329,7 @@ An example of a for loop over the contents of a vector:
let v: &[foo] = &[a, b, c];
for v.each |e| {
for v.iter().advance |e| {
bar(*e);
}
~~~~
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorial.md
Expand Up @@ -1396,7 +1396,7 @@ assert!(!crayons.is_empty());
// Iterate over a vector, obtaining a pointer to each element
// (`for` is explained in the next section)
for crayons.each |crayon| {
for crayons.iter().advance |crayon| {
let delicious_crayon_wax = unwrap_crayon(*crayon);
eat_crayon_wax(delicious_crayon_wax);
}
Expand Down Expand Up @@ -2119,7 +2119,7 @@ generic types.
~~~~
# trait Printable { fn print(&self); }
fn print_all<T: Printable>(printable_things: ~[T]) {
for printable_things.each |thing| {
for printable_things.iter().advance |thing| {
thing.print();
}
}
Expand Down Expand Up @@ -2165,7 +2165,7 @@ However, consider this function:
trait Drawable { fn draw(&self); }
fn draw_all<T: Drawable>(shapes: ~[T]) {
for shapes.each |shape| { shape.draw(); }
for shapes.iter().advance |shape| { shape.draw(); }
}
# let c: Circle = new_circle();
# draw_all(~[c]);
Expand All @@ -2180,7 +2180,7 @@ an _object_.
~~~~
# trait Drawable { fn draw(&self); }
fn draw_all(shapes: &[@Drawable]) {
for shapes.each |shape| { shape.draw(); }
for shapes.iter().advance |shape| { shape.draw(); }
}
~~~~

Expand Down
7 changes: 4 additions & 3 deletions src/compiletest/compiletest.rc
Expand Up @@ -208,7 +208,8 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
debug!("making tests from %s",
config.src_base.to_str());
let mut tests = ~[];
for os::list_dir_path(&config.src_base).each |file| {
let dirs = os::list_dir_path(&config.src_base);
for dirs.iter().advance |file| {
let file = copy *file;
debug!("inspecting file %s", file.to_str());
if is_test(config, file) {
Expand All @@ -230,11 +231,11 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {

let mut valid = false;

for valid_extensions.each |ext| {
for valid_extensions.iter().advance |ext| {
if name.ends_with(*ext) { valid = true; }
}

for invalid_prefixes.each |pre| {
for invalid_prefixes.iter().advance |pre| {
if name.starts_with(*pre) { valid = false; }
}

Expand Down
7 changes: 4 additions & 3 deletions src/compiletest/runtest.rs
Expand Up @@ -327,7 +327,7 @@ fn check_error_patterns(props: &TestProps,
fatal_ProcRes(fmt!("error pattern '%s' not found!",
missing_patterns[0]), ProcRes);
} else {
for missing_patterns.each |pattern| {
for missing_patterns.iter().advance |pattern| {
error(fmt!("error pattern '%s' not found!", *pattern));
}
fatal_ProcRes(~"multiple error patterns not found", ProcRes);
Expand Down Expand Up @@ -757,7 +757,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
runargs.push(fmt!("%s", config.adb_test_dir));
runargs.push(fmt!("%s", prog_short));

for args.args.each |tv| {
for args.args.iter().advance |tv| {
runargs.push(tv.to_owned());
}

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

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

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

Expand Down
7 changes: 4 additions & 3 deletions src/libextra/arc.rs
Expand Up @@ -517,6 +517,7 @@ mod tests {

use arc::*;

use core::vec;
use core::cell::Cell;
use core::comm;
use core::task;
Expand Down Expand Up @@ -725,7 +726,7 @@ mod tests {
}

// Wait for children to pass their asserts
for children.each |r| {
for children.iter().advance |r| {
r.recv();
}

Expand Down Expand Up @@ -790,7 +791,7 @@ mod tests {
assert_eq!(*state, 42);
*state = 31337;
// send to other readers
for reader_convos.each |x| {
for vec::each(reader_convos) |x| {
match *x {
(ref rc, _) => rc.send(()),
}
Expand All @@ -799,7 +800,7 @@ mod tests {
let read_mode = arc.downgrade(write_mode);
do (&read_mode).read |state| {
// complete handshake with other readers
for reader_convos.each |x| {
for vec::each(reader_convos) |x| {
match *x {
(_, ref rp) => rp.recv(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/fileinput.rs
Expand Up @@ -421,7 +421,7 @@ mod test {
fn make_file(path : &Path, contents: &[~str]) {
let file = io::file_writer(path, [io::Create, io::Truncate]).get();
for contents.each |&str| {
for contents.iter().advance |&str| {
file.write_str(str);
file.write_char('\n');
}
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/getopts.rs
Expand Up @@ -295,7 +295,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
}
}
let mut name_pos = 0;
for names.each() |nm| {
for names.iter().advance() |nm| {
name_pos += 1;
let optid = match find_opt(opts, copy *nm) {
Some(id) => id,
Expand Down Expand Up @@ -373,7 +373,7 @@ pub fn opt_count(mm: &Matches, nm: &str) -> uint {

/// Returns true if any of several options were matched
pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
for names.each |nm| {
for names.iter().advance |nm| {
match find_opt(mm.opts, mkname(*nm)) {
Some(id) if !mm.vals[id].is_empty() => return true,
_ => (),
Expand All @@ -400,7 +400,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
* option took an argument
*/
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
for names.each |nm| {
for names.iter().advance |nm| {
match opt_val(mm, *nm) {
Val(ref s) => return copy *s,
_ => ()
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/json.rs
Expand Up @@ -1385,7 +1385,7 @@ mod tests {
fn mk_object(items: &[(~str, Json)]) -> Json {
let mut d = ~HashMap::new();

for items.each |item| {
for items.iter().advance |item| {
match *item {
(ref key, ref value) => { d.insert(copy *key, copy *value); },
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/net_ip.rs
Expand Up @@ -426,7 +426,7 @@ mod test {
let results = result::unwrap(ga_result);
debug!("test_get_addr: Number of results for %s: %?",
localhost_name, results.len());
for results.each |r| {
for results.iter().advance |r| {
let ipv_prefix = match *r {
Ipv4(_) => ~"IPv4",
Ipv6(_) => ~"IPv6"
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/net_url.rs
Expand Up @@ -210,7 +210,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
for m.each |key, values| {
let key = encode_plus(*key);

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

pub fn query_to_str(query: &Query) -> ~str {
let mut strvec = ~[];
for query.each |kv| {
for query.iter().advance |kv| {
match kv {
&(ref k, ref v) => {
strvec.push(fmt!("%s=%s",
Expand Down
38 changes: 20 additions & 18 deletions src/libextra/num/bigint.rs
Expand Up @@ -1349,7 +1349,7 @@ mod biguint_tests {

#[test]
fn test_add() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand All @@ -1362,7 +1362,7 @@ mod biguint_tests {

#[test]
fn test_sub() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand Down Expand Up @@ -1413,7 +1413,7 @@ mod biguint_tests {

#[test]
fn test_mul() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand All @@ -1423,7 +1423,7 @@ mod biguint_tests {
assert!(b * a == c);
}

for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand All @@ -1437,7 +1437,7 @@ mod biguint_tests {

#[test]
fn test_div_rem() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand All @@ -1451,7 +1451,7 @@ mod biguint_tests {
}
}

for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
Expand Down Expand Up @@ -1567,9 +1567,10 @@ mod biguint_tests {

#[test]
fn test_to_str_radix() {
for to_str_pairs().each |num_pair| {
let r = to_str_pairs();
for r.iter().advance |num_pair| {
let &(n, rs) = num_pair;
for rs.each |str_pair| {
for rs.iter().advance |str_pair| {
let &(radix, str) = str_pair;
assert_eq!(n.to_str_radix(radix), str);
}
Expand All @@ -1578,9 +1579,10 @@ mod biguint_tests {

#[test]
fn test_from_str_radix() {
for to_str_pairs().each |num_pair| {
let r = to_str_pairs();
for r.iter().advance |num_pair| {
let &(n, rs) = num_pair;
for rs.each |str_pair| {
for rs.iter().advance |str_pair| {
let &(radix, str) = str_pair;
assert_eq!(&n, &FromStrRadix::from_str_radix(str, radix).get());
}
Expand Down Expand Up @@ -1756,7 +1758,7 @@ mod bigint_tests {

#[test]
fn test_add() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand All @@ -1775,7 +1777,7 @@ mod bigint_tests {

#[test]
fn test_sub() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand Down Expand Up @@ -1832,7 +1834,7 @@ mod bigint_tests {

#[test]
fn test_mul() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand All @@ -1845,7 +1847,7 @@ mod bigint_tests {
assert!((-b) * a == -c);
}

for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand Down Expand Up @@ -1884,7 +1886,7 @@ mod bigint_tests {
}
}

for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand All @@ -1894,7 +1896,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
}

for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand Down Expand Up @@ -1927,7 +1929,7 @@ mod bigint_tests {
check_sub(&a.neg(), b, &q.neg(), &r.neg());
check_sub(&a.neg(), &b.neg(), q, &r.neg());
}
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand All @@ -1937,7 +1939,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
}

for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
Expand Down

0 comments on commit 3b126e4

Please sign in to comment.