1
Fork 0

De-mode vec::each() and many of the str iteration routines

Note that the method foo.each() is not de-moded, nor the other
vec routines.
This commit is contained in:
Niko Matsakis 2012-09-18 21:41:37 -07:00
parent 62b7f4d800
commit 9cf271fe96
81 changed files with 556 additions and 750 deletions

View file

@ -1235,14 +1235,14 @@ let crayons = ~[Almond, AntiqueBrass, Apricot];
assert crayons.len() == 3; assert crayons.len() == 3;
assert !crayons.is_empty(); assert !crayons.is_empty();
// Iterate over a vector // Iterate over a vector, obtaining a pointer to each element
for crayons.each |crayon| { for crayons.each |crayon| {
let delicious_crayon_wax = unwrap_crayon(crayon); let delicious_crayon_wax = unwrap_crayon(crayon);
eat_crayon_wax(delicious_crayon_wax); eat_crayon_wax(delicious_crayon_wax);
} }
// Map vector elements // Map vector elements
let crayon_names = crayons.map(crayon_to_str); let crayon_names = crayons.map(|v| crayon_to_str(v));
let favorite_crayon_name = crayon_names[0]; let favorite_crayon_name = crayon_names[0];
// Remove whitespace from before and after the string // Remove whitespace from before and after the string
@ -1384,28 +1384,32 @@ call_twice(bare_function);
Closures in Rust are frequently used in combination with higher-order Closures in Rust are frequently used in combination with higher-order
functions to simulate control structures like `if` and functions to simulate control structures like `if` and
`loop`. Consider this function that iterates over a vector of `loop`. Consider this function that iterates over a vector of
integers, applying an operator to each: integers, passing in a pointer to each integer in the vector:
~~~~ ~~~~
fn each(v: ~[int], op: fn(int)) { fn each(v: ~[int], op: fn(v: &int)) {
let mut n = 0; let mut n = 0;
while n < v.len() { while n < v.len() {
op(v[n]); op(&v[n]);
n += 1; n += 1;
} }
} }
~~~~ ~~~~
As a caller, if we use a closure to provide the final operator The reason we pass in a *pointer* to an integer rather than the
argument, we can write it in a way that has a pleasant, block-like integer itself is that this is how the actual `each()` function for
structure. vectors works. Using a pointer means that the function can be used
for vectors of any type, even large records that would be impractical
to copy out of the vector on each iteration. As a caller, if we use a
closure to provide the final operator argument, we can write it in a
way that has a pleasant, block-like structure.
~~~~ ~~~~
# fn each(v: ~[int], op: fn(int)) {} # fn each(v: ~[int], op: fn(v: &int)) { }
# fn do_some_work(i: int) { } # fn do_some_work(i: int) { }
each(~[1, 2, 3], |n| { each(~[1, 2, 3], |n| {
debug!("%i", n); debug!("%i", *n);
do_some_work(n); do_some_work(*n);
}); });
~~~~ ~~~~
@ -1413,11 +1417,11 @@ This is such a useful pattern that Rust has a special form of function
call that can be written more like a built-in control structure: call that can be written more like a built-in control structure:
~~~~ ~~~~
# fn each(v: ~[int], op: fn(int)) {} # fn each(v: ~[int], op: fn(v: &int)) { }
# fn do_some_work(i: int) { } # fn do_some_work(i: int) { }
do each(~[1, 2, 3]) |n| { do each(~[1, 2, 3]) |n| {
debug!("%i", n); debug!("%i", *n);
do_some_work(n); do_some_work(*n);
} }
~~~~ ~~~~
@ -1461,10 +1465,10 @@ Consider again our `each` function, this time improved to
break early when the iteratee returns `false`: break early when the iteratee returns `false`:
~~~~ ~~~~
fn each(v: ~[int], op: fn(int) -> bool) { fn each(v: ~[int], op: fn(v: &int) -> bool) {
let mut n = 0; let mut n = 0;
while n < v.len() { while n < v.len() {
if !op(v[n]) { if !op(&v[n]) {
break; break;
} }
n += 1; n += 1;
@ -1478,7 +1482,7 @@ And using this function to iterate over a vector:
# use each = vec::each; # use each = vec::each;
# use println = io::println; # use println = io::println;
each(~[2, 4, 8, 5, 16], |n| { each(~[2, 4, 8, 5, 16], |n| {
if n % 2 != 0 { if *n % 2 != 0 {
println(~"found odd number!"); println(~"found odd number!");
false false
} else { true } } else { true }
@ -1495,7 +1499,7 @@ to the next iteration, write `again`.
# use each = vec::each; # use each = vec::each;
# use println = io::println; # use println = io::println;
for each(~[2, 4, 8, 5, 16]) |n| { for each(~[2, 4, 8, 5, 16]) |n| {
if n % 2 != 0 { if *n % 2 != 0 {
println(~"found odd number!"); println(~"found odd number!");
break; break;
} }
@ -1511,7 +1515,7 @@ function, not just the loop body.
# use each = vec::each; # use each = vec::each;
fn contains(v: ~[int], elt: int) -> bool { fn contains(v: ~[int], elt: int) -> bool {
for each(v) |x| { for each(v) |x| {
if (x == elt) { return true; } if (*x == elt) { return true; }
} }
false false
} }
@ -1529,9 +1533,9 @@ every type they apply to. Thus, Rust allows functions and datatypes to have
type parameters. type parameters.
~~~~ ~~~~
fn map<T, U>(vector: &[T], function: fn(T) -> U) -> ~[U] { fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[]; let mut accumulator = ~[];
for vector.each |element| { for vec::each(vector) |element| {
vec::push(accumulator, function(element)); vec::push(accumulator, function(element));
} }
return accumulator; return accumulator;
@ -1544,7 +1548,12 @@ type of the vector's content agree with each other.
Inside a generic function, the names of the type parameters Inside a generic function, the names of the type parameters
(capitalized by convention) stand for opaque types. You can't look (capitalized by convention) stand for opaque types. You can't look
inside them, but you can pass them around. inside them, but you can pass them around. Note that instances of
generic types are almost always passed by pointer. For example, the
parameter `function()` is supplied with a pointer to a value of type
`T` and not a value of type `T` itself. This ensures that the
function works with the broadest set of types possible, since some
types are expensive or illegal to copy and pass by value.
## Generic datatypes ## Generic datatypes
@ -1686,12 +1695,12 @@ generalized sequence types is:
~~~~ ~~~~
trait Seq<T> { trait Seq<T> {
fn len() -> uint; fn len() -> uint;
fn iter(fn(T)); fn iter(b: fn(v: &T));
} }
impl<T> ~[T]: Seq<T> { impl<T> ~[T]: Seq<T> {
fn len() -> uint { vec::len(self) } fn len() -> uint { vec::len(self) }
fn iter(b: fn(T)) { fn iter(b: fn(v: &T)) {
for self.each |elt| { b(elt); } for vec::each(self) |elt| { b(elt); }
} }
} }
~~~~ ~~~~
@ -2186,7 +2195,7 @@ Here is the function that implements the child task:
~~~~ ~~~~
# use std::comm::DuplexStream; # use std::comm::DuplexStream;
# use pipes::{Port, Chan}; # use pipes::{Port, Chan};
fn stringifier(channel: DuplexStream<~str, uint>) { fn stringifier(channel: &DuplexStream<~str, uint>) {
let mut value: uint; let mut value: uint;
loop { loop {
value = channel.recv(); value = channel.recv();
@ -2210,7 +2219,7 @@ Here is the code for the parent task:
# use std::comm::DuplexStream; # use std::comm::DuplexStream;
# use pipes::{Port, Chan}; # use pipes::{Port, Chan};
# use task::spawn; # use task::spawn;
# fn stringifier(channel: DuplexStream<~str, uint>) { # fn stringifier(channel: &DuplexStream<~str, uint>) {
# let mut value: uint; # let mut value: uint;
# loop { # loop {
# value = channel.recv(); # value = channel.recv();
@ -2223,7 +2232,7 @@ Here is the code for the parent task:
let (from_child, to_child) = DuplexStream(); let (from_child, to_child) = DuplexStream();
do spawn || { do spawn || {
stringifier(to_child); stringifier(&to_child);
}; };
from_child.send(22u); from_child.send(22u);

View file

@ -1502,7 +1502,7 @@ fn print_source(s: source) {
print(io::with_str_writer(|writer| { print(io::with_str_writer(|writer| {
let mut list = ~" >> "; let mut list = ~" >> ";
do vec::iteri(pks) |i, pk| { for vec::eachi(pks) |i, pk| {
if str::len(list) > 78u { if str::len(list) > 78u {
writer.write_line(list); writer.write_line(list);
list = ~" >> "; list = ~" >> ";
@ -1518,16 +1518,17 @@ fn cmd_list(c: &cargo) {
sync(c); sync(c);
if vec::len(c.opts.free) >= 3u { if vec::len(c.opts.free) >= 3u {
do vec::iter_between(c.opts.free, 2u, vec::len(c.opts.free)) |name| { let v = vec::view(c.opts.free, 2u, vec::len(c.opts.free));
if !valid_pkg_name(name) { for vec::each(v) |name| {
error(fmt!("'%s' is an invalid source name", name)); if !valid_pkg_name(*name) {
error(fmt!("'%s' is an invalid source name", *name));
} else { } else {
match c.sources.find(name) { match c.sources.find(*name) {
Some(source) => { Some(source) => {
print_source(source); print_source(source);
} }
None => { None => {
error(fmt!("no such source: %s", name)); error(fmt!("no such source: %s", *name));
} }
} }
} }

View file

@ -425,8 +425,8 @@ fn compose_and_run_compiler(
let extra_link_args = ~[~"-L", let extra_link_args = ~[~"-L",
aux_output_dir_name(config, testfile).to_str()]; aux_output_dir_name(config, testfile).to_str()];
do vec::iter(props.aux_builds) |rel_ab| { for vec::each(props.aux_builds) |rel_ab| {
let abs_ab = config.aux_base.push_rel(&Path(rel_ab)); let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
let aux_args = let aux_args =
make_compile_args(config, props, ~[~"--lib"] + extra_link_args, make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
|a,b| make_lib_name(a, b, testfile), &abs_ab); |a,b| make_lib_name(a, b, testfile), &abs_ab);

View file

@ -91,7 +91,7 @@ pure fn build_sized_opt<A>(size: Option<uint>,
#[inline(always)] #[inline(always)]
pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] { pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| { do build_sized(lhs.len() + rhs.len()) |push| {
for vec::each(lhs) |x| { push(x); } for vec::each(lhs) |x| { push(*x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); } for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
} }
} }
@ -101,7 +101,7 @@ pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] { pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
do build_sized(v.len()) |push| { do build_sized(v.len()) |push| {
for vec::each(v) |elem| { for vec::each(v) |elem| {
push(f(elem)); push(f(*elem));
} }
} }
} }

View file

@ -4,7 +4,7 @@ export reinterpret_cast, forget, bump_box_refcount, transmute;
export transmute_mut, transmute_immut, transmute_region, transmute_mut_region; export transmute_mut, transmute_immut, transmute_region, transmute_mut_region;
export transmute_mut_unsafe, transmute_immut_unsafe; export transmute_mut_unsafe, transmute_immut_unsafe;
export copy_lifetime; export copy_lifetime, copy_lifetime_vec;
#[abi = "rust-intrinsic"] #[abi = "rust-intrinsic"]
extern mod rusti { extern mod rusti {
@ -85,8 +85,9 @@ unsafe fn copy_lifetime<S,T>(_ptr: &a/S, ptr: &T) -> &a/T {
} }
/// Transforms lifetime of the second pointer to match the first. /// Transforms lifetime of the second pointer to match the first.
unsafe fn copy_lifetime_to_unsafe<S,T>(_ptr: &a/S, +ptr: *T) -> &a/T { #[inline(always)]
transmute(ptr) unsafe fn copy_lifetime_vec<S,T>(_ptr: &a/[S], ptr: &T) -> &a/T {
transmute_region(ptr)
} }

View file

@ -34,7 +34,7 @@ fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
let mut result: ~[T] = ~[]; let mut result: ~[T] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
match elt { match *elt {
Left(l) => vec::push(result, l), Left(l) => vec::push(result, l),
_ => { /* fallthrough */ } _ => { /* fallthrough */ }
} }
@ -47,7 +47,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
let mut result: ~[U] = ~[]; let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
match elt { match *elt {
Right(r) => vec::push(result, r), Right(r) => vec::push(result, r),
_ => { /* fallthrough */ } _ => { /* fallthrough */ }
} }
@ -67,7 +67,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
let mut lefts: ~[T] = ~[]; let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[]; let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
match elt { match *elt {
Left(l) => vec::push(lefts, l), Left(l) => vec::push(lefts, l),
Right(r) => vec::push(rights, r) Right(r) => vec::push(rights, r)
} }

View file

@ -390,7 +390,9 @@ impl &SipState : Streaming {
fn result_str() -> ~str { fn result_str() -> ~str {
let r = self.result_bytes(); let r = self.result_bytes();
let mut s = ~""; let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); } for vec::each(r) |b| {
s += uint::to_str(*b as uint, 16u);
}
move s move s
} }
@ -483,7 +485,9 @@ fn test_siphash() {
fn to_hex_str(r: &[u8]/8) -> ~str { fn to_hex_str(r: &[u8]/8) -> ~str {
let mut s = ~""; let mut s = ~"";
for vec::each(*r) |b| { s += uint::to_str(b as uint, 16u); } for vec::each(*r) |b| {
s += uint::to_str(*b as uint, 16u);
}
return s; return s;
} }

View file

@ -451,7 +451,7 @@ fn mk_file_writer(path: &Path, flags: ~[FileFlag])
let mut fflags: c_int = wb(); let mut fflags: c_int = wb();
for vec::each(flags) |f| { for vec::each(flags) |f| {
match f { match *f {
Append => fflags |= O_APPEND as c_int, Append => fflags |= O_APPEND as c_int,
Create => fflags |= O_CREAT as c_int, Create => fflags |= O_CREAT as c_int,
Truncate => fflags |= O_TRUNC as c_int, Truncate => fflags |= O_TRUNC as c_int,

View file

@ -7,7 +7,12 @@ type IMPL_T<A> = dvec::DVec<A>;
* Attempts to access this dvec during iteration will fail. * Attempts to access this dvec during iteration will fail.
*/ */
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) { pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
unsafe { self.swap(|v| { vec::each(v, f); move v }) } unsafe {
do self.swap |v| {
v.each(f);
move v
}
}
} }
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> { pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {

View file

@ -300,146 +300,3 @@ pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
for v.each |x| { push(x); } for v.each |x| { push(x); }
} }
} }
/*
#[test]
fn test_enumerate() {
enumerate(["0", "1", "2"]) {|i,j|
assert fmt!("%u",i) == j;
}
}
#[test]
fn test_map_and_to_vec() {
let a = bind vec::iter(~[0, 1, 2], _);
let b = bind map(a, {|i| 2*i}, _);
let c = to_vec(b);
assert c == ~[0, 2, 4];
}
#[test]
fn test_map_directly_on_vec() {
let b = bind map(~[0, 1, 2], {|i| 2*i}, _);
let c = to_vec(b);
assert c == ~[0, 2, 4];
}
#[test]
fn test_filter_on_int_range() {
fn is_even(&&i: int) -> bool {
return (i % 2) == 0;
}
let l = to_vec(bind filter(bind int::range(0, 10, _), is_even, _));
assert l == ~[0, 2, 4, 6, 8];
}
#[test]
fn test_filter_on_uint_range() {
fn is_even(&&i: uint) -> bool {
return (i % 2u) == 0u;
}
let l = to_vec(bind filter(bind uint::range(0u, 10u, _), is_even, _));
assert l == ~[0u, 2u, 4u, 6u, 8u];
}
#[test]
fn test_filter_map() {
fn negativate_the_evens(&&i: int) -> Option<int> {
if i % 2 == 0 {
Some(-i)
} else {
none
}
}
let l = to_vec(bind filter_map(
bind int::range(0, 5, _), negativate_the_evens, _));
assert l == ~[0, -2, -4];
}
#[test]
fn test_flat_map_with_option() {
fn if_even(&&i: int) -> Option<int> {
if (i % 2) == 0 { Some(i) }
else { none }
}
let a = bind vec::iter(~[0, 1, 2], _);
let b = bind flat_map(a, if_even, _);
let c = to_vec(b);
assert c == ~[0, 2];
}
#[test]
fn test_flat_map_with_list() {
fn repeat(&&i: int) -> ~[int] {
let mut r = ~[];
int::range(0, i) {|_j| r += ~[i]; }
r
}
let a = bind vec::iter(~[0, 1, 2, 3], _);
let b = bind flat_map(a, repeat, _);
let c = to_vec(b);
debug!("c = %?", c);
assert c == ~[1, 2, 2, 3, 3, 3];
}
#[test]
fn test_repeat() {
let mut c = ~[], i = 0u;
repeat(5u) {||
c += ~[(i * i)];
i += 1u;
};
debug!("c = %?", c);
assert c == ~[0u, 1u, 4u, 9u, 16u];
}
#[test]
fn test_min() {
assert min(~[5, 4, 1, 2, 3]) == 1;
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_min_empty() {
min::<int, ~[int]>(~[]);
}
#[test]
fn test_max() {
assert max(~[1, 2, 4, 2, 3]) == 4;
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_max_empty() {
max::<int, ~[int]>(~[]);
}
#[test]
fn test_reversed() {
assert to_vec(bind reversed(~[1, 2, 3], _)) == ~[3, 2, 1];
}
#[test]
fn test_count() {
assert count(~[1, 2, 1, 2, 1], 1) == 3u;
}
#[test]
fn test_foldr() {
fn sub(&&a: int, &&b: int) -> int {
a - b
}
let sum = foldr(~[1, 2, 3, 4], 0, sub);
assert sum == -2;
}
*/

View file

@ -211,7 +211,7 @@ mod global_env {
fn env() -> ~[(~str,~str)] { fn env() -> ~[(~str,~str)] {
let mut pairs = ~[]; let mut pairs = ~[];
for vec::each(rustrt::rust_env_pairs()) |p| { for vec::each(rustrt::rust_env_pairs()) |p| {
let vs = str::splitn_char(p, '=', 1u); let vs = str::splitn_char(*p, '=', 1u);
assert vec::len(vs) == 2u; assert vec::len(vs) == 2u;
vec::push(pairs, (copy vs[0], copy vs[1])); vec::push(pairs, (copy vs[0], copy vs[1]));
} }
@ -893,7 +893,7 @@ mod tests {
let e = env(); let e = env();
assert vec::len(e) > 0u; assert vec::len(e) > 0u;
for vec::each(e) |p| { for vec::each(e) |p| {
let (n, v) = copy p; let (n, v) = copy *p;
log(debug, n); log(debug, n);
let v2 = getenv(n); let v2 = getenv(n);
// MingW seems to set some funky environment variables like // MingW seems to set some funky environment variables like
@ -985,7 +985,9 @@ mod tests {
// Just assuming that we've got some contents in the current directory // Just assuming that we've got some contents in the current directory
assert (vec::len(dirs) > 0u); assert (vec::len(dirs) > 0u);
for vec::each(dirs) |dir| { log(debug, dir); } for vec::each(dirs) |dir| {
log(debug, *dir);
}
} }
#[test] #[test]

View file

@ -158,7 +158,7 @@ impl ReprVisitor {
fn write_escaped_slice(slice: &str) { fn write_escaped_slice(slice: &str) {
self.writer.write_char('"'); self.writer.write_char('"');
do str::chars_iter(slice) |ch| { for str::chars_each(slice) |ch| {
self.writer.write_escaped_char(ch); self.writer.write_escaped_char(ch);
} }
self.writer.write_char('"'); self.writer.write_char('"');
@ -563,7 +563,7 @@ impl ReprPrinterWrapper {
let vec_repr = *vec_repr_ptr; let vec_repr = *vec_repr_ptr;
let data_ptr = ptr::to_unsafe_ptr(&(*vec_repr).unboxed.data); let data_ptr = ptr::to_unsafe_ptr(&(*vec_repr).unboxed.data);
let slice: &str = transmute((data_ptr, (*vec_repr).unboxed.fill)); let slice: &str = transmute((data_ptr, (*vec_repr).unboxed.fill));
do str::chars_iter(slice) |ch| { for str::chars_each(slice) |ch| {
self.printer.writer.write_escaped_char(ch); self.printer.writer.write_escaped_char(ch);
} }
self.printer.writer.write_char('"'); self.printer.writer.write_char('"');
@ -686,7 +686,7 @@ impl ReprPrinterWrapper : TyVisitor {
self.printer.writer.write_char('"'); self.printer.writer.write_char('"');
let slice_ptr: *&str = transmute(copy self.printer.ptr); let slice_ptr: *&str = transmute(copy self.printer.ptr);
let slice = *slice_ptr; let slice = *slice_ptr;
do str::chars_iter(slice) |ch| { for str::chars_each(slice) |ch| {
self.printer.writer.write_escaped_char(ch); self.printer.writer.write_escaped_char(ch);
} }
self.printer.writer.write_char('"'); self.printer.writer.write_char('"');

View file

@ -267,7 +267,7 @@ impl<T: Copy, E: Copy> Result<T, E> {
* } * }
*/ */
fn map_vec<T,U:Copy,V:Copy>( fn map_vec<T,U:Copy,V:Copy>(
ts: &[T], op: fn(T) -> Result<V,U>) -> Result<~[V],U> { ts: &[T], op: fn((&T)) -> Result<V,U>) -> Result<~[V],U> {
let mut vs: ~[V] = ~[]; let mut vs: ~[V] = ~[];
vec::reserve(vs, vec::len(ts)); vec::reserve(vs, vec::len(ts));

View file

@ -87,7 +87,7 @@ fn with_argv<T>(prog: &str, args: &[~str],
let mut argptrs = str::as_c_str(prog, |b| ~[b]); let mut argptrs = str::as_c_str(prog, |b| ~[b]);
let mut tmps = ~[]; let mut tmps = ~[];
for vec::each(args) |arg| { for vec::each(args) |arg| {
let t = @copy arg; let t = @copy *arg;
vec::push(tmps, t); vec::push(tmps, t);
vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b])); vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
} }
@ -106,7 +106,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
let mut ptrs = ~[]; let mut ptrs = ~[];
for vec::each(es) |e| { for vec::each(es) |e| {
let (k,v) = copy e; let (k,v) = copy *e;
let t = @(fmt!("%s=%s", k, v)); let t = @(fmt!("%s=%s", k, v));
vec::push(tmps, t); vec::push(tmps, t);
vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b])); vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b]));
@ -131,7 +131,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
Some(es) if !vec::is_empty(es) => { Some(es) if !vec::is_empty(es) => {
let mut blk : ~[u8] = ~[]; let mut blk : ~[u8] = ~[];
for vec::each(es) |e| { for vec::each(es) |e| {
let (k,v) = e; let (k,v) = *e;
let t = fmt!("%s=%s", k, v); let t = fmt!("%s=%s", k, v);
let mut v : ~[u8] = ::cast::reinterpret_cast(&t); let mut v : ~[u8] = ::cast::reinterpret_cast(&t);
blk += v; blk += v;

View file

@ -17,7 +17,7 @@ trait SendMap<K:Eq Hash, V: Copy> {
pure fn len(&const self) -> uint; pure fn len(&const self) -> uint;
pure fn is_empty(&const self) -> bool; pure fn is_empty(&const self) -> bool;
pure fn contains_key(&const self, k: &K) -> bool; pure fn contains_key(&const self, k: &K) -> bool;
pure fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool); pure fn each(&self, blk: fn(k: &K, v: &V) -> bool);
pure fn each_key_ref(&self, blk: fn(k: &K) -> bool); pure fn each_key_ref(&self, blk: fn(k: &K) -> bool);
pure fn each_value_ref(&self, blk: fn(v: &V) -> bool); pure fn each_value_ref(&self, blk: fn(v: &V) -> bool);
pure fn find(&const self, k: &K) -> Option<V>; pure fn find(&const self, k: &K) -> Option<V>;
@ -311,7 +311,7 @@ mod linear {
} }
} }
pure fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool) { pure fn each(&self, blk: fn(k: &K, v: &V) -> bool) {
for vec::each(self.buckets) |slot| { for vec::each(self.buckets) |slot| {
let mut broke = false; let mut broke = false;
do slot.iter |bucket| { do slot.iter |bucket| {
@ -323,12 +323,12 @@ mod linear {
} }
} }
pure fn each_key_ref(&self, blk: fn(k: &K) -> bool) { pure fn each_key(&self, blk: fn(k: &K) -> bool) {
self.each_ref(|k, _v| blk(k)) self.each(|k, _v| blk(k))
} }
pure fn each_value_ref(&self, blk: fn(v: &V) -> bool) { pure fn each_value(&self, blk: fn(v: &V) -> bool) {
self.each_ref(|_k, v| blk(v)) self.each(|_k, v| blk(v))
} }
} }
@ -358,22 +358,6 @@ mod linear {
} }
} }
impl<K: Hash IterBytes Eq Copy, V: Copy> LinearMap<K,V> {
pure fn each(&self, blk: fn(+K,+V) -> bool) {
self.each_ref(|k,v| blk(copy *k, copy *v));
}
}
impl<K: Hash IterBytes Eq Copy, V> LinearMap<K,V> {
pure fn each_key(&self, blk: fn(+K) -> bool) {
self.each_key_ref(|k| blk(copy *k));
}
}
impl<K: Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
pure fn each_value(&self, blk: fn(+V) -> bool) {
self.each_value_ref(|v| blk(copy *v));
}
}
} }
#[test] #[test]
@ -438,8 +422,8 @@ mod test {
} }
let mut observed = 0; let mut observed = 0;
for m.each |k, v| { for m.each |k, v| {
assert v == k*2; assert *v == *k * 2;
observed |= (1 << k); observed |= (1 << *k);
} }
assert observed == 0xFFFF_FFFF; assert observed == 0xFFFF_FFFF;
} }

View file

@ -72,12 +72,12 @@ export
map, map,
each, eachi, each, eachi,
each_char, each_chari, each_char, each_chari,
bytes_iter, bytes_each,
chars_iter, chars_each,
split_char_iter, split_char_each,
splitn_char_iter, splitn_char_each,
words_iter, words_each,
lines_iter, lines_each,
// Searching // Searching
find, find_from, find_between, find, find_from, find_between,
@ -235,7 +235,9 @@ pure fn from_chars(chs: &[char]) -> ~str {
let mut buf = ~""; let mut buf = ~"";
unsafe { unsafe {
reserve(buf, chs.len()); reserve(buf, chs.len());
for vec::each(chs) |ch| { push_char(buf, ch); } for vec::each(chs) |ch| {
push_char(buf, *ch);
}
} }
move buf move buf
} }
@ -289,7 +291,9 @@ pure fn append(+lhs: ~str, rhs: &str) -> ~str {
/// Concatenate a vector of strings /// Concatenate a vector of strings
pure fn concat(v: &[~str]) -> ~str { pure fn concat(v: &[~str]) -> ~str {
let mut s: ~str = ~""; let mut s: ~str = ~"";
for vec::each(v) |ss| { unsafe { push_str(s, ss) }; } for vec::each(v) |ss| {
unsafe { push_str(s, *ss) };
}
move s move s
} }
@ -298,7 +302,7 @@ pure fn connect(v: &[~str], sep: &str) -> ~str {
let mut s = ~"", first = true; let mut s = ~"", first = true;
for vec::each(v) |ss| { for vec::each(v) |ss| {
if first { first = false; } else { unsafe { push_str(s, sep); } } if first { first = false; } else { unsafe { push_str(s, sep); } }
unsafe { push_str(s, ss) }; unsafe { push_str(s, *ss) };
} }
move s move s
} }
@ -879,7 +883,7 @@ pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
let mut result = ~""; let mut result = ~"";
unsafe { unsafe {
reserve(result, len(ss)); reserve(result, len(ss));
do chars_iter(ss) |cc| { for chars_each(ss) |cc| {
str::push_char(result, ff(cc)); str::push_char(result, ff(cc));
} }
} }
@ -887,12 +891,12 @@ pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
} }
/// Iterate over the bytes in a string /// Iterate over the bytes in a string
pure fn bytes_iter(ss: &str, it: fn(u8)) { pure fn bytes_each(ss: &str, it: fn(u8) -> bool) {
let mut pos = 0u; let mut pos = 0u;
let len = len(ss); let len = len(ss);
while (pos < len) { while (pos < len) {
it(ss[pos]); if !it(ss[pos]) { return; }
pos += 1u; pos += 1u;
} }
} }
@ -933,40 +937,40 @@ pure fn each_chari(s: &str, it: fn(uint, char) -> bool) {
} }
/// Iterate over the characters in a string /// Iterate over the characters in a string
pure fn chars_iter(s: &str, it: fn(char)) { pure fn chars_each(s: &str, it: fn(char) -> bool) {
let mut pos = 0u; let mut pos = 0u;
let len = len(s); let len = len(s);
while (pos < len) { while (pos < len) {
let {ch, next} = char_range_at(s, pos); let {ch, next} = char_range_at(s, pos);
pos = next; pos = next;
it(ch); if !it(ch) { return; }
} }
} }
/// Apply a function to each substring after splitting by character /// Apply a function to each substring after splitting by character
pure fn split_char_iter(ss: &str, cc: char, ff: fn(&&~str)) { pure fn split_char_each(ss: &str, cc: char, ff: fn(v: &str) -> bool) {
vec::iter(split_char(ss, cc), ff) vec::each(split_char(ss, cc), |s| ff(*s))
} }
/** /**
* Apply a function to each substring after splitting by character, up to * Apply a function to each substring after splitting by character, up to
* `count` times * `count` times
*/ */
pure fn splitn_char_iter(ss: &str, sep: char, count: uint, pure fn splitn_char_each(ss: &str, sep: char, count: uint,
ff: fn(&&~str)) { ff: fn(v: &str) -> bool) {
vec::iter(splitn_char(ss, sep, count), ff) vec::each(splitn_char(ss, sep, count), |s| ff(*s))
} }
/// Apply a function to each word /// Apply a function to each word
pure fn words_iter(ss: &str, ff: fn(&&~str)) { pure fn words_each(ss: &str, ff: fn(v: &str) -> bool) {
vec::iter(words(ss), ff) vec::each(words(ss), |s| ff(*s))
} }
/** /**
* Apply a function to each line (by '\n') * Apply a function to each line (by '\n')
*/ */
pure fn lines_iter(ss: &str, ff: fn(&&~str)) { pure fn lines_each(ss: &str, ff: fn(v: &str) -> bool) {
vec::iter(lines(ss), ff) vec::each(lines(ss), |s| ff(*s))
} }
/* /*
@ -1518,7 +1522,7 @@ pure fn is_utf16(v: &[u16]) -> bool {
/// Converts to a vector of `u16` encoded as UTF-16 /// Converts to a vector of `u16` encoded as UTF-16
pure fn to_utf16(s: &str) -> ~[u16] { pure fn to_utf16(s: &str) -> ~[u16] {
let mut u = ~[]; let mut u = ~[];
do chars_iter(s) |cch| { for chars_each(s) |cch| {
// Arithmetic with u32 literals is easier on the eyes than chars. // Arithmetic with u32 literals is easier on the eyes than chars.
let mut ch = cch as u32; let mut ch = cch as u32;
@ -1947,7 +1951,9 @@ pure fn escape_default(s: &str) -> ~str {
let mut out: ~str = ~""; let mut out: ~str = ~"";
unsafe { unsafe {
reserve_at_least(out, str::len(s)); reserve_at_least(out, str::len(s));
chars_iter(s, |c| push_str(out, char::escape_default(c))); for chars_each(s) |c| {
push_str(out, char::escape_default(c));
}
} }
move out move out
} }
@ -1957,7 +1963,9 @@ pure fn escape_unicode(s: &str) -> ~str {
let mut out: ~str = ~""; let mut out: ~str = ~"";
unsafe { unsafe {
reserve_at_least(out, str::len(s)); reserve_at_least(out, str::len(s));
chars_iter(s, |c| push_str(out, char::escape_unicode(c))); for chars_each(s) |c| {
push_str(out, char::escape_unicode(c));
}
} }
move out move out
} }
@ -2094,7 +2102,7 @@ mod raw {
/// Appends a vector of bytes to a string. (Not UTF-8 safe). /// Appends a vector of bytes to a string. (Not UTF-8 safe).
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) { unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
reserve_at_least(s, s.len() + bytes.len()); reserve_at_least(s, s.len() + bytes.len());
for vec::each(bytes) |byte| { push_byte(s, byte); } for vec::each(bytes) |byte| { push_byte(s, *byte); }
} }
/// Removes the last byte from a string and returns it. (Not UTF-8 safe). /// Removes the last byte from a string and returns it. (Not UTF-8 safe).
@ -3044,50 +3052,52 @@ mod tests {
} }
#[test] #[test]
fn test_chars_iter() { fn test_chars_each() {
let mut i = 0; let mut i = 0;
do chars_iter(~"x\u03c0y") |ch| { for chars_each(~"x\u03c0y") |ch| {
match i { match i {
0 => assert ch == 'x', 0 => assert ch == 'x',
1 => assert ch == '\u03c0', 1 => assert ch == '\u03c0',
2 => assert ch == 'y', 2 => assert ch == 'y',
_ => fail ~"test_chars_iter failed" _ => fail ~"test_chars_each failed"
} }
i += 1; i += 1;
} }
chars_iter(~"", |_ch| fail ); // should not fail chars_each(~"", |_ch| fail ); // should not fail
} }
#[test] #[test]
fn test_bytes_iter() { fn test_bytes_each() {
let mut i = 0; let mut i = 0;
do bytes_iter(~"xyz") |bb| { for bytes_each(~"xyz") |bb| {
match i { match i {
0 => assert bb == 'x' as u8, 0 => assert bb == 'x' as u8,
1 => assert bb == 'y' as u8, 1 => assert bb == 'y' as u8,
2 => assert bb == 'z' as u8, 2 => assert bb == 'z' as u8,
_ => fail ~"test_bytes_iter failed" _ => fail ~"test_bytes_each failed"
} }
i += 1; i += 1;
} }
bytes_iter(~"", |bb| assert bb == 0u8); for bytes_each(~"") |bb| {
assert bb == 0u8;
}
} }
#[test] #[test]
fn test_split_char_iter() { fn test_split_char_each() {
let data = ~"\nMary had a little lamb\nLittle lamb\n"; let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0; let mut ii = 0;
do split_char_iter(data, ' ') |xx| { for split_char_each(data, ' ') |xx| {
match ii { match ii {
0 => assert ~"\nMary" == xx, 0 => assert "\nMary" == xx,
1 => assert ~"had" == xx, 1 => assert "had" == xx,
2 => assert ~"a" == xx, 2 => assert "a" == xx,
3 => assert ~"little" == xx, 3 => assert "little" == xx,
_ => () _ => ()
} }
ii += 1; ii += 1;
@ -3095,16 +3105,16 @@ mod tests {
} }
#[test] #[test]
fn test_splitn_char_iter() { fn test_splitn_char_each() {
let data = ~"\nMary had a little lamb\nLittle lamb\n"; let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0; let mut ii = 0;
do splitn_char_iter(data, ' ', 2u) |xx| { for splitn_char_each(data, ' ', 2u) |xx| {
match ii { match ii {
0 => assert ~"\nMary" == xx, 0 => assert "\nMary" == xx,
1 => assert ~"had" == xx, 1 => assert "had" == xx,
2 => assert ~"a little lamb\nLittle lamb\n" == xx, 2 => assert "a little lamb\nLittle lamb\n" == xx,
_ => () _ => ()
} }
ii += 1; ii += 1;
@ -3112,37 +3122,37 @@ mod tests {
} }
#[test] #[test]
fn test_words_iter() { fn test_words_each() {
let data = ~"\nMary had a little lamb\nLittle lamb\n"; let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0; let mut ii = 0;
do words_iter(data) |ww| { for words_each(data) |ww| {
match ii { match ii {
0 => assert ~"Mary" == ww, 0 => assert "Mary" == ww,
1 => assert ~"had" == ww, 1 => assert "had" == ww,
2 => assert ~"a" == ww, 2 => assert "a" == ww,
3 => assert ~"little" == ww, 3 => assert "little" == ww,
_ => () _ => ()
} }
ii += 1; ii += 1;
} }
words_iter(~"", |_x| fail); // should not fail words_each(~"", |_x| fail); // should not fail
} }
#[test] #[test]
fn test_lines_iter () { fn test_lines_each () {
let lf = ~"\nMary had a little lamb\nLittle lamb\n"; let lf = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0; let mut ii = 0;
do lines_iter(lf) |x| { for lines_each(lf) |x| {
match ii { match ii {
0 => assert ~"" == x, 0 => assert "" == x,
1 => assert ~"Mary had a little lamb" == x, 1 => assert "Mary had a little lamb" == x,
2 => assert ~"Little lamb" == x, 2 => assert "Little lamb" == x,
3 => assert ~"" == x, 3 => assert "" == x,
_ => () _ => ()
} }
ii += 1; ii += 1;
@ -3221,7 +3231,7 @@ mod tests {
0x000a_u16 ]) ]; 0x000a_u16 ]) ];
for vec::each(pairs) |p| { for vec::each(pairs) |p| {
let (s, u) = copy p; let (s, u) = copy *p;
assert to_utf16(s) == u; assert to_utf16(s) == u;
assert from_utf16(u) == s; assert from_utf16(u) == s;
assert from_utf16(to_utf16(s)) == s; assert from_utf16(to_utf16(s)) == s;

View file

@ -888,7 +888,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
assert was_present; assert was_present;
} }
fn taskset_each(tasks: &TaskSet, blk: fn(+*rust_task) -> bool) { fn taskset_each(tasks: &TaskSet, blk: fn(+*rust_task) -> bool) {
tasks.each_key(blk) tasks.each_key(|k| blk(*k))
} }
// One of these per group of linked-failure tasks. // One of these per group of linked-failure tasks.

View file

@ -76,12 +76,8 @@ export zip, zip_slice;
export swap; export swap;
export reverse; export reverse;
export reversed; export reversed;
export iter, iter_between, each, eachi, reach, reachi; export each, each_mut, each_const, eachi, reach, reachi;
export each_ref, each_mut_ref, each_const_ref;
export iter2; export iter2;
export iteri;
export riter;
export riteri;
export permute; export permute;
export windowed; export windowed;
export as_imm_buf; export as_imm_buf;
@ -755,7 +751,7 @@ fn grow_set<T: Copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> ~[U] { pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> ~[U] {
let mut result = ~[]; let mut result = ~[];
unsafe{reserve(result, len(v));} unsafe{reserve(result, len(v));}
for each(v) |elem| { unsafe { push(result, f(elem)); } } for each(v) |elem| { unsafe { push(result, f(*elem)); } }
move result move result
} }
@ -781,7 +777,7 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] {
*/ */
pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] { pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
let mut result = ~[]; let mut result = ~[];
for each(v) |elem| { unsafe{ push_all_move(result, f(elem)); } } for each(v) |elem| { unsafe{ push_all_move(result, f(*elem)); } }
move result move result
} }
@ -809,7 +805,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
-> ~[U] { -> ~[U] {
let mut result = ~[]; let mut result = ~[];
for each(v) |elem| { for each(v) |elem| {
match f(elem) { match f(*elem) {
None => {/* no-op */ } None => {/* no-op */ }
Some(result_elem) => unsafe { push(result, result_elem); } Some(result_elem) => unsafe { push(result, result_elem); }
} }
@ -827,7 +823,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] { pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
let mut result = ~[]; let mut result = ~[];
for each(v) |elem| { for each(v) |elem| {
if f(elem) { unsafe { push(result, elem); } } if f(*elem) { unsafe { push(result, *elem); } }
} }
move result move result
} }
@ -839,7 +835,7 @@ pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
*/ */
pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] { pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] {
let mut r = ~[]; let mut r = ~[];
for each(v) |inner| { unsafe { push_all(r, inner); } } for each(v) |inner| { unsafe { push_all(r, *inner); } }
move r move r
} }
@ -849,7 +845,7 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
let mut first = true; let mut first = true;
for each(v) |inner| { for each(v) |inner| {
if first { first = false; } else { unsafe { push(r, sep); } } if first { first = false; } else { unsafe { push(r, sep); } }
unsafe { push_all(r, inner) }; unsafe { push_all(r, *inner) };
} }
move r move r
} }
@ -857,8 +853,8 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
/// Reduce a vector from left to right /// Reduce a vector from left to right
pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T { pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
let mut accum = z; let mut accum = z;
do iter(v) |elt| { for each(v) |elt| {
accum = p(accum, elt); accum = p(accum, *elt);
} }
return accum; return accum;
} }
@ -866,7 +862,7 @@ pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
/// Reduce a vector from right to left /// Reduce a vector from right to left
pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U { pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
let mut accum = z; let mut accum = z;
do riter(v) |elt| { for reach(v) |elt| {
accum = p(elt, accum); accum = p(elt, accum);
} }
return accum; return accum;
@ -878,7 +874,7 @@ pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
* If the vector contains no elements then false is returned. * If the vector contains no elements then false is returned.
*/ */
pure fn any<T>(v: &[T], f: fn(T) -> bool) -> bool { pure fn any<T>(v: &[T], f: fn(T) -> bool) -> bool {
for each(v) |elem| { if f(elem) { return true; } } for each(v) |elem| { if f(*elem) { return true; } }
return false; return false;
} }
@ -905,7 +901,7 @@ pure fn any2<T, U>(v0: &[T], v1: &[U],
* If the vector contains no elements then true is returned. * If the vector contains no elements then true is returned.
*/ */
pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool { pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool {
for each(v) |elem| { if !f(elem) { return false; } } for each(v) |elem| { if !f(*elem) { return false; } }
return true; return true;
} }
@ -935,14 +931,14 @@ pure fn all2<T, U>(v0: &[T], v1: &[U],
/// Return true if a vector contains an element with the given value /// Return true if a vector contains an element with the given value
pure fn contains<T: Eq>(v: &[T], x: T) -> bool { pure fn contains<T: Eq>(v: &[T], x: T) -> bool {
for each(v) |elt| { if x == elt { return true; } } for each(v) |elt| { if x == *elt { return true; } }
return false; return false;
} }
/// Returns the number of elements that are equal to a given value /// Returns the number of elements that are equal to a given value
pure fn count<T: Eq>(v: &[T], x: T) -> uint { pure fn count<T: Eq>(v: &[T], x: T) -> uint {
let mut cnt = 0u; let mut cnt = 0u;
for each(v) |elt| { if x == elt { cnt += 1u; } } for each(v) |elt| { if x == *elt { cnt += 1u; } }
return cnt; return cnt;
} }
@ -1070,7 +1066,7 @@ pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) { pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
let mut as_ = ~[], bs = ~[]; let mut as_ = ~[], bs = ~[];
for each(v) |p| { for each(v) |p| {
let (a, b) = p; let (a, b) = *p;
unsafe { unsafe {
vec::push(as_, a); vec::push(as_, a);
vec::push(bs, b); vec::push(bs, b);
@ -1150,7 +1146,6 @@ fn reverse<T>(v: &[mut T]) {
while i < ln / 2u { v[i] <-> v[ln - i - 1u]; i += 1u; } while i < ln / 2u { v[i] <-> v[ln - i - 1u]; i += 1u; }
} }
/// Returns a vector with the order of elements reversed /// Returns a vector with the order of elements reversed
pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] { pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
let mut rs: ~[T] = ~[]; let mut rs: ~[T] = ~[];
@ -1163,50 +1158,13 @@ pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
move rs move rs
} }
/**
* Iterates over a slice
*
* Iterates over slice `v` and, for each element, calls function `f` with the
* element's value.
*/
#[inline(always)]
pure fn iter<T>(v: &[T], f: fn(T)) {
iter_between(v, 0u, vec::len(v), f)
}
/*
Function: iter_between
Iterates over a slice
Iterates over slice `v` and, for each element, calls function `f` with the
element's value.
*/
#[inline(always)]
pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) {
do as_imm_buf(v) |base_ptr, len| {
assert start <= end;
assert end <= len;
unsafe {
let mut n = end;
let mut p = ptr::offset(base_ptr, start);
while n > start {
f(*p);
p = ptr::offset(p, 1u);
n -= 1u;
}
}
}
}
/** /**
* Iterates over a vector, with option to break * Iterates over a vector, with option to break
* *
* Return true to continue, false to break. * Return true to continue, false to break.
*/ */
#[inline(always)] #[inline(always)]
pure fn each<T>(v: &[T], f: fn(T) -> bool) { pure fn each<T>(v: &r/[T], f: fn((&r/T)) -> bool) {
// ^^^^ // ^^^^
// NB---this CANNOT be &[const T]! The reason // NB---this CANNOT be &[const T]! The reason
// is that you are passing it to `f()` using // is that you are passing it to `f()` using
@ -1217,7 +1175,8 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) {
let mut p = p; let mut p = p;
while n > 0u { while n > 0u {
unsafe { unsafe {
if !f(*p) { break; } let q = cast::copy_lifetime_vec(v, &*p);
if !f(q) { break; }
p = ptr::offset(p, 1u); p = ptr::offset(p, 1u);
} }
n -= 1u; n -= 1u;
@ -1225,30 +1184,11 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) {
} }
} }
/**
* Iterates over a vector, with option to break
*
* Return true to continue, false to break.
*/
#[inline(always)]
pure fn each_ref<T>(v: &r/[T], f: fn(v: &r/T) -> bool) {
// this is not the most efficient impl, as it repeats the bound checks,
// but it's good enough
let mut i = 0;
let n = v.len();
while i < n {
if !f(&v[i]) {
return;
}
i += 1;
}
}
/// Like `each()`, but for the case where you have /// Like `each()`, but for the case where you have
/// a vector with mutable contents and you would like /// a vector with mutable contents and you would like
/// to mutate the contents as you iterate. /// to mutate the contents as you iterate.
#[inline(always)] #[inline(always)]
fn each_mut_ref<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) { fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
let mut i = 0; let mut i = 0;
let n = v.len(); let n = v.len();
while i < n { while i < n {
@ -1262,7 +1202,7 @@ fn each_mut_ref<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
/// Like `each()`, but for the case where you have a vector that *may or may /// Like `each()`, but for the case where you have a vector that *may or may
/// not* have mutable contents. /// not* have mutable contents.
#[inline(always)] #[inline(always)]
pure fn each_const_ref<T>(v: &[const T], f: fn(elem: &const T) -> bool) { pure fn each_const<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
let mut i = 0; let mut i = 0;
let n = v.len(); let n = v.len();
while i < n { while i < n {
@ -1344,43 +1284,6 @@ fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(U, T)) {
} }
} }
/**
* Iterates over a vector's elements and indexes
*
* Iterates over vector `v` and, for each element, calls function `f` with the
* element's value and index.
*/
#[inline(always)]
pure fn iteri<T>(v: &[T], f: fn(uint, T)) {
let mut i = 0u;
let l = len(v);
while i < l { f(i, v[i]); i += 1u; }
}
/**
* Iterates over a vector in reverse
*
* Iterates over vector `v` and, for each element, calls function `f` with the
* element's value.
*/
pure fn riter<T>(v: &[T], f: fn(T)) {
riteri(v, |_i, v| f(v))
}
/**
* Iterates over a vector's elements and indexes in reverse
*
* Iterates over vector `v` and, for each element, calls function `f` with the
* element's value and index.
*/
pure fn riteri<T>(v: &[T], f: fn(uint, T)) {
let mut i = len(v);
while 0u < i {
i -= 1u;
f(i, v[i]);
};
}
/** /**
* Iterate over all permutations of vector `v`. * Iterate over all permutations of vector `v`.
* *
@ -1414,12 +1317,12 @@ pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) {
pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] { pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
let mut ww = ~[]; let mut ww = ~[];
assert 1u <= nn; assert 1u <= nn;
vec::iteri (xx, |ii, _x| { for vec::eachi (xx) |ii, _x| {
let len = vec::len(xx); let len = vec::len(xx);
if ii+nn <= len unsafe { if ii+nn <= len unsafe {
vec::push(ww, vec::slice(xx, ii, ii+nn)); vec::push(ww, vec::slice(xx, ii, ii+nn));
} }
}); }
move ww move ww
} }
@ -1626,10 +1529,6 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
trait ImmutableVector<T> { trait ImmutableVector<T> {
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U; pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
pure fn iter(f: fn(T));
pure fn iteri(f: fn(uint, T));
pure fn riter(f: fn(T));
pure fn riteri(f: fn(uint, T));
pure fn map<U>(f: fn(T) -> U) -> ~[U]; pure fn map<U>(f: fn(T) -> U) -> ~[U];
pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U]; pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U];
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U]; fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
@ -1650,38 +1549,6 @@ impl<T> &[T]: ImmutableVector<T> {
/// Reduce a vector from right to left /// Reduce a vector from right to left
#[inline] #[inline]
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) } pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
/**
* Iterates over a vector
*
* Iterates over vector `v` and, for each element, calls function `f` with
* the element's value.
*/
#[inline]
pure fn iter(f: fn(T)) { iter(self, f) }
/**
* Iterates over a vector's elements and indexes
*
* Iterates over vector `v` and, for each element, calls function `f` with
* the element's value and index.
*/
#[inline]
pure fn iteri(f: fn(uint, T)) { iteri(self, f) }
/**
* Iterates over a vector in reverse
*
* Iterates over vector `v` and, for each element, calls function `f` with
* the element's value.
*/
#[inline]
pure fn riter(f: fn(T)) { riter(self, f) }
/**
* Iterates over a vector's elements and indexes in reverse
*
* Iterates over vector `v` and, for each element, calls function `f` with
* the element's value and index.
*/
#[inline]
pure fn riteri(f: fn(uint, T)) { riteri(self, f) }
/// Apply a function to each element of a vector and return the results /// Apply a function to each element of a vector and return the results
#[inline] #[inline]
pure fn map<U>(f: fn(T) -> U) -> ~[U] { map(self, f) } pure fn map<U>(f: fn(T) -> U) -> ~[U] { map(self, f) }
@ -2013,7 +1880,13 @@ mod bytes {
// required in the slice. // required in the slice.
impl<A> &[A]: iter::BaseIter<A> { impl<A> &[A]: iter::BaseIter<A> {
pure fn each(blk: fn(A) -> bool) { each(self, blk) } pure fn each(blk: fn(A) -> bool) {
for each(self) |e| {
if (!blk(*e)) {
return;
}
}
}
pure fn size_hint() -> Option<uint> { Some(len(self)) } pure fn size_hint() -> Option<uint> { Some(len(self)) }
} }
@ -2465,55 +2338,57 @@ mod tests {
} }
#[test] #[test]
fn test_iter_empty() { fn test_each_empty() {
let mut i = 0; for each::<int>(~[]) |_v| {
iter::<int>(~[], |_v| i += 1); fail; // should never be executed
assert i == 0; }
} }
#[test] #[test]
fn test_iter_nonempty() { fn test_iter_nonempty() {
let mut i = 0; let mut i = 0;
iter(~[1, 2, 3], |v| i += v); for each(~[1, 2, 3]) |v| {
i += *v;
}
assert i == 6; assert i == 6;
} }
#[test] #[test]
fn test_iteri() { fn test_iteri() {
let mut i = 0; let mut i = 0;
iteri(~[1, 2, 3], |j, v| { for eachi(~[1, 2, 3]) |j, v| {
if i == 0 { assert v == 1; } if i == 0 { assert v == 1; }
assert j + 1u == v as uint; assert j + 1u == v as uint;
i += v; i += v;
}); }
assert i == 6; assert i == 6;
} }
#[test] #[test]
fn test_riter_empty() { fn test_reach_empty() {
let mut i = 0; for reach::<int>(~[]) |_v| {
riter::<int>(~[], |_v| i += 1); fail; // should never execute
assert i == 0; }
} }
#[test] #[test]
fn test_riter_nonempty() { fn test_riter_nonempty() {
let mut i = 0; let mut i = 0;
riter(~[1, 2, 3], |v| { for reach(~[1, 2, 3]) |v| {
if i == 0 { assert v == 3; } if i == 0 { assert v == 3; }
i += v i += v
}); }
assert i == 6; assert i == 6;
} }
#[test] #[test]
fn test_riteri() { fn test_reachi() {
let mut i = 0; let mut i = 0;
riteri(~[0, 1, 2], |j, v| { for reachi(~[0, 1, 2]) |j, v| {
if i == 0 { assert v == 2; } if i == 0 { assert v == 2; }
assert j == v as uint; assert j == v as uint;
i += v; i += v;
}); }
assert i == 3; assert i == 3;
} }

View file

@ -642,6 +642,7 @@ mod tests {
c.send(()); c.send(());
} }
} }
// Readers try to catch the writer in the act // Readers try to catch the writer in the act
let mut children = ~[]; let mut children = ~[];
for 5.times { for 5.times {
@ -652,8 +653,10 @@ mod tests {
} }
} }
} }
// Wait for children to pass their asserts // Wait for children to pass their asserts
for vec::each(children) |r| { future::get(&r); } for vec::each(children) |r| { future::get(r); }
// Wait for writer to finish // Wait for writer to finish
p.recv(); p.recv();
do arc.read |num| { assert *num == 10; } do arc.read |num| { assert *num == 10; }
@ -714,7 +717,7 @@ mod tests {
*state = 31337; *state = 31337;
// send to other readers // send to other readers
for vec::each(reader_convos) |x| { for vec::each(reader_convos) |x| {
match x { match *x {
(rc, _) => rc.send(()), (rc, _) => rc.send(()),
} }
} }
@ -723,7 +726,7 @@ mod tests {
do (&read_mode).read |state| { do (&read_mode).read |state| {
// complete handshake with other readers // complete handshake with other readers
for vec::each(reader_convos) |x| { for vec::each(reader_convos) |x| {
match x { match *x {
(_, rp) => rp.recv(), (_, rp) => rp.recv(),
} }
} }

View file

@ -294,14 +294,14 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
let mut name_pos = 0u; let mut name_pos = 0u;
for vec::each(names) |nm| { for vec::each(names) |nm| {
name_pos += 1u; name_pos += 1u;
let optid = match find_opt(opts, nm) { let optid = match find_opt(opts, *nm) {
Some(id) => id, Some(id) => id,
None => return Err(UnrecognizedOption(name_str(&nm))) None => return Err(UnrecognizedOption(name_str(nm)))
}; };
match opts[optid].hasarg { match opts[optid].hasarg {
No => { No => {
if !option::is_none::<~str>(i_arg) { if !option::is_none::<~str>(i_arg) {
return Err(UnexpectedArgument(name_str(&nm))); return Err(UnexpectedArgument(name_str(nm)));
} }
vec::push(vals[optid], Given); vec::push(vals[optid], Given);
} }
@ -318,7 +318,7 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
vec::push(vals[optid], vec::push(vals[optid],
Val(option::get::<~str>(i_arg))); Val(option::get::<~str>(i_arg)));
} else if i + 1u == l { } else if i + 1u == l {
return Err(ArgumentMissing(name_str(&nm))); return Err(ArgumentMissing(name_str(nm)));
} else { i += 1u; vec::push(vals[optid], Val(args[i])); } } else { i += 1u; vec::push(vals[optid], Val(args[i])); }
} }
} }
@ -367,7 +367,7 @@ fn opt_present(+mm: Matches, nm: &str) -> bool {
/// Returns true if any of several options were matched /// Returns true if any of several options were matched
fn opts_present(+mm: Matches, names: &[~str]) -> bool { fn opts_present(+mm: Matches, names: &[~str]) -> bool {
for vec::each(names) |nm| { for vec::each(names) |nm| {
match find_opt(mm.opts, mkname(nm)) { match find_opt(mm.opts, mkname(*nm)) {
Some(_) => return true, Some(_) => return true,
None => () None => ()
} }
@ -394,7 +394,7 @@ fn opt_str(+mm: Matches, nm: &str) -> ~str {
*/ */
fn opts_str(+mm: Matches, names: &[~str]) -> ~str { fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
for vec::each(names) |nm| { for vec::each(names) |nm| {
match opt_val(mm, nm) { match opt_val(mm, *nm) {
Val(s) => return s, Val(s) => return s,
_ => () _ => ()
} }
@ -412,7 +412,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[]; let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(mm, nm)) |v| { for vec::each(opt_vals(mm, nm)) |v| {
match v { Val(s) => vec::push(acc, s), _ => () } match *v { Val(s) => vec::push(acc, s), _ => () }
} }
return acc; return acc;
} }

View file

@ -179,7 +179,7 @@ fn to_writer_pretty(wr: io::Writer, j: Json, indent: uint) {
fn escape_str(s: &str) -> ~str { fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\""; let mut escaped = ~"\"";
do str::chars_iter(s) |c| { for str::chars_each(s) |c| {
match c { match c {
'"' => escaped += ~"\\\"", '"' => escaped += ~"\\\"",
'\\' => escaped += ~"\\\\", '\\' => escaped += ~"\\\\",
@ -834,8 +834,8 @@ mod tests {
fn mk_dict(items: &[(~str, Json)]) -> Json { fn mk_dict(items: &[(~str, Json)]) -> Json {
let d = map::str_hash(); let d = map::str_hash();
do vec::iter(items) |item| { for vec::each(items) |item| {
let (key, value) = copy item; let (key, value) = copy *item;
d.insert(key, value); d.insert(key, value);
}; };

View file

@ -435,10 +435,13 @@ fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>( fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
items: &[(K, V)]) -> HashMap<K, V> { items: &[(K, V)]) -> HashMap<K, V> {
let map = HashMap(); let map = HashMap();
do vec::iter(items) |item| { for vec::each(items) |item| {
let (key, value) = item; match *item {
(key, value) => {
map.insert(key, value); map.insert(key, value);
} }
}
}
map map
} }
@ -520,7 +523,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each(op: fn(+key: K, +value: V) -> bool) { pure fn each(op: fn(+key: K, +value: V) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each(op) p.each(|k, v| op(*k, *v))
} }
} }
} }
@ -528,7 +531,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each_key(op: fn(+key: K) -> bool) { pure fn each_key(op: fn(+key: K) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each_key(op) p.each_key(|k| op(*k))
} }
} }
} }
@ -536,7 +539,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each_value(op: fn(+value: V) -> bool) { pure fn each_value(op: fn(+value: V) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each_value(op) p.each_value(|v| op(*v))
} }
} }
} }
@ -544,7 +547,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each_ref(op: fn(key: &K, value: &V) -> bool) { pure fn each_ref(op: fn(key: &K, value: &V) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each_ref(op) p.each(op)
} }
} }
} }
@ -552,7 +555,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each_key_ref(op: fn(key: &K) -> bool) { pure fn each_key_ref(op: fn(key: &K) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each_key_ref(op) p.each_key(op)
} }
} }
} }
@ -560,7 +563,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
pure fn each_value_ref(op: fn(value: &V) -> bool) { pure fn each_value_ref(op: fn(value: &V) -> bool) {
unsafe { unsafe {
do self.borrow_imm |p| { do self.borrow_imm |p| {
p.each_value_ref(op) p.each_value(op)
} }
} }
} }

View file

@ -364,12 +364,12 @@ mod test {
log(debug, fmt!("test_get_addr: Number of results for %s: %?", log(debug, fmt!("test_get_addr: Number of results for %s: %?",
localhost_name, vec::len(results))); localhost_name, vec::len(results)));
for vec::each(results) |r| { for vec::each(results) |r| {
let ipv_prefix = match r { let ipv_prefix = match *r {
Ipv4(_) => ~"IPv4", Ipv4(_) => ~"IPv4",
Ipv6(_) => ~"IPv6" Ipv6(_) => ~"IPv6"
}; };
log(debug, fmt!("test_get_addr: result %s: '%s'", log(debug, fmt!("test_get_addr: result %s: '%s'",
ipv_prefix, format_addr(&r))); ipv_prefix, format_addr(r)));
} }
// at least one result.. this is going to vary from system // at least one result.. this is going to vary from system
// to system, based on stuff like the contents of /etc/hosts // to system, based on stuff like the contents of /etc/hosts

View file

@ -91,7 +91,7 @@ trait Deserializer {
fn emit_from_vec<S: Serializer, T>(s: S, v: ~[T], f: fn(T)) { fn emit_from_vec<S: Serializer, T>(s: S, v: ~[T], f: fn(T)) {
do s.emit_vec(vec::len(v)) { do s.emit_vec(vec::len(v)) {
do vec::iteri(v) |i,e| { for vec::eachi(v) |i,e| {
do s.emit_vec_elt(i) { do s.emit_vec_elt(i) {
f(e) f(e)
} }

View file

@ -66,7 +66,7 @@ fn sha1() -> Sha1 {
fn add_input(st: &Sha1State, msg: &[u8]) { fn add_input(st: &Sha1State, msg: &[u8]) {
assert (!st.computed); assert (!st.computed);
for vec::each(msg) |element| { for vec::each(msg) |element| {
st.msg_block[st.msg_block_idx] = element; st.msg_block[st.msg_block_idx] = *element;
st.msg_block_idx += 1u; st.msg_block_idx += 1u;
st.len_low += 8u32; st.len_low += 8u32;
if st.len_low == 0u32 { if st.len_low == 0u32 {
@ -161,7 +161,7 @@ fn sha1() -> Sha1 {
fn mk_result(st: &Sha1State) -> ~[u8] { fn mk_result(st: &Sha1State) -> ~[u8] {
if !(*st).computed { pad_msg(st); (*st).computed = true; } if !(*st).computed { pad_msg(st); (*st).computed = true; }
let mut rs: ~[u8] = ~[]; let mut rs: ~[u8] = ~[];
for vec::each_mut_ref((*st).h) |ptr_hpart| { for vec::each_mut((*st).h) |ptr_hpart| {
let hpart = *ptr_hpart; let hpart = *ptr_hpart;
let a = (hpart >> 24u32 & 0xFFu32) as u8; let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8; let b = (hpart >> 16u32 & 0xFFu32) as u8;
@ -240,7 +240,9 @@ fn sha1() -> Sha1 {
fn result_str() -> ~str { fn result_str() -> ~str {
let rr = mk_result(&self); let rr = mk_result(&self);
let mut s = ~""; let mut s = ~"";
for vec::each(rr) |b| { s += uint::to_str(b as uint, 16u); } for vec::each(rr) |b| {
s += uint::to_str(*b as uint, 16u);
}
return s; return s;
} }
} }

View file

@ -103,21 +103,15 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
fn get(+key: uint) -> V { get(self, key) } fn get(+key: uint) -> V { get(self, key) }
pure fn find(+key: uint) -> Option<V> { find(self, key) } pure fn find(+key: uint) -> Option<V> { find(self, key) }
fn rehash() { fail } fn rehash() { fail }
pure fn each(it: fn(+key: uint, +value: V) -> bool) { pure fn each(it: fn(+key: uint, +value: V) -> bool) {
let mut idx = 0u, l = self.v.len(); self.each_ref(|k, v| it(*k, *v))
while idx < l {
match self.v.get_elt(idx) {
Some(elt) => if !it(idx, elt) { break },
None => ()
}
idx += 1u;
}
} }
pure fn each_key(it: fn(+key: uint) -> bool) { pure fn each_key(it: fn(+key: uint) -> bool) {
self.each(|k, _v| it(k)) self.each_ref(|k, _v| it(*k))
} }
pure fn each_value(it: fn(+value: V) -> bool) { pure fn each_value(it: fn(+value: V) -> bool) {
self.each(|_k, v| it(v)) self.each_ref(|_k, v| it(*v))
} }
pure fn each_ref(it: fn(key: &uint, value: &V) -> bool) { pure fn each_ref(it: fn(key: &uint, value: &V) -> bool) {
let mut idx = 0u, l = self.v.len(); let mut idx = 0u, l = self.v.len();

View file

@ -260,7 +260,7 @@ mod test_qsort {
let pairs = vec::zip(expected, immut_names); let pairs = vec::zip(expected, immut_names);
for vec::each(pairs) |p| { for vec::each(pairs) |p| {
let (a, b) = p; let (a, b) = *p;
debug!("%d %d", a, b); debug!("%d %d", a, b);
assert (a == b); assert (a == b);
} }

View file

@ -40,7 +40,7 @@ fn color_supported() -> bool {
return match os::getenv(~"TERM") { return match os::getenv(~"TERM") {
option::Some(env) => { option::Some(env) => {
for vec::each(supported_terms) |term| { for vec::each(supported_terms) |term| {
if term == env { return true; } if *term == env { return true; }
} }
false false
} }

View file

@ -227,7 +227,7 @@ fn print_failures(st: ConsoleTestState) {
let failures = vec::map(failures, |test| test.name); let failures = vec::map(failures, |test| test.name);
let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures); let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures);
for vec::each(failures) |name| { for vec::each(failures) |name| {
st.out.write_line(fmt!(" %s", name)); st.out.write_line(fmt!(" %s", *name));
} }
} }
@ -538,9 +538,9 @@ mod tests {
let testfn = fn~() { }; let testfn = fn~() { };
let mut tests = ~[]; let mut tests = ~[];
for vec::each(names) |name| { for vec::each(names) |name| {
let test = {name: name, testfn: copy testfn, ignore: false, let test = {name: *name, testfn: copy testfn, ignore: false,
should_fail: false}; should_fail: false};
tests += ~[test]; vec::push(tests, test);
} }
tests tests
}; };
@ -557,7 +557,11 @@ mod tests {
let pairs = vec::zip(expected, filtered); let pairs = vec::zip(expected, filtered);
for vec::each(pairs) |p| { let (a, b) = copy p; assert (a == b.name); } for vec::each(pairs) |p| {
match *p {
(a, b) => { assert (a == b.name); }
}
}
} }
} }

View file

@ -1023,7 +1023,7 @@ mod tests {
} }
} }
[ for vec::each([
~"Sunday", ~"Sunday",
~"Monday", ~"Monday",
~"Tuesday", ~"Tuesday",
@ -1031,9 +1031,11 @@ mod tests {
~"Thursday", ~"Thursday",
~"Friday", ~"Friday",
~"Saturday" ~"Saturday"
]/_.iter(|day| assert test(day, ~"%A")); ]) |day| {
assert test(*day, ~"%A");
}
[ for vec::each([
~"Sun", ~"Sun",
~"Mon", ~"Mon",
~"Tue", ~"Tue",
@ -1041,9 +1043,11 @@ mod tests {
~"Thu", ~"Thu",
~"Fri", ~"Fri",
~"Sat" ~"Sat"
]/_.iter(|day| assert test(day, ~"%a")); ]) |day| {
assert test(*day, ~"%a");
}
[ for vec::each([
~"January", ~"January",
~"February", ~"February",
~"March", ~"March",
@ -1056,9 +1060,11 @@ mod tests {
~"October", ~"October",
~"November", ~"November",
~"December" ~"December"
]/_.iter(|day| assert test(day, ~"%B")); ]) |day| {
assert test(*day, ~"%B");
}
[ for vec::each([
~"Jan", ~"Jan",
~"Feb", ~"Feb",
~"Mar", ~"Mar",
@ -1071,7 +1077,9 @@ mod tests {
~"Oct", ~"Oct",
~"Nov", ~"Nov",
~"Dec" ~"Dec"
]/_.iter(|day| assert test(day, ~"%b")); ]) |day| {
assert test(*day, ~"%b");
}
assert test(~"19", ~"%C"); assert test(~"19", ~"%C");
assert test(~"Fri Feb 13 23:31:30 2009", ~"%c"); assert test(~"Fri Feb 13 23:31:30 2009", ~"%c");

View file

@ -294,7 +294,9 @@ fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node,
let d_id = ast_util::local_def(id); let d_id = ast_util::local_def(id);
let p = extend(cx, ident); let p = extend(cx, ident);
// only need to handle methods // only need to handle methods
do vec::iter(struct_def.methods) |m| { map_method(d_id, p, m, cx); } for vec::each(struct_def.methods) |m| {
map_method(d_id, p, *m, cx);
}
} }
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {

View file

@ -429,7 +429,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
match vi.node { match vi.node {
view_item_use(_, _, id) => vfn(id), view_item_use(_, _, id) => vfn(id),
view_item_import(vps) | view_item_export(vps) => { view_item_import(vps) | view_item_export(vps) => {
do vec::iter(vps) |vp| { for vec::each(vps) |vp| {
match vp.node { match vp.node {
view_path_simple(_, _, _, id) => vfn(id), view_path_simple(_, _, _, id) => vfn(id),
view_path_glob(_, id) => vfn(id), view_path_glob(_, id) => vfn(id),
@ -490,7 +490,9 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
}, },
visit_ty_params: fn@(ps: ~[ty_param]) { visit_ty_params: fn@(ps: ~[ty_param]) {
vec::iter(ps, |p| vfn(p.id)) for vec::each(ps) |p| {
vfn(p.id);
}
}, },
visit_fn: fn@(fk: visit::fn_kind, d: ast::fn_decl, visit_fn: fn@(fk: visit::fn_kind, d: ast::fn_decl,
@ -499,33 +501,33 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
match fk { match fk {
visit::fk_ctor(_, _, tps, self_id, parent_id) => { visit::fk_ctor(_, _, tps, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id)); for vec::each(tps) |tp| { vfn(tp.id); }
vfn(id); vfn(id);
vfn(self_id); vfn(self_id);
vfn(parent_id.node); vfn(parent_id.node);
} }
visit::fk_dtor(tps, _, self_id, parent_id) => { visit::fk_dtor(tps, _, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id)); for vec::each(tps) |tp| { vfn(tp.id); }
vfn(id); vfn(id);
vfn(self_id); vfn(self_id);
vfn(parent_id.node); vfn(parent_id.node);
} }
visit::fk_item_fn(_, tps, _) => { visit::fk_item_fn(_, tps, _) => {
vec::iter(tps, |tp| vfn(tp.id)); for vec::each(tps) |tp| { vfn(tp.id); }
} }
visit::fk_method(_, tps, m) => { visit::fk_method(_, tps, m) => {
vfn(m.self_id); vfn(m.self_id);
vec::iter(tps, |tp| vfn(tp.id)); for vec::each(tps) |tp| { vfn(tp.id); }
} }
visit::fk_anon(_, capture_clause) visit::fk_anon(_, capture_clause) |
| visit::fk_fn_block(capture_clause) => { visit::fk_fn_block(capture_clause) => {
for vec::each(*capture_clause) |clause| { for vec::each(*capture_clause) |clause| {
vfn(clause.id); vfn(clause.id);
} }
} }
} }
do vec::iter(d.inputs) |arg| { for vec::each(d.inputs) |arg| {
vfn(arg.id) vfn(arg.id)
} }
}, },

View file

@ -228,7 +228,7 @@ fn finish<T: qq_helper>
let mut state = active; let mut state = active;
let mut i = 0u, j = 0u; let mut i = 0u, j = 0u;
let g_len = cx.gather.len(); let g_len = cx.gather.len();
do str::chars_iter(*str) |ch| { for str::chars_each(*str) |ch| {
if (j < g_len && i == cx.gather[j].lo) { if (j < g_len && i == cx.gather[j].lo) {
assert ch == '$'; assert ch == '$';
let repl = fmt!("$%u ", j); let repl = fmt!("$%u ", j);

View file

@ -211,7 +211,7 @@ pure fn follow(m: arb_depth<matchable>, idx_path: &[uint]) ->
for vec::each(idx_path) |idx| { for vec::each(idx_path) |idx| {
res = match res { res = match res {
leaf(_) => return res,/* end of the line */ leaf(_) => return res,/* end of the line */
seq(new_ms, _) => new_ms[idx] seq(new_ms, _) => new_ms[*idx]
} }
} }
return res; return res;

View file

@ -1674,7 +1674,7 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
word(s.s, ~":"); word(s.s, ~":");
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
nbsp(s); nbsp(s);
match bound { match *bound {
ast::bound_copy => word(s.s, ~"Copy"), ast::bound_copy => word(s.s, ~"Copy"),
ast::bound_send => word(s.s, ~"Send"), ast::bound_send => word(s.s, ~"Send"),
ast::bound_const => word(s.s, ~"Const"), ast::bound_const => word(s.s, ~"Const"),

View file

@ -263,7 +263,7 @@ fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
fn visit_ty_param_bounds<E>(bounds: @~[ty_param_bound], e: E, v: vt<E>) { fn visit_ty_param_bounds<E>(bounds: @~[ty_param_bound], e: E, v: vt<E>) {
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
match bound { match *bound {
bound_trait(t) => v.visit_ty(t, e, v), bound_trait(t) => v.visit_ty(t, e, v),
bound_copy | bound_send | bound_const | bound_owned => () bound_copy | bound_send | bound_const | bound_owned => ()
} }

View file

@ -539,7 +539,7 @@ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
// gas doesn't! // gas doesn't!
fn sanitize(s: ~str) -> ~str { fn sanitize(s: ~str) -> ~str {
let mut result = ~""; let mut result = ~"";
do str::chars_iter(s) |c| { for str::chars_each(s) |c| {
match c { match c {
'@' => result += ~"_sbox_", '@' => result += ~"_sbox_",
'~' => result += ~"_ubox_", '~' => result += ~"_ubox_",

View file

@ -99,8 +99,8 @@ fn get_crate_vers(cstore: cstore, cnum: ast::crate_num) -> ~str {
fn set_crate_data(cstore: cstore, cnum: ast::crate_num, fn set_crate_data(cstore: cstore, cnum: ast::crate_num,
data: crate_metadata) { data: crate_metadata) {
p(cstore).metas.insert(cnum, data); p(cstore).metas.insert(cnum, data);
do vec::iter(decoder::get_crate_module_paths(cstore.intr, data)) |dp| { for vec::each(decoder::get_crate_module_paths(cstore.intr, data)) |dp| {
let (did, path) = dp; let (did, path) = *dp;
let d = {crate: cnum, node: did.node}; let d = {crate: cnum, node: did.node};
p(cstore).mod_path_map.insert(d, @path); p(cstore).mod_path_map.insert(d, @path);
} }

View file

@ -267,7 +267,9 @@ fn encode_path(ecx: @encode_ctxt, ebml_w: ebml::Writer, path: ast_map::path,
do ebml_w.wr_tag(tag_path) { do ebml_w.wr_tag(tag_path) {
ebml_w.wr_tagged_u32(tag_path_len, (vec::len(path) + 1u) as u32); ebml_w.wr_tagged_u32(tag_path_len, (vec::len(path) + 1u) as u32);
do vec::iter(path) |pe| { encode_path_elt(ecx, ebml_w, pe); } for vec::each(path) |pe| {
encode_path_elt(ecx, ebml_w, *pe);
}
encode_path_elt(ecx, ebml_w, name); encode_path_elt(ecx, ebml_w, name);
} }
} }
@ -768,7 +770,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item,
// written. Here, we output the *real* type signatures. I feel like // written. Here, we output the *real* type signatures. I feel like
// maybe we should only ever handle the real type signatures. // maybe we should only ever handle the real type signatures.
for vec::each(ms) |m| { for vec::each(ms) |m| {
let ty_m = ast_util::trait_method_to_ty_method(m); let ty_m = ast_util::trait_method_to_ty_method(*m);
if ty_m.self_ty.node != ast::sty_static { loop; } if ty_m.self_ty.node != ast::sty_static { loop; }
vec::push(*index, {val: ty_m.id, pos: ebml_w.writer.tell()}); vec::push(*index, {val: ty_m.id, pos: ebml_w.writer.tell()});

View file

@ -366,7 +366,7 @@ fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) { fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| { for vec::each(*bs) |bound| {
match bound { match *bound {
ty::bound_send => w.write_char('S'), ty::bound_send => w.write_char('S'),
ty::bound_copy => w.write_char('C'), ty::bound_copy => w.write_char('C'),
ty::bound_const => w.write_char('K'), ty::bound_const => w.write_char('K'),

View file

@ -108,7 +108,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
implicit_mode = cap_copy; implicit_mode = cap_copy;
} }
do vec::iter(*freevars) |fvar| { for vec::each(*freevars) |fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node; let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
match cap_map.find(fvar_def_id) { match cap_map.find(fvar_def_id) {
option::Some(_) => { /* was explicitly named, do nothing */ } option::Some(_) => { /* was explicitly named, do nothing */ }

View file

@ -211,7 +211,7 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
}; };
let ty = ty::node_id_to_type(cx.tcx, id); let ty = ty::node_id_to_type(cx.tcx, id);
chk(cx, fn_id, Some(fv), is_move, ty, fv.span); chk(cx, fn_id, Some(*fv), is_move, ty, fv.span);
} }
} }
@ -228,7 +228,7 @@ fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) { fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
for vec::each(a.pats) |p| { for vec::each(a.pats) |p| {
do pat_util::pat_bindings(cx.tcx.def_map, p) |mode, id, span, _path| { do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| {
if mode == bind_by_value { if mode == bind_by_value {
let t = ty::node_id_to_type(cx.tcx, id); let t = ty::node_id_to_type(cx.tcx, id);
let reason = "consider binding with `ref` or `move` instead"; let reason = "consider binding with `ref` or `move` instead";

View file

@ -124,13 +124,13 @@ fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
// An option identifying a branch (either a literal, a enum variant or a // An option identifying a branch (either a literal, a enum variant or a
// range) // range)
enum opt { enum Opt {
lit(@ast::expr), lit(@ast::expr),
var(/* disr val */int, /* variant dids */{enm: def_id, var: def_id}), var(/* disr val */int, /* variant dids */{enm: def_id, var: def_id}),
range(@ast::expr, @ast::expr) range(@ast::expr, @ast::expr)
} }
fn opt_eq(tcx: ty::ctxt, a: opt, b: opt) -> bool { fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool {
match (a, b) { match (*a, *b) {
(lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0, (lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0,
(range(a1, a2), range(b1, b2)) => { (range(a1, a2), range(b1, b2)) => {
const_eval::compare_lit_exprs(tcx, a1, b1) == 0 && const_eval::compare_lit_exprs(tcx, a1, b1) == 0 &&
@ -145,11 +145,11 @@ enum opt_result {
single_result(Result), single_result(Result),
range_result(Result, Result), range_result(Result, Result),
} }
fn trans_opt(bcx: block, o: opt) -> opt_result { fn trans_opt(bcx: block, o: &Opt) -> opt_result {
let _icx = bcx.insn_ctxt("alt::trans_opt"); let _icx = bcx.insn_ctxt("alt::trans_opt");
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let mut bcx = bcx; let mut bcx = bcx;
match o { match *o {
lit(lit_expr) => { lit(lit_expr) => {
let datumblock = expr::trans_to_datum(bcx, lit_expr); let datumblock = expr::trans_to_datum(bcx, lit_expr);
return single_result(datumblock.to_result()); return single_result(datumblock.to_result());
@ -164,7 +164,7 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
} }
} }
fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> opt { fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt {
let vdef = ast_util::variant_def_ids(tcx.def_map.get(pat_id)); let vdef = ast_util::variant_def_ids(tcx.def_map.get(pat_id));
let variants = ty::enum_variants(tcx, vdef.enm); let variants = ty::enum_variants(tcx, vdef.enm);
for vec::each(*variants) |v| { for vec::each(*variants) |v| {
@ -337,7 +337,7 @@ fn enter_default(bcx: block, dm: DefMap, m: &[@Match/&r],
} }
} }
fn enter_opt(bcx: block, m: &[@Match/&r], opt: opt, col: uint, fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
variant_size: uint, val: ValueRef) variant_size: uint, val: ValueRef)
-> ~[@Match/&r] -> ~[@Match/&r]
{ {
@ -353,7 +353,7 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: opt, col: uint,
do enter_match(bcx, tcx.def_map, m, col, val) |p| { do enter_match(bcx, tcx.def_map, m, col, val) |p| {
match p.node { match p.node {
ast::pat_enum(_, subpats) => { ast::pat_enum(_, subpats) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) { if opt_eq(tcx, &variant_opt(tcx, p.id), opt) {
Some(option::get_default(subpats, Some(option::get_default(subpats,
vec::from_elem(variant_size, vec::from_elem(variant_size,
dummy))) dummy)))
@ -362,17 +362,17 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: opt, col: uint,
} }
} }
ast::pat_ident(_, _, None) if pat_is_variant(tcx.def_map, p) => { ast::pat_ident(_, _, None) if pat_is_variant(tcx.def_map, p) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) { if opt_eq(tcx, &variant_opt(tcx, p.id), opt) {
Some(~[]) Some(~[])
} else { } else {
None None
} }
} }
ast::pat_lit(l) => { ast::pat_lit(l) => {
if opt_eq(tcx, lit(l), opt) { Some(~[]) } else { None } if opt_eq(tcx, &lit(l), opt) {Some(~[])} else {None}
} }
ast::pat_range(l1, l2) => { ast::pat_range(l1, l2) => {
if opt_eq(tcx, range(l1, l2), opt) { Some(~[]) } else { None } if opt_eq(tcx, &range(l1, l2), opt) {Some(~[])} else {None}
} }
_ => { _ => {
assert_is_binding_or_wild(bcx, p); assert_is_binding_or_wild(bcx, p);
@ -397,7 +397,7 @@ fn enter_rec_or_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint,
ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => { ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => {
let mut pats = ~[]; let mut pats = ~[];
for vec::each(fields) |fname| { for vec::each(fields) |fname| {
match fpats.find(|p| p.ident == fname) { match fpats.find(|p| p.ident == *fname) {
None => vec::push(pats, dummy), None => vec::push(pats, dummy),
Some(pat) => vec::push(pats, pat.pat) Some(pat) => vec::push(pats, pat.pat)
} }
@ -487,9 +487,9 @@ fn enter_uniq(bcx: block, dm: DefMap, m: &[@Match/&r],
} }
} }
fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[opt] { fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] {
fn add_to_set(tcx: ty::ctxt, set: &DVec<opt>, val: opt) { fn add_to_set(tcx: ty::ctxt, set: &DVec<Opt>, val: Opt) {
if set.any(|l| opt_eq(tcx, l, val)) {return;} if set.any(|l| opt_eq(tcx, &l, &val)) {return;}
set.push(val); set.push(val);
} }
@ -628,12 +628,14 @@ fn pick_col(m: &[@Match]) -> uint {
let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u)); let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u));
for vec::each(m) |br| { for vec::each(m) |br| {
let mut i = 0u; let mut i = 0u;
for vec::each(br.pats) |p| { scores[i] += score(p); i += 1u; } for vec::each(br.pats) |p| { scores[i] += score(*p); i += 1u; }
} }
let mut max_score = 0u; let mut max_score = 0u;
let mut best_col = 0u; let mut best_col = 0u;
let mut i = 0u; let mut i = 0u;
for vec::each(scores) |score| { for vec::each(scores) |score| {
let score = *score;
// Irrefutable columns always go first, they'd only be duplicated in // Irrefutable columns always go first, they'd only be duplicated in
// the branches. // the branches.
if score == 0u { return i; } if score == 0u { return i; }
@ -959,7 +961,7 @@ fn compile_submatch(bcx: block,
} }
} }
for vec::each(opts) |o| { for vec::each(opts) |o| {
match o { match *o {
range(_, _) => { kind = compare; break } range(_, _) => { kind = compare; break }
_ => () _ => ()
} }
@ -1037,7 +1039,7 @@ fn compile_submatch(bcx: block,
let mut size = 0u; let mut size = 0u;
let mut unpacked = ~[]; let mut unpacked = ~[];
match opt { match *opt {
var(_, vdef) => { var(_, vdef) => {
let args = extract_variant_args(opt_cx, pat_id, vdef, val); let args = extract_variant_args(opt_cx, pat_id, vdef, val);
size = args.vals.len(); size = args.vals.len();
@ -1087,7 +1089,7 @@ fn trans_alt_inner(scope_cx: block,
} }
let mut arm_datas = ~[], matches = ~[]; let mut arm_datas = ~[], matches = ~[];
for vec::each_ref(arms) |arm| { for vec::each(arms) |arm| {
let body = scope_block(bcx, arm.body.info(), ~"case_body"); let body = scope_block(bcx, arm.body.info(), ~"case_body");
// Create the bindings map, which is a mapping from each binding name // Create the bindings map, which is a mapping from each binding name
@ -1129,7 +1131,7 @@ fn trans_alt_inner(scope_cx: block,
bindings_map: bindings_map}; bindings_map: bindings_map};
vec::push(arm_datas, arm_data); vec::push(arm_datas, arm_data);
for vec::each(arm.pats) |p| { for vec::each(arm.pats) |p| {
vec::push(matches, @Match {pats: ~[p], data: arm_data}); vec::push(matches, @Match {pats: ~[*p], data: arm_data});
} }
} }

View file

@ -160,11 +160,7 @@ fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>,
let n = args.len() as int; let n = args.len() as int;
let llforeign: ValueRef = let llforeign: ValueRef =
get_simple_extern_fn(cx, externs, llmod, name, n); get_simple_extern_fn(cx, externs, llmod, name, n);
let mut call_args: ~[ValueRef] = ~[]; return Call(cx, llforeign, args);
for vec::each(args) |a| {
vec::push(call_args, a);
}
return Call(cx, llforeign, call_args);
} }
fn umax(cx: block, a: ValueRef, b: ValueRef) -> ValueRef { fn umax(cx: block, a: ValueRef, b: ValueRef) -> ValueRef {
@ -599,7 +595,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
int::to_str(variant.disr_val, 10u)); int::to_str(variant.disr_val, 10u));
AddCase(llswitch, C_int(ccx, variant.disr_val), variant_cx.llbb); AddCase(llswitch, C_int(ccx, variant.disr_val), variant_cx.llbb);
let variant_cx = let variant_cx =
iter_variant(variant_cx, llunion_a_ptr, variant, iter_variant(variant_cx, llunion_a_ptr, *variant,
substs.tps, tid, f); substs.tps, tid, f);
Br(variant_cx, next_cx.llbb); Br(variant_cx, next_cx.llbb);
} }
@ -748,7 +744,7 @@ fn need_invoke(bcx: block) -> bool {
match cur.kind { match cur.kind {
block_scope(inf) => { block_scope(inf) => {
for vec::each(inf.cleanups) |cleanup| { for vec::each(inf.cleanups) |cleanup| {
match cleanup { match *cleanup {
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => { clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
if cleanup_type == normal_exit_and_unwind { if cleanup_type == normal_exit_and_unwind {
return true; return true;
@ -1020,9 +1016,9 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
match d.node { match d.node {
ast::decl_local(locals) => { ast::decl_local(locals) => {
for vec::each(locals) |local| { for vec::each(locals) |local| {
bcx = init_local(bcx, local); bcx = init_local(bcx, *local);
if cx.sess().opts.extra_debuginfo { if cx.sess().opts.extra_debuginfo {
debuginfo::create_local_var(bcx, local); debuginfo::create_local_var(bcx, *local);
} }
} }
} }
@ -1118,7 +1114,7 @@ fn trans_block_cleanups_(bcx: block,
bcx.ccx().sess.opts.debugging_opts & session::no_landing_pads != 0; bcx.ccx().sess.opts.debugging_opts & session::no_landing_pads != 0;
if bcx.unreachable && !no_lpads { return bcx; } if bcx.unreachable && !no_lpads { return bcx; }
let mut bcx = bcx; let mut bcx = bcx;
do vec::riter(cleanups) |cu| { for vec::reach(cleanups) |cu| {
match cu { match cu {
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => { clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => {
// Some types don't need to be cleaned up during // Some types don't need to be cleaned up during
@ -1235,7 +1231,9 @@ fn block_locals(b: ast::blk, it: fn(@ast::local)) {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
match d.node { match d.node {
ast::decl_local(locals) => { ast::decl_local(locals) => {
for vec::each(locals) |local| { it(local); } for vec::each(locals) |local| {
it(*local);
}
} }
_ => {/* fall through */ } _ => {/* fall through */ }
} }
@ -1789,7 +1787,7 @@ fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
match variant.node.kind { match variant.node.kind {
ast::tuple_variant_kind(args) if args.len() > 0 => { ast::tuple_variant_kind(args) if args.len() > 0 => {
let llfn = get_item_val(ccx, variant.node.id); let llfn = get_item_val(ccx, variant.node.id);
trans_enum_variant(ccx, id, variant, args, disr_val, trans_enum_variant(ccx, id, *variant, args, disr_val,
degen, None, llfn); degen, None, llfn);
} }
ast::tuple_variant_kind(_) => { ast::tuple_variant_kind(_) => {
@ -1910,7 +1908,9 @@ fn trans_trait(ccx: @crate_ctxt, tps: ~[ast::ty_param],
// and control visibility. // and control visibility.
fn trans_mod(ccx: @crate_ctxt, m: ast::_mod) { fn trans_mod(ccx: @crate_ctxt, m: ast::_mod) {
let _icx = ccx.insn_ctxt("trans_mod"); let _icx = ccx.insn_ctxt("trans_mod");
for vec::each(m.items) |item| { trans_item(ccx, *item); } for vec::each(m.items) |item| {
trans_item(ccx, **item);
}
} }
fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef { fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
@ -2355,10 +2355,11 @@ fn gather_local_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
ast::item_fn(*) => { ast::item_fn(*) => {
let attr_metas = attr::attr_metas( let attr_metas = attr::attr_metas(
attr::find_attrs_by_name(item.attrs, ~"rt")); attr::find_attrs_by_name(item.attrs, ~"rt"));
do vec::iter(attr_metas) |attr_meta| { for vec::each(attr_metas) |attr_meta| {
match attr::get_meta_item_list(attr_meta) { match attr::get_meta_item_list(*attr_meta) {
Some(list) => { Some(list) => {
let name = attr::get_meta_item_name(vec::head(list)); let head = vec::head(list);
let name = attr::get_meta_item_name(head);
push_rtcall(ccx, name, {crate: ast::local_crate, push_rtcall(ccx, name, {crate: ast::local_crate,
node: item.id}); node: item.id});
} }
@ -2413,8 +2414,8 @@ fn gather_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
let expected_rtcalls = let expected_rtcalls =
~[~"exchange_free", ~"exchange_malloc", ~"fail_", ~"free", ~"malloc"]; ~[~"exchange_free", ~"exchange_malloc", ~"fail_", ~"free", ~"malloc"];
for vec::each(expected_rtcalls) |name| { for vec::each(expected_rtcalls) |name| {
if !ccx.rtcalls.contains_key(name) { if !ccx.rtcalls.contains_key(*name) {
fail fmt!("no definition for runtime call %s", name); fail fmt!("no definition for runtime call %s", *name);
} }
} }
} }

View file

@ -435,7 +435,7 @@ fn GEP(cx: block, Pointer: ValueRef, Indices: ~[ValueRef]) -> ValueRef {
// XXX: Use a small-vector optimization to avoid allocations here. // XXX: Use a small-vector optimization to avoid allocations here.
fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef { fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
let mut v: ~[ValueRef] = ~[]; let mut v: ~[ValueRef] = ~[];
for vec::each(ixs) |i| { vec::push(v, C_i32(i as i32)); } for vec::each(ixs) |i| { vec::push(v, C_i32(*i as i32)); }
count_insn(cx, "gepi"); count_insn(cx, "gepi");
return InBoundsGEP(cx, base, v); return InBoundsGEP(cx, base, v);
} }

View file

@ -450,7 +450,7 @@ fn trans_args(cx: block, llenv: ValueRef, args: CallArgs, fn_ty: ty::t,
match args { match args {
ArgExprs(arg_exprs) => { ArgExprs(arg_exprs) => {
let last = arg_exprs.len() - 1u; let last = arg_exprs.len() - 1u;
do vec::iteri(arg_exprs) |i, arg_expr| { for vec::eachi(arg_exprs) |i, arg_expr| {
let arg_val = unpack_result!(bcx, { let arg_val = unpack_result!(bcx, {
trans_arg_expr(bcx, arg_tys[i], arg_expr, &mut temp_cleanups, trans_arg_expr(bcx, arg_tys[i], arg_expr, &mut temp_cleanups,
if i == last { ret_flag } else { None }) if i == last { ret_flag } else { None })
@ -466,8 +466,8 @@ fn trans_args(cx: block, llenv: ValueRef, args: CallArgs, fn_ty: ty::t,
// now that all arguments have been successfully built, we can revoke any // now that all arguments have been successfully built, we can revoke any
// temporary cleanups, as they are only needed if argument construction // temporary cleanups, as they are only needed if argument construction
// should fail (for example, cleanup of copy mode args). // should fail (for example, cleanup of copy mode args).
do vec::iter(temp_cleanups) |c| { for vec::each(temp_cleanups) |c| {
revoke_clean(bcx, c) revoke_clean(bcx, *c)
} }
return {bcx: bcx, args: llargs, retslot: llretslot}; return {bcx: bcx, args: llargs, retslot: llretslot};

View file

@ -209,7 +209,7 @@ fn store_environment(bcx: block,
// Copy expr values into boxed bindings. // Copy expr values into boxed bindings.
let mut bcx = bcx; let mut bcx = bcx;
do vec::iteri(bound_values) |i, bv| { for vec::eachi(bound_values) |i, bv| {
debug!("Copy %s into closure", bv.to_str(ccx)); debug!("Copy %s into closure", bv.to_str(ccx));
if !ccx.sess.no_asm_comments() { if !ccx.sess.no_asm_comments() {
@ -232,7 +232,9 @@ fn store_environment(bcx: block,
} }
} }
for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, cleanup); } for vec::each(temp_cleanups) |cleanup| {
revoke_clean(bcx, *cleanup);
}
return {llbox: llbox, cdata_ty: cdata_ty, bcx: bcx}; return {llbox: llbox, cdata_ty: cdata_ty, bcx: bcx};
} }
@ -251,8 +253,8 @@ fn build_closure(bcx0: block,
// Package up the captured upvars // Package up the captured upvars
let mut env_vals = ~[]; let mut env_vals = ~[];
do vec::iter(cap_vars) |cap_var| { for vec::each(cap_vars) |cap_var| {
debug!("Building closure: captured variable %?", cap_var); debug!("Building closure: captured variable %?", *cap_var);
let datum = expr::trans_local_var(bcx, id, cap_var.def); let datum = expr::trans_local_var(bcx, id, cap_var.def);
match cap_var.mode { match cap_var.mode {
capture::cap_ref => { capture::cap_ref => {
@ -316,7 +318,7 @@ fn load_environment(fcx: fn_ctxt,
// Populate the upvars from the environment. // Populate the upvars from the environment.
let mut i = 0u; let mut i = 0u;
do vec::iter(cap_vars) |cap_var| { for vec::each(cap_vars) |cap_var| {
match cap_var.mode { match cap_var.mode {
capture::cap_drop => { /* ignore */ } capture::cap_drop => { /* ignore */ }
_ => { _ => {

View file

@ -1175,11 +1175,13 @@ fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef {
fn path_str(sess: session::session, p: path) -> ~str { fn path_str(sess: session::session, p: path) -> ~str {
let mut r = ~"", first = true; let mut r = ~"", first = true;
for vec::each(p) |e| { for vec::each(p) |e| {
match e { ast_map::path_name(s) | ast_map::path_mod(s) => { match *e {
ast_map::path_name(s) | ast_map::path_mod(s) => {
if first { first = false; } if first { first = false; }
else { r += ~"::"; } else { r += ~"::"; }
r += sess.str_of(s); r += sess.str_of(s);
} } }
}
} }
r r
} }
@ -1269,8 +1271,8 @@ fn find_vtable(tcx: ty::ctxt, ps: &param_substs,
// somewhat awkward // somewhat awkward
for vec::each(*ps.bounds) |bounds| { for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; } if i >= n_param { break; }
for vec::each(*bounds) |bound| { for vec::each(**bounds) |bound| {
match bound { ty::bound_trait(_) => vtable_off += 1u, _ => () } match *bound { ty::bound_trait(_) => vtable_off += 1u, _ => () }
} }
i += 1u; i += 1u;
} }

View file

@ -13,7 +13,7 @@ fn trans_block(bcx: block, b: ast::blk, dest: expr::Dest) -> block {
}; };
for vec::each(b.node.stmts) |s| { for vec::each(b.node.stmts) |s| {
debuginfo::update_source_pos(bcx, b.span); debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s); bcx = trans_stmt(bcx, **s);
} }
match b.node.expr { match b.node.expr {
Some(e) => { Some(e) => {
@ -85,7 +85,7 @@ fn join_blocks(parent_bcx: block, in_cxs: ~[block]) -> block {
let mut reachable = false; let mut reachable = false;
for vec::each(in_cxs) |bcx| { for vec::each(in_cxs) |bcx| {
if !bcx.unreachable { if !bcx.unreachable {
Br(bcx, out.llbb); Br(*bcx, out.llbb);
reachable = true; reachable = true;
} }
} }

View file

@ -1027,7 +1027,9 @@ fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: Dest) -> block {
let mut bcx = bcx; let mut bcx = bcx;
let addr = match dest { let addr = match dest {
Ignore => { Ignore => {
for vec::each(elts) |ex| { bcx = trans_into(bcx, ex, Ignore); } for vec::each(elts) |ex| {
bcx = trans_into(bcx, *ex, Ignore);
}
return bcx; return bcx;
} }
SaveIn(pos) => pos, SaveIn(pos) => pos,
@ -1040,7 +1042,9 @@ fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: Dest) -> block {
add_clean_temp_mem(bcx, dest, e_ty); add_clean_temp_mem(bcx, dest, e_ty);
vec::push(temp_cleanups, dest); vec::push(temp_cleanups, dest);
} }
for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, cleanup); } for vec::each(temp_cleanups) |cleanup| {
revoke_clean(bcx, *cleanup);
}
return bcx; return bcx;
} }

View file

@ -165,9 +165,9 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
} else { } else {
let mut field_off = off; let mut field_off = off;
for vec::each(tys) |ty| { for vec::each(tys) |ty| {
field_off = align(field_off, ty); field_off = align(field_off, *ty);
classify(ty, cls, i, field_off); classify(*ty, cls, i, field_off);
field_off += ty_size(ty); field_off += ty_size(*ty);
} }
} }
} }
@ -283,7 +283,7 @@ fn llreg_ty(cls: ~[x86_64_reg_class]) -> TypeRef {
fn llvec_len(cls: ~[x86_64_reg_class]) -> uint { fn llvec_len(cls: ~[x86_64_reg_class]) -> uint {
let mut len = 1u; let mut len = 1u;
for vec::each(cls) |c| { for vec::each(cls) |c| {
if c != sseup_class { if *c != sseup_class {
break; break;
} }
len += 1u; len += 1u;
@ -377,7 +377,7 @@ fn x86_64_tys(atys: ~[TypeRef],
let mut arg_tys = ~[]; let mut arg_tys = ~[];
let mut attrs = ~[]; let mut attrs = ~[];
for vec::each(atys) |t| { for vec::each(atys) |t| {
let (ty, attr) = x86_64_ty(t, is_pass_byval, ByValAttribute); let (ty, attr) = x86_64_ty(*t, is_pass_byval, ByValAttribute);
vec::push(arg_tys, ty); vec::push(arg_tys, ty);
vec::push(attrs, attr); vec::push(attrs, attr);
} }
@ -410,7 +410,7 @@ fn decl_x86_64_fn(tys: x86_64_tys,
let fnty = T_fn(atys, rty); let fnty = T_fn(atys, rty);
let llfn = decl(fnty); let llfn = decl(fnty);
do vec::iteri(tys.attrs) |i, a| { for vec::eachi(tys.attrs) |i, a| {
match a { match a {
option::Some(attr) => { option::Some(attr) => {
let llarg = get_param(llfn, i); let llarg = get_param(llfn, i);
@ -640,7 +640,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt,
let _icx = bcx.insn_ctxt("foreign::shim::build_ret"); let _icx = bcx.insn_ctxt("foreign::shim::build_ret");
match tys.x86_64_tys { match tys.x86_64_tys {
Some(x86_64) => { Some(x86_64) => {
do vec::iteri(x86_64.attrs) |i, a| { for vec::eachi(x86_64.attrs) |i, a| {
match a { match a {
Some(attr) => { Some(attr) => {
llvm::LLVMAddInstrAttribute( llvm::LLVMAddInstrAttribute(
@ -771,9 +771,9 @@ fn trans_foreign_mod(ccx: @crate_ctxt,
let tys = c_stack_tys(ccx, id); let tys = c_stack_tys(ccx, id);
if attr::attrs_contains_name(foreign_item.attrs, if attr::attrs_contains_name(foreign_item.attrs,
~"rust_stack") { ~"rust_stack") {
build_direct_fn(ccx, llwrapfn, foreign_item, tys, cc); build_direct_fn(ccx, llwrapfn, *foreign_item, tys, cc);
} else { } else {
let llshimfn = build_shim_fn(ccx, foreign_item, tys, cc); let llshimfn = build_shim_fn(ccx, *foreign_item, tys, cc);
build_wrap_fn(ccx, tys, llshimfn, llwrapfn); build_wrap_fn(ccx, tys, llshimfn, llwrapfn);
} }
} else { } else {

View file

@ -35,7 +35,7 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
if method.tps.len() == 0u { if method.tps.len() == 0u {
let llfn = get_item_val(ccx, method.id); let llfn = get_item_val(ccx, method.id);
let path = vec::append_one(sub_path, path_name(method.ident)); let path = vec::append_one(sub_path, path_name(method.ident));
trans_method(ccx, path, method, None, llfn); trans_method(ccx, path, *method, None, llfn);
} }
} }
} }

View file

@ -244,7 +244,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
vec::map2(*bounds, substs, |bounds, subst| { vec::map2(*bounds, substs, |bounds, subst| {
let mut v = ~[]; let mut v = ~[];
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
match bound { match *bound {
ty::bound_trait(_) => { ty::bound_trait(_) => {
vec::push(v, meth::vtable_id(ccx, vts[i])); vec::push(v, meth::vtable_id(ccx, vts[i]));
i += 1u; i += 1u;

View file

@ -54,7 +54,9 @@ fn traverse_exports(cx: ctx, vis: ~[@view_item]) -> bool {
fn traverse_export(cx: ctx, exp_id: node_id) { fn traverse_export(cx: ctx, exp_id: node_id) {
do option::iter(cx.exp_map.find(exp_id)) |defs| { do option::iter(cx.exp_map.find(exp_id)) |defs| {
for vec::each(defs) |def| { traverse_def_id(cx, def.id); } for vec::each(defs) |def| {
traverse_def_id(cx, def.id);
}
} }
} }
@ -82,7 +84,9 @@ fn traverse_def_id(cx: ctx, did: def_id) {
fn traverse_public_mod(cx: ctx, m: _mod) { fn traverse_public_mod(cx: ctx, m: _mod) {
if !traverse_exports(cx, m.view_items) { if !traverse_exports(cx, m.view_items) {
// No exports, so every local item is exported // No exports, so every local item is exported
for vec::each(m.items) |item| { traverse_public_item(cx, item); } for vec::each(m.items) |item| {
traverse_public_item(cx, *item);
}
} }
} }
@ -93,7 +97,9 @@ fn traverse_public_item(cx: ctx, item: @item) {
item_mod(m) => traverse_public_mod(cx, m), item_mod(m) => traverse_public_mod(cx, m),
item_foreign_mod(nm) => { item_foreign_mod(nm) => {
if !traverse_exports(cx, nm.view_items) { if !traverse_exports(cx, nm.view_items) {
for vec::each(nm.items) |item| { cx.rmap.insert(item.id, ()); } for vec::each(nm.items) |item| {
cx.rmap.insert(item.id, ());
}
} }
} }
item_fn(_, _, tps, blk) => { item_fn(_, _, tps, blk) => {

View file

@ -323,7 +323,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
ty::ty_tup(elts) => { ty::ty_tup(elts) => {
let mut s = ~[shape_struct], sub = ~[]; let mut s = ~[shape_struct], sub = ~[];
for vec::each(elts) |elt| { for vec::each(elts) |elt| {
sub += shape_of(ccx, elt); sub += shape_of(ccx, *elt);
} }
add_substr(s, sub); add_substr(s, sub);
s s
@ -376,7 +376,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info) -> ~[u8] { fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info) -> ~[u8] {
let mut s = ~[]; let mut s = ~[];
for vec::each(v.args) |t| { s += shape_of(ccx, t); } for vec::each(v.args) |t| { s += shape_of(ccx, *t); }
return s; return s;
} }
@ -391,10 +391,10 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
while i < ccx.shape_cx.tag_order.len() { while i < ccx.shape_cx.tag_order.len() {
let {did, substs} = ccx.shape_cx.tag_order[i]; let {did, substs} = ccx.shape_cx.tag_order[i];
let variants = @ty::substd_enum_variants(ccx.tcx, did, &substs); let variants = @ty::substd_enum_variants(ccx.tcx, did, &substs);
do vec::iter(*variants) |v| { for vec::each(*variants) |v| {
offsets += ~[vec::len(data) as u16]; offsets += ~[vec::len(data) as u16];
let variant_shape = shape_of_variant(ccx, v); let variant_shape = shape_of_variant(ccx, *v);
add_substr(data, variant_shape); add_substr(data, variant_shape);
let zname = str::to_bytes(ccx.sess.str_of(v.name)) + ~[0u8]; let zname = str::to_bytes(ccx.sess.str_of(v.name)) + ~[0u8];
@ -435,7 +435,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
let lv = largest_variants(ccx, variants); let lv = largest_variants(ccx, variants);
add_u16(lv_table, vec::len(lv) as u16); add_u16(lv_table, vec::len(lv) as u16);
for vec::each(lv) |v| { add_u16(lv_table, v as u16); } for vec::each(lv) |v| { add_u16(lv_table, *v as u16); }
// Determine whether the enum has dynamic size. // Determine whether the enum has dynamic size.
assert !vec::any(*variants, |v| { assert !vec::any(*variants, |v| {
@ -482,13 +482,13 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
let mut bounded = true; let mut bounded = true;
let mut min_size = 0u, min_align = 0u; let mut min_size = 0u, min_align = 0u;
for vec::each(variant.args) |elem_t| { for vec::each(variant.args) |elem_t| {
if ty::type_has_params(elem_t) { if ty::type_has_params(*elem_t) {
// NB: We could do better here; this causes us to // NB: We could do better here; this causes us to
// conservatively assume that (int, T) has minimum size 0, // conservatively assume that (int, T) has minimum size 0,
// when in fact it has minimum size sizeof(int). // when in fact it has minimum size sizeof(int).
bounded = false; bounded = false;
} else { } else {
let llty = type_of::type_of(ccx, elem_t); let llty = type_of::type_of(ccx, *elem_t);
min_size += llsize_of_real(ccx, llty); min_size += llsize_of_real(ccx, llty);
min_align += llalign_of_pref(ccx, llty); min_align += llalign_of_pref(ccx, llty);
} }
@ -553,8 +553,8 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
for vec::each(largest_variants) |vid| { for vec::each(largest_variants) |vid| {
// We increment a "virtual data pointer" to compute the size. // We increment a "virtual data pointer" to compute the size.
let mut lltys = ~[]; let mut lltys = ~[];
for vec::each(variants[vid].args) |typ| { for vec::each(variants[*vid].args) |typ| {
lltys += ~[type_of::type_of(ccx, typ)]; lltys += ~[type_of::type_of(ccx, *typ)];
} }
let llty = trans::common::T_struct(lltys); let llty = trans::common::T_struct(lltys);

View file

@ -335,7 +335,7 @@ fn write_content(bcx: block,
vec::push(temp_cleanups, lleltptr); vec::push(temp_cleanups, lleltptr);
} }
for vec::each(temp_cleanups) |cleanup| { for vec::each(temp_cleanups) |cleanup| {
revoke_clean(bcx, cleanup); revoke_clean(bcx, *cleanup);
} }
} }
} }
@ -373,7 +373,7 @@ fn write_content(bcx: block,
} }
for vec::each(temp_cleanups) |cleanup| { for vec::each(temp_cleanups) |cleanup| {
revoke_clean(bcx, cleanup); revoke_clean(bcx, *cleanup);
} }
return bcx; return bcx;

View file

@ -158,7 +158,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
ty::ty_tup(elts) => { ty::ty_tup(elts) => {
let mut tys = ~[]; let mut tys = ~[];
for vec::each(elts) |elt| { for vec::each(elts) |elt| {
vec::push(tys, type_of(cx, elt)); vec::push(tys, type_of(cx, *elt));
} }
T_struct(tys) T_struct(tys)
} }

View file

@ -118,7 +118,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
fn type_needs(cx: ctx, use_: uint, ty: ty::t) { fn type_needs(cx: ctx, use_: uint, ty: ty::t) {
// Optimization -- don't descend type if all params already have this use // Optimization -- don't descend type if all params already have this use
for vec::each_mut_ref(cx.uses) |u| { for vec::each_mut(cx.uses) |u| {
if *u & use_ != use_ { if *u & use_ != use_ {
type_needs_inner(cx, use_, ty, @Nil); type_needs_inner(cx, use_, ty, @Nil);
return; return;
@ -144,7 +144,7 @@ fn type_needs_inner(cx: ctx, use_: uint, ty: ty::t,
let seen = @Cons(did, enums_seen); let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| { for vec::each(v.args) |aty| {
let t = ty::subst(cx.ccx.tcx, &substs, aty); let t = ty::subst(cx.ccx.tcx, &substs, *aty);
type_needs_inner(cx, use_, t, seen); type_needs_inner(cx, use_, t, seen);
} }
} }
@ -247,14 +247,16 @@ fn mark_for_expr(cx: ctx, e: @expr) {
node_type_needs(cx, use_tydesc, val.id); node_type_needs(cx, use_tydesc, val.id);
} }
expr_call(f, _, _) => { expr_call(f, _, _) => {
vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), |a| { for vec::each(
ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id))
) |a| {
match a.mode { match a.mode {
expl(by_move) | expl(by_copy) | expl(by_val) => { expl(by_move) | expl(by_copy) | expl(by_val) => {
type_needs(cx, use_repr, a.ty); type_needs(cx, use_repr, a.ty);
} }
_ => () _ => ()
} }
}) }
} }
expr_match(*) | expr_block(_) | expr_if(*) | expr_match(*) | expr_block(_) | expr_if(*) |
expr_while(*) | expr_fail(_) | expr_break(_) | expr_again(_) | expr_while(*) | expr_fail(_) | expr_break(_) | expr_again(_) |

View file

@ -774,7 +774,7 @@ impl FnVid : to_bytes::IterBytes {
fn param_bounds_to_kind(bounds: param_bounds) -> kind { fn param_bounds_to_kind(bounds: param_bounds) -> kind {
let mut kind = kind_noncopyable(); let mut kind = kind_noncopyable();
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
match bound { match *bound {
bound_copy => { bound_copy => {
kind = raise_kind(kind, kind_implicitly_copyable()); kind = raise_kind(kind, kind_implicitly_copyable());
} }
@ -2682,7 +2682,7 @@ pure fn hash_type_structure(st: &sty) -> uint {
} }
pure fn hash_subtys(id: uint, subtys: ~[t]) -> uint { pure fn hash_subtys(id: uint, subtys: ~[t]) -> uint {
let mut h = id; let mut h = id;
for vec::each(subtys) |s| { h = (h << 2u) + type_id(s) } for vec::each(subtys) |s| { h = (h << 2u) + type_id(*s) }
h h
} }
pure fn hash_substs(h: uint, substs: &substs) -> uint { pure fn hash_substs(h: uint, substs: &substs) -> uint {

View file

@ -57,7 +57,6 @@ use std::smallintmap;
use std::map; use std::map;
use std::map::{HashMap, int_hash}; use std::map::{HashMap, int_hash};
use std::serialization::{serialize_uint, deserialize_uint}; use std::serialization::{serialize_uint, deserialize_uint};
use vec::each;
use syntax::print::pprust::*; use syntax::print::pprust::*;
use util::ppaux::{ty_to_str, tys_to_str, region_to_str, use util::ppaux::{ty_to_str, tys_to_str, region_to_str,
bound_region_to_str, vstore_to_str, expr_repr}; bound_region_to_str, vstore_to_str, expr_repr};

View file

@ -293,7 +293,7 @@ impl LookupContext {
let mut next_bound_idx = 0; // count only trait bounds let mut next_bound_idx = 0; // count only trait bounds
let bounds = tcx.ty_param_bounds.get(param_ty.def_id.node); let bounds = tcx.ty_param_bounds.get(param_ty.def_id.node);
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
let bound_t = match bound { let bound_t = match *bound {
ty::bound_trait(bound_t) => bound_t, ty::bound_trait(bound_t) => bound_t,
ty::bound_copy | ty::bound_send | ty::bound_copy | ty::bound_send |

View file

@ -49,7 +49,7 @@ fn lookup_vtables(fcx: @fn_ctxt,
let mut result = ~[], i = 0u; let mut result = ~[], i = 0u;
for substs.tps.each |ty| { for substs.tps.each |ty| {
for vec::each(*bounds[i]) |bound| { for vec::each(*bounds[i]) |bound| {
match bound { match *bound {
ty::bound_trait(i_ty) => { ty::bound_trait(i_ty) => {
let i_ty = ty::subst(tcx, substs, i_ty); let i_ty = ty::subst(tcx, substs, i_ty);
vec::push(result, lookup_vtable(fcx, expr, ty, i_ty, vec::push(result, lookup_vtable(fcx, expr, ty, i_ty,
@ -122,7 +122,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
ty::ty_param({idx: n, def_id: did}) => { ty::ty_param({idx: n, def_id: did}) => {
let mut n_bound = 0; let mut n_bound = 0;
for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| { for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| {
match bound { match *bound {
ty::bound_send | ty::bound_copy | ty::bound_const | ty::bound_send | ty::bound_copy | ty::bound_const |
ty::bound_owned => { ty::bound_owned => {
/* ignore */ /* ignore */
@ -215,7 +215,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
// unify it with trait_ty in order to get all // unify it with trait_ty in order to get all
// the ty vars sorted out. // the ty vars sorted out.
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| { for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
match ty::get(of_ty).sty { match ty::get(*of_ty).sty {
ty::ty_trait(id, _, _) => { ty::ty_trait(id, _, _) => {
// Not the trait we're looking for // Not the trait we're looking for
if id != trait_id { loop; } if id != trait_id { loop; }
@ -271,8 +271,8 @@ fn lookup_vtable(fcx: @fn_ctxt,
debug!("(checking vtable) @2 relating trait \ debug!("(checking vtable) @2 relating trait \
ty %s to of_ty %s", ty %s to of_ty %s",
fcx.infcx().ty_to_str(trait_ty), fcx.infcx().ty_to_str(trait_ty),
fcx.infcx().ty_to_str(of_ty)); fcx.infcx().ty_to_str(*of_ty));
let of_ty = ty::subst(tcx, &substs, of_ty); let of_ty = ty::subst(tcx, &substs, *of_ty);
relate_trait_tys(fcx, expr, trait_ty, of_ty); relate_trait_tys(fcx, expr, trait_ty, of_ty);
// Recall that trait_ty -- the trait type // Recall that trait_ty -- the trait type

View file

@ -137,7 +137,7 @@ fn visit_expr(e: @ast::expr, wbcx: wb_ctxt, v: wb_vt) {
match e.node { match e.node {
ast::expr_fn(_, decl, _, _) | ast::expr_fn(_, decl, _, _) |
ast::expr_fn_block(decl, _, _) => { ast::expr_fn_block(decl, _, _) => {
do vec::iter(decl.inputs) |input| { for vec::each(decl.inputs) |input| {
let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id); let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id);
// Just in case we never constrained the mode to anything, // Just in case we never constrained the mode to anything,

View file

@ -363,7 +363,7 @@ fn check_methods_against_trait(ccx: @crate_ctxt,
Some({mty: impl_m, span, _}) => { Some({mty: impl_m, span, _}) => {
compare_impl_method( compare_impl_method(
ccx.tcx, span, impl_m, vec::len(tps), ccx.tcx, span, impl_m, vec::len(tps),
trait_m, tpt.substs, selfty); *trait_m, tpt.substs, selfty);
} }
None => { None => {
// If we couldn't find an implementation for trait_m in // If we couldn't find an implementation for trait_m in

View file

@ -314,8 +314,8 @@ fn write_desc(
} }
fn write_sections(ctxt: Ctxt, sections: ~[doc::Section]) { fn write_sections(ctxt: Ctxt, sections: ~[doc::Section]) {
do vec::iter(sections) |section| { for vec::each(sections) |section| {
write_section(ctxt, section); write_section(ctxt, *section);
} }
} }
@ -609,7 +609,9 @@ fn write_variants(
write_header_(ctxt, H4, ~"Variants"); write_header_(ctxt, H4, ~"Variants");
vec::iter(docs, |variant| write_variant(ctxt, variant) ); for vec::each(docs) |variant| {
write_variant(ctxt, *variant);
}
ctxt.w.write_line(~""); ctxt.w.write_line(~"");
} }
@ -666,7 +668,9 @@ fn write_trait(ctxt: Ctxt, doc: doc::TraitDoc) {
} }
fn write_methods(ctxt: Ctxt, docs: ~[doc::MethodDoc]) { fn write_methods(ctxt: Ctxt, docs: ~[doc::MethodDoc]) {
do vec::iter(docs) |doc| { write_method(ctxt, doc) } for vec::each(docs) |doc| {
write_method(ctxt, *doc);
}
} }
fn write_method(ctxt: Ctxt, doc: doc::MethodDoc) { fn write_method(ctxt: Ctxt, doc: doc::MethodDoc) {

View file

@ -75,9 +75,12 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
}; };
do vec::each(edges) |e| { do vec::each(edges) |e| {
let (i, j) = e; match *e {
(i, j) => {
map::set_add(graph[i], j); map::set_add(graph[i], j);
map::set_add(graph[j], i); map::set_add(graph[j], i);
}
}
true true
} }

View file

@ -73,7 +73,10 @@ fn run(args: &[~str]) {
server(from_parent, to_parent); server(from_parent, to_parent);
} }
vec::iter(worker_results, |r| { future::get(&r); } ); for vec::each(worker_results) |r| {
future::get(r);
}
//error!("sending stop message"); //error!("sending stop message");
to_child.send(stop); to_child.send(stop);
move_out!(to_child); move_out!(to_child);

View file

@ -70,7 +70,10 @@ fn run(args: &[~str]) {
server(from_parent, to_parent); server(from_parent, to_parent);
} }
vec::iter(worker_results, |r| { future::get(&r); } ); for vec::each(worker_results) |r| {
future::get(r);
}
//error!("sending stop message"); //error!("sending stop message");
to_child.send(stop); to_child.send(stop);
move_out!(to_child); move_out!(to_child);

View file

@ -44,7 +44,9 @@ fn run(args: ~[~str]) {
} }
}; };
} }
vec::iter(worker_results, |r| { future::get(&r); } ); for vec::each(worker_results) |r| {
future::get(r);
}
comm::send(to_child, stop); comm::send(to_child, stop);
let result = comm::recv(from_child); let result = comm::recv(from_child);
let end = std::time::precise_time_s(); let end = std::time::precise_time_s();

View file

@ -9,8 +9,8 @@ fn print_complements() {
let all = ~[Blue, Red, Yellow]; let all = ~[Blue, Red, Yellow];
for vec::each(all) |aa| { for vec::each(all) |aa| {
for vec::each(all) |bb| { for vec::each(all) |bb| {
io::println(show_color(aa) + ~" + " + show_color(bb) + io::println(show_color(*aa) + ~" + " + show_color(*bb) +
~" -> " + show_color(transform(aa,bb))); ~" -> " + show_color(transform(*aa, *bb)));
} }
} }
} }
@ -171,7 +171,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
// print each creature's stats // print each creature's stats
for vec::each(report) |rep| { for vec::each(report) |rep| {
io::println(rep); io::println(*rep);
} }
// print the total number of creatures met // print the total number of creatures met

View file

@ -31,8 +31,8 @@ fn calc(children: uint, parent_ch: comm::Chan<msg>) {
match comm::recv(port) { match comm::recv(port) {
start => { start => {
do vec::iter (child_chs) |child_ch| { for vec::each(child_chs) |child_ch| {
comm::send(child_ch, start); comm::send(*child_ch, start);
} }
} }
_ => fail ~"task-perf-one-million failed (port not in start state)" _ => fail ~"task-perf-one-million failed (port not in start state)"

View file

@ -1,6 +1,6 @@
fn want_slice(v: &[int]) -> int { fn want_slice(v: &[int]) -> int {
let mut sum = 0; let mut sum = 0;
for vec::each(v) |i| { sum += i; } for vec::each(v) |i| { sum += *i; }
return sum; return sum;
} }

View file

@ -1,5 +1,5 @@
fn main() { fn main() {
do vec::iter(fail) |i| { for vec::each(fail) |i| {
log (debug, i * 2); log (debug, i * 2);
//~^ ERROR the type of this value must be known //~^ ERROR the type of this value must be known
}; };

View file

@ -1,5 +1,6 @@
fn main() { fn main() {
let a: ~[int] = ~[]; let a: ~[int] = ~[];
vec::each(a, fn@(_x: int) -> bool { //~ ERROR not all control paths return a value vec::each(a, fn@(_x: &int) -> bool {
//~^ ERROR not all control paths return a value
}); });
} }

View file

@ -2,9 +2,9 @@ fn concat<T: Copy>(v: ~[const ~[const T]]) -> ~[T] {
let mut r = ~[]; let mut r = ~[];
// Earlier versions of our type checker accepted this: // Earlier versions of our type checker accepted this:
vec::iter(v, |&&inner: ~[T]| { vec::each(v, |inner: &~[T]| {
//~^ ERROR values differ in mutability //~^ ERROR values differ in mutability
r += inner; r += *inner; true
}); });
return r; return r;

View file

@ -2,21 +2,23 @@
// making method calls, but only if there aren't any matches without // making method calls, but only if there aren't any matches without
// it. // it.
#[legacy_modes];
trait iterable<A> { trait iterable<A> {
fn iterate(blk: fn(A) -> bool); fn iterate(blk: fn(x: &A) -> bool);
} }
impl<A> &[A]: iterable<A> { impl<A> &[A]: iterable<A> {
fn iterate(f: fn(A) -> bool) { fn iterate(f: fn(x: &A) -> bool) {
vec::each(self, f); for vec::each(self) |e| {
if !f(e) { break; }
}
} }
} }
impl<A> ~[A]: iterable<A> { impl<A> ~[A]: iterable<A> {
fn iterate(f: fn(A) -> bool) { fn iterate(f: fn(x: &A) -> bool) {
vec::each(self, f); for vec::each(self) |e| {
if !f(e) { break; }
}
} }
} }
@ -29,7 +31,7 @@ fn length<A, T: iterable<A>>(x: T) -> uint {
fn main() { fn main() {
let x = ~[0,1,2,3]; let x = ~[0,1,2,3];
// Call a method // Call a method
for x.iterate() |y| { assert x[y] == y; } for x.iterate() |y| { assert x[*y] == *y; }
// Call a parameterized function // Call a parameterized function
assert length(x) == vec::len(x); assert length(x) == vec::len(x);
// Call a parameterized function, with type arguments that require // Call a parameterized function, with type arguments that require
@ -39,7 +41,7 @@ fn main() {
// Now try it with a type that *needs* to be borrowed // Now try it with a type that *needs* to be borrowed
let z = [0,1,2,3]/_; let z = [0,1,2,3]/_;
// Call a method // Call a method
for z.iterate() |y| { assert z[y] == y; } for z.iterate() |y| { assert z[*y] == *y; }
// Call a parameterized function // Call a parameterized function
assert length::<int, &[int]>(z) == vec::len(z); assert length::<int, &[int]>(z) == vec::len(z);
} }

View file

@ -1,5 +1,7 @@
fn main() { fn main() {
let mut sum = 0; let mut sum = 0;
for vec::each(~[1, 2, 3, 4, 5]) |x| { sum += x; } for vec::each(~[1, 2, 3, 4, 5]) |x| {
sum += *x;
}
assert (sum == 15); assert (sum == 15);
} }

View file

@ -3,8 +3,8 @@ fn main() {
let v = ~[-1f, 0f, 1f, 2f, 3f]; let v = ~[-1f, 0f, 1f, 2f, 3f];
// Statement form does not require parentheses: // Statement form does not require parentheses:
do vec::iter(v) |i| { for vec::each(v) |i| {
log(info, i); log(info, *i);
} }
// Usable at all: // Usable at all:

View file

@ -1,6 +1,6 @@
fn want_slice(v: &[int]) -> int { fn want_slice(v: &[int]) -> int {
let mut sum = 0; let mut sum = 0;
for vec::each(v) |i| { sum += i; } for vec::each(v) |i| { sum += *i; }
return sum; return sum;
} }

View file

@ -7,7 +7,7 @@ fn main() {
loop { i += 1; if i == 20 { break; } } loop { i += 1; if i == 20 { break; } }
assert (i == 20); assert (i == 20);
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
if x == 3 { break; } assert (x <= 3); if *x == 3 { break; } assert (*x <= 3);
} }
i = 0; i = 0;
while i < 10 { i += 1; if i % 2 == 0 { loop; } assert (i % 2 != 0); } while i < 10 { i += 1; if i % 2 == 0 { loop; } assert (i % 2 != 0); }
@ -17,7 +17,7 @@ fn main() {
if i >= 10 { break; } if i >= 10 { break; }
} }
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
if x % 2 == 0 { loop; } if *x % 2 == 0 { loop; }
assert (x % 2 != 0); assert (*x % 2 != 0);
} }
} }

View file

@ -6,7 +6,7 @@ trait sum {
impl &[int]: sum { impl &[int]: sum {
fn sum() -> int { fn sum() -> int {
let mut sum = 0; let mut sum = 0;
for vec::each(self) |e| { sum += e; } for vec::each(self) |e| { sum += *e; }
return sum; return sum;
} }
} }