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.is_empty();
// Iterate over a vector
// Iterate over a vector, obtaining a pointer to each element
for crayons.each |crayon| {
let delicious_crayon_wax = unwrap_crayon(crayon);
eat_crayon_wax(delicious_crayon_wax);
}
// 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];
// 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
functions to simulate control structures like `if` and
`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;
while n < v.len() {
op(v[n]);
op(&v[n]);
n += 1;
}
}
~~~~
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.
The reason we pass in a *pointer* to an integer rather than the
integer itself is that this is how the actual `each()` function for
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) { }
each(~[1, 2, 3], |n| {
debug!("%i", n);
do_some_work(n);
debug!("%i", *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:
~~~~
# fn each(v: ~[int], op: fn(int)) {}
# fn each(v: ~[int], op: fn(v: &int)) { }
# fn do_some_work(i: int) { }
do each(~[1, 2, 3]) |n| {
debug!("%i", n);
do_some_work(n);
debug!("%i", *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`:
~~~~
fn each(v: ~[int], op: fn(int) -> bool) {
fn each(v: ~[int], op: fn(v: &int) -> bool) {
let mut n = 0;
while n < v.len() {
if !op(v[n]) {
if !op(&v[n]) {
break;
}
n += 1;
@ -1478,7 +1482,7 @@ And using this function to iterate over a vector:
# use each = vec::each;
# use println = io::println;
each(~[2, 4, 8, 5, 16], |n| {
if n % 2 != 0 {
if *n % 2 != 0 {
println(~"found odd number!");
false
} else { true }
@ -1495,7 +1499,7 @@ to the next iteration, write `again`.
# use each = vec::each;
# use println = io::println;
for each(~[2, 4, 8, 5, 16]) |n| {
if n % 2 != 0 {
if *n % 2 != 0 {
println(~"found odd number!");
break;
}
@ -1511,7 +1515,7 @@ function, not just the loop body.
# use each = vec::each;
fn contains(v: ~[int], elt: int) -> bool {
for each(v) |x| {
if (x == elt) { return true; }
if (*x == elt) { return true; }
}
false
}
@ -1529,9 +1533,9 @@ every type they apply to. Thus, Rust allows functions and datatypes to have
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 = ~[];
for vector.each |element| {
for vec::each(vector) |element| {
vec::push(accumulator, function(element));
}
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
(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
@ -1686,12 +1695,12 @@ generalized sequence types is:
~~~~
trait Seq<T> {
fn len() -> uint;
fn iter(fn(T));
fn iter(b: fn(v: &T));
}
impl<T> ~[T]: Seq<T> {
fn len() -> uint { vec::len(self) }
fn iter(b: fn(T)) {
for self.each |elt| { b(elt); }
fn iter(b: fn(v: &T)) {
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 pipes::{Port, Chan};
fn stringifier(channel: DuplexStream<~str, uint>) {
fn stringifier(channel: &DuplexStream<~str, uint>) {
let mut value: uint;
loop {
value = channel.recv();
@ -2210,7 +2219,7 @@ Here is the code for the parent task:
# use std::comm::DuplexStream;
# use pipes::{Port, Chan};
# use task::spawn;
# fn stringifier(channel: DuplexStream<~str, uint>) {
# fn stringifier(channel: &DuplexStream<~str, uint>) {
# let mut value: uint;
# loop {
# value = channel.recv();
@ -2223,7 +2232,7 @@ Here is the code for the parent task:
let (from_child, to_child) = DuplexStream();
do spawn || {
stringifier(to_child);
stringifier(&to_child);
};
from_child.send(22u);

View File

@ -1502,7 +1502,7 @@ fn print_source(s: source) {
print(io::with_str_writer(|writer| {
let mut list = ~" >> ";
do vec::iteri(pks) |i, pk| {
for vec::eachi(pks) |i, pk| {
if str::len(list) > 78u {
writer.write_line(list);
list = ~" >> ";
@ -1518,16 +1518,17 @@ fn cmd_list(c: &cargo) {
sync(c);
if vec::len(c.opts.free) >= 3u {
do vec::iter_between(c.opts.free, 2u, vec::len(c.opts.free)) |name| {
if !valid_pkg_name(name) {
error(fmt!("'%s' is an invalid source name", name));
let v = vec::view(c.opts.free, 2u, vec::len(c.opts.free));
for vec::each(v) |name| {
if !valid_pkg_name(*name) {
error(fmt!("'%s' is an invalid source name", *name));
} else {
match c.sources.find(name) {
match c.sources.find(*name) {
Some(source) => {
print_source(source);
}
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",
aux_output_dir_name(config, testfile).to_str()];
do vec::iter(props.aux_builds) |rel_ab| {
let abs_ab = config.aux_base.push_rel(&Path(rel_ab));
for vec::each(props.aux_builds) |rel_ab| {
let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
let aux_args =
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
|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)]
pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
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]); }
}
}
@ -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] {
do build_sized(v.len()) |push| {
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_unsafe, transmute_immut_unsafe;
export copy_lifetime;
export copy_lifetime, copy_lifetime_vec;
#[abi = "rust-intrinsic"]
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.
unsafe fn copy_lifetime_to_unsafe<S,T>(_ptr: &a/S, +ptr: *T) -> &a/T {
transmute(ptr)
#[inline(always)]
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] = ~[];
for vec::each(eithers) |elt| {
match elt {
match *elt {
Left(l) => vec::push(result, l),
_ => { /* fallthrough */ }
}
@ -47,7 +47,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| {
match elt {
match *elt {
Right(r) => vec::push(result, r),
_ => { /* fallthrough */ }
}
@ -67,7 +67,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| {
match elt {
match *elt {
Left(l) => vec::push(lefts, l),
Right(r) => vec::push(rights, r)
}

View File

@ -390,7 +390,9 @@ impl &SipState : Streaming {
fn result_str() -> ~str {
let r = self.result_bytes();
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
}
@ -483,7 +485,9 @@ fn test_siphash() {
fn to_hex_str(r: &[u8]/8) -> ~str {
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;
}

View File

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

View File

@ -300,146 +300,3 @@ pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
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)] {
let mut pairs = ~[];
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;
vec::push(pairs, (copy vs[0], copy vs[1]));
}
@ -893,7 +893,7 @@ mod tests {
let e = env();
assert vec::len(e) > 0u;
for vec::each(e) |p| {
let (n, v) = copy p;
let (n, v) = copy *p;
log(debug, n);
let v2 = getenv(n);
// 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
assert (vec::len(dirs) > 0u);
for vec::each(dirs) |dir| { log(debug, dir); }
for vec::each(dirs) |dir| {
log(debug, *dir);
}
}
#[test]

View File

@ -158,7 +158,7 @@ impl ReprVisitor {
fn write_escaped_slice(slice: &str) {
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_char('"');
@ -563,7 +563,7 @@ impl ReprPrinterWrapper {
let vec_repr = *vec_repr_ptr;
let data_ptr = ptr::to_unsafe_ptr(&(*vec_repr).unboxed.data);
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_char('"');
@ -686,7 +686,7 @@ impl ReprPrinterWrapper : TyVisitor {
self.printer.writer.write_char('"');
let slice_ptr: *&str = transmute(copy self.printer.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_char('"');

View File

@ -267,7 +267,7 @@ impl<T: Copy, E: Copy> Result<T, E> {
* }
*/
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] = ~[];
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 tmps = ~[];
for vec::each(args) |arg| {
let t = @copy arg;
let t = @copy *arg;
vec::push(tmps, t);
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 = ~[];
for vec::each(es) |e| {
let (k,v) = copy e;
let (k,v) = copy *e;
let t = @(fmt!("%s=%s", k, v));
vec::push(tmps, t);
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) => {
let mut blk : ~[u8] = ~[];
for vec::each(es) |e| {
let (k,v) = e;
let (k,v) = *e;
let t = fmt!("%s=%s", k, v);
let mut v : ~[u8] = ::cast::reinterpret_cast(&t);
blk += v;

View File

@ -17,7 +17,7 @@ trait SendMap<K:Eq Hash, V: Copy> {
pure fn len(&const self) -> uint;
pure fn is_empty(&const self) -> 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_value_ref(&self, blk: fn(v: &V) -> bool);
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| {
let mut broke = false;
do slot.iter |bucket| {
@ -323,12 +323,12 @@ mod linear {
}
}
pure fn each_key_ref(&self, blk: fn(k: &K) -> bool) {
self.each_ref(|k, _v| blk(k))
pure fn each_key(&self, blk: fn(k: &K) -> bool) {
self.each(|k, _v| blk(k))
}
pure fn each_value_ref(&self, blk: fn(v: &V) -> bool) {
self.each_ref(|_k, v| blk(v))
pure fn each_value(&self, blk: fn(v: &V) -> bool) {
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]
@ -438,8 +422,8 @@ mod test {
}
let mut observed = 0;
for m.each |k, v| {
assert v == k*2;
observed |= (1 << k);
assert *v == *k * 2;
observed |= (1 << *k);
}
assert observed == 0xFFFF_FFFF;
}

View File

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

View File

@ -76,12 +76,8 @@ export zip, zip_slice;
export swap;
export reverse;
export reversed;
export iter, iter_between, each, eachi, reach, reachi;
export each_ref, each_mut_ref, each_const_ref;
export each, each_mut, each_const, eachi, reach, reachi;
export iter2;
export iteri;
export riter;
export riteri;
export permute;
export windowed;
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] {
let mut result = ~[];
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
}
@ -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] {
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
}
@ -809,7 +805,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
-> ~[U] {
let mut result = ~[];
for each(v) |elem| {
match f(elem) {
match f(*elem) {
None => {/* no-op */ }
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] {
let mut result = ~[];
for each(v) |elem| {
if f(elem) { unsafe { push(result, elem); } }
if f(*elem) { unsafe { push(result, *elem); } }
}
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] {
let mut r = ~[];
for each(v) |inner| { unsafe { push_all(r, inner); } }
for each(v) |inner| { unsafe { push_all(r, *inner); } }
move r
}
@ -849,7 +845,7 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
let mut first = true;
for each(v) |inner| {
if first { first = false; } else { unsafe { push(r, sep); } }
unsafe { push_all(r, inner) };
unsafe { push_all(r, *inner) };
}
move r
}
@ -857,8 +853,8 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
/// Reduce a vector from left to right
pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
let mut accum = z;
do iter(v) |elt| {
accum = p(accum, elt);
for each(v) |elt| {
accum = p(accum, *elt);
}
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
pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
let mut accum = z;
do riter(v) |elt| {
for reach(v) |elt| {
accum = p(elt, 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.
*/
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;
}
@ -905,7 +901,7 @@ pure fn any2<T, U>(v0: &[T], v1: &[U],
* If the vector contains no elements then true is returned.
*/
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;
}
@ -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
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;
}
/// Returns the number of elements that are equal to a given value
pure fn count<T: Eq>(v: &[T], x: T) -> uint {
let mut cnt = 0u;
for each(v) |elt| { if x == elt { cnt += 1u; } }
for each(v) |elt| { if x == *elt { cnt += 1u; } }
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]) {
let mut as_ = ~[], bs = ~[];
for each(v) |p| {
let (a, b) = p;
let (a, b) = *p;
unsafe {
vec::push(as_, a);
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; }
}
/// Returns a vector with the order of elements reversed
pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
let mut rs: ~[T] = ~[];
@ -1163,50 +1158,13 @@ pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
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
*
* Return true to continue, false to break.
*/
#[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
// 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;
while n > 0u {
unsafe {
if !f(*p) { break; }
let q = cast::copy_lifetime_vec(v, &*p);
if !f(q) { break; }
p = ptr::offset(p, 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
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[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 n = v.len();
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
/// not* have mutable contents.
#[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 n = v.len();
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`.
*
@ -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]] {
let mut ww = ~[];
assert 1u <= nn;
vec::iteri (xx, |ii, _x| {
for vec::eachi (xx) |ii, _x| {
let len = vec::len(xx);
if ii+nn <= len unsafe {
vec::push(ww, vec::slice(xx, ii, ii+nn));
}
});
}
move ww
}
@ -1626,10 +1529,6 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
trait ImmutableVector<T> {
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 mapi<U>(f: fn(uint, 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
#[inline]
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
#[inline]
pure fn map<U>(f: fn(T) -> U) -> ~[U] { map(self, f) }
@ -2013,7 +1880,13 @@ mod bytes {
// required in the slice.
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)) }
}
@ -2465,55 +2338,57 @@ mod tests {
}
#[test]
fn test_iter_empty() {
let mut i = 0;
iter::<int>(~[], |_v| i += 1);
assert i == 0;
fn test_each_empty() {
for each::<int>(~[]) |_v| {
fail; // should never be executed
}
}
#[test]
fn test_iter_nonempty() {
let mut i = 0;
iter(~[1, 2, 3], |v| i += v);
for each(~[1, 2, 3]) |v| {
i += *v;
}
assert i == 6;
}
#[test]
fn test_iteri() {
let mut i = 0;
iteri(~[1, 2, 3], |j, v| {
for eachi(~[1, 2, 3]) |j, v| {
if i == 0 { assert v == 1; }
assert j + 1u == v as uint;
i += v;
});
}
assert i == 6;
}
#[test]
fn test_riter_empty() {
let mut i = 0;
riter::<int>(~[], |_v| i += 1);
assert i == 0;
fn test_reach_empty() {
for reach::<int>(~[]) |_v| {
fail; // should never execute
}
}
#[test]
fn test_riter_nonempty() {
let mut i = 0;
riter(~[1, 2, 3], |v| {
for reach(~[1, 2, 3]) |v| {
if i == 0 { assert v == 3; }
i += v
});
}
assert i == 6;
}
#[test]
fn test_riteri() {
fn test_reachi() {
let mut i = 0;
riteri(~[0, 1, 2], |j, v| {
for reachi(~[0, 1, 2]) |j, v| {
if i == 0 { assert v == 2; }
assert j == v as uint;
i += v;
});
}
assert i == 3;
}

View File

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

View File

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

View File

@ -179,7 +179,7 @@ fn to_writer_pretty(wr: io::Writer, j: Json, indent: uint) {
fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\"";
do str::chars_iter(s) |c| {
for str::chars_each(s) |c| {
match c {
'"' => escaped += ~"\\\"",
'\\' => escaped += ~"\\\\",
@ -834,8 +834,8 @@ mod tests {
fn mk_dict(items: &[(~str, Json)]) -> Json {
let d = map::str_hash();
do vec::iter(items) |item| {
let (key, value) = copy item;
for vec::each(items) |item| {
let (key, value) = copy *item;
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>(
items: &[(K, V)]) -> HashMap<K, V> {
let map = HashMap();
do vec::iter(items) |item| {
let (key, value) = item;
for vec::each(items) |item| {
match *item {
(key, value) => {
map.insert(key, value);
}
}
}
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) {
unsafe {
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) {
unsafe {
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) {
unsafe {
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) {
unsafe {
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) {
unsafe {
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) {
unsafe {
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: %?",
localhost_name, vec::len(results)));
for vec::each(results) |r| {
let ipv_prefix = match r {
let ipv_prefix = match *r {
Ipv4(_) => ~"IPv4",
Ipv6(_) => ~"IPv6"
};
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
// 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)) {
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) {
f(e)
}

View File

@ -66,7 +66,7 @@ fn sha1() -> Sha1 {
fn add_input(st: &Sha1State, msg: &[u8]) {
assert (!st.computed);
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.len_low += 8u32;
if st.len_low == 0u32 {
@ -161,7 +161,7 @@ fn sha1() -> Sha1 {
fn mk_result(st: &Sha1State) -> ~[u8] {
if !(*st).computed { pad_msg(st); (*st).computed = true; }
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 a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;
@ -240,7 +240,9 @@ fn sha1() -> Sha1 {
fn result_str() -> ~str {
let rr = mk_result(&self);
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;
}
}

View File

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

View File

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

View File

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

View File

@ -227,7 +227,7 @@ fn print_failures(st: ConsoleTestState) {
let failures = vec::map(failures, |test| test.name);
let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures);
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 mut tests = ~[];
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};
tests += ~[test];
vec::push(tests, test);
}
tests
};
@ -557,7 +557,11 @@ mod tests {
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",
~"Monday",
~"Tuesday",
@ -1031,9 +1031,11 @@ mod tests {
~"Thursday",
~"Friday",
~"Saturday"
]/_.iter(|day| assert test(day, ~"%A"));
]) |day| {
assert test(*day, ~"%A");
}
[
for vec::each([
~"Sun",
~"Mon",
~"Tue",
@ -1041,9 +1043,11 @@ mod tests {
~"Thu",
~"Fri",
~"Sat"
]/_.iter(|day| assert test(day, ~"%a"));
]) |day| {
assert test(*day, ~"%a");
}
[
for vec::each([
~"January",
~"February",
~"March",
@ -1056,9 +1060,11 @@ mod tests {
~"October",
~"November",
~"December"
]/_.iter(|day| assert test(day, ~"%B"));
]) |day| {
assert test(*day, ~"%B");
}
[
for vec::each([
~"Jan",
~"Feb",
~"Mar",
@ -1071,7 +1077,9 @@ mod tests {
~"Oct",
~"Nov",
~"Dec"
]/_.iter(|day| assert test(day, ~"%b"));
]) |day| {
assert test(*day, ~"%b");
}
assert test(~"19", ~"%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 p = extend(cx, ident);
// 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) {

View File

@ -429,7 +429,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
match vi.node {
view_item_use(_, _, id) => vfn(id),
view_item_import(vps) | view_item_export(vps) => {
do vec::iter(vps) |vp| {
for vec::each(vps) |vp| {
match vp.node {
view_path_simple(_, _, _, 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]) {
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,
@ -499,33 +501,33 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
match fk {
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(self_id);
vfn(parent_id.node);
}
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(self_id);
vfn(parent_id.node);
}
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) => {
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_fn_block(capture_clause) => {
visit::fk_anon(_, capture_clause) |
visit::fk_fn_block(capture_clause) => {
for vec::each(*capture_clause) |clause| {
vfn(clause.id);
}
}
}
do vec::iter(d.inputs) |arg| {
for vec::each(d.inputs) |arg| {
vfn(arg.id)
}
},

View File

@ -228,7 +228,7 @@ fn finish<T: qq_helper>
let mut state = active;
let mut i = 0u, j = 0u;
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) {
assert ch == '$';
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| {
res = match res {
leaf(_) => return res,/* end of the line */
seq(new_ms, _) => new_ms[idx]
seq(new_ms, _) => new_ms[*idx]
}
}
return res;

View File

@ -1674,7 +1674,7 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
word(s.s, ~":");
for vec::each(*bounds) |bound| {
nbsp(s);
match bound {
match *bound {
ast::bound_copy => word(s.s, ~"Copy"),
ast::bound_send => word(s.s, ~"Send"),
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>) {
for vec::each(*bounds) |bound| {
match bound {
match *bound {
bound_trait(t) => v.visit_ty(t, e, v),
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!
fn sanitize(s: ~str) -> ~str {
let mut result = ~"";
do str::chars_iter(s) |c| {
for str::chars_each(s) |c| {
match c {
'@' => result += ~"_sbox_",
'~' => 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,
data: crate_metadata) {
p(cstore).metas.insert(cnum, data);
do vec::iter(decoder::get_crate_module_paths(cstore.intr, data)) |dp| {
let (did, path) = dp;
for vec::each(decoder::get_crate_module_paths(cstore.intr, data)) |dp| {
let (did, path) = *dp;
let d = {crate: cnum, node: did.node};
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) {
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);
}
}
@ -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
// maybe we should only ever handle the real type signatures.
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; }
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]) {
for vec::each(*bs) |bound| {
match bound {
match *bound {
ty::bound_send => w.write_char('S'),
ty::bound_copy => w.write_char('C'),
ty::bound_const => w.write_char('K'),

View File

@ -108,7 +108,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
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;
match cap_map.find(fvar_def_id) {
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);
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>) {
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 {
let t = ty::node_id_to_type(cx.tcx, id);
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
// range)
enum opt {
enum Opt {
lit(@ast::expr),
var(/* disr val */int, /* variant dids */{enm: def_id, var: def_id}),
range(@ast::expr, @ast::expr)
}
fn opt_eq(tcx: ty::ctxt, a: opt, b: opt) -> bool {
match (a, b) {
fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool {
match (*a, *b) {
(lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0,
(range(a1, a2), range(b1, b2)) => {
const_eval::compare_lit_exprs(tcx, a1, b1) == 0 &&
@ -145,11 +145,11 @@ enum opt_result {
single_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 ccx = bcx.ccx();
let mut bcx = bcx;
match o {
match *o {
lit(lit_expr) => {
let datumblock = expr::trans_to_datum(bcx, lit_expr);
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 variants = ty::enum_variants(tcx, vdef.enm);
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)
-> ~[@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| {
match p.node {
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,
vec::from_elem(variant_size,
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) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) {
if opt_eq(tcx, &variant_opt(tcx, p.id), opt) {
Some(~[])
} else {
None
}
}
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) => {
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);
@ -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, _) => {
let mut pats = ~[];
for vec::each(fields) |fname| {
match fpats.find(|p| p.ident == fname) {
match fpats.find(|p| p.ident == *fname) {
None => vec::push(pats, dummy),
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 add_to_set(tcx: ty::ctxt, set: &DVec<opt>, val: opt) {
if set.any(|l| opt_eq(tcx, l, val)) {return;}
fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] {
fn add_to_set(tcx: ty::ctxt, set: &DVec<Opt>, val: Opt) {
if set.any(|l| opt_eq(tcx, &l, &val)) {return;}
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));
for vec::each(m) |br| {
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 best_col = 0u;
let mut i = 0u;
for vec::each(scores) |score| {
let score = *score;
// Irrefutable columns always go first, they'd only be duplicated in
// the branches.
if score == 0u { return i; }
@ -959,7 +961,7 @@ fn compile_submatch(bcx: block,
}
}
for vec::each(opts) |o| {
match o {
match *o {
range(_, _) => { kind = compare; break }
_ => ()
}
@ -1037,7 +1039,7 @@ fn compile_submatch(bcx: block,
let mut size = 0u;
let mut unpacked = ~[];
match opt {
match *opt {
var(_, vdef) => {
let args = extract_variant_args(opt_cx, pat_id, vdef, val);
size = args.vals.len();
@ -1087,7 +1089,7 @@ fn trans_alt_inner(scope_cx: block,
}
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");
// 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};
vec::push(arm_datas, arm_data);
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 llforeign: ValueRef =
get_simple_extern_fn(cx, externs, llmod, name, n);
let mut call_args: ~[ValueRef] = ~[];
for vec::each(args) |a| {
vec::push(call_args, a);
}
return Call(cx, llforeign, call_args);
return Call(cx, llforeign, args);
}
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));
AddCase(llswitch, C_int(ccx, variant.disr_val), variant_cx.llbb);
let variant_cx =
iter_variant(variant_cx, llunion_a_ptr, variant,
iter_variant(variant_cx, llunion_a_ptr, *variant,
substs.tps, tid, f);
Br(variant_cx, next_cx.llbb);
}
@ -748,7 +744,7 @@ fn need_invoke(bcx: block) -> bool {
match cur.kind {
block_scope(inf) => {
for vec::each(inf.cleanups) |cleanup| {
match cleanup {
match *cleanup {
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
if cleanup_type == normal_exit_and_unwind {
return true;
@ -1020,9 +1016,9 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
match d.node {
ast::decl_local(locals) => {
for vec::each(locals) |local| {
bcx = init_local(bcx, local);
bcx = init_local(bcx, *local);
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;
if bcx.unreachable && !no_lpads { return bcx; }
let mut bcx = bcx;
do vec::riter(cleanups) |cu| {
for vec::reach(cleanups) |cu| {
match cu {
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => {
// 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, _) => {
match d.node {
ast::decl_local(locals) => {
for vec::each(locals) |local| { it(local); }
for vec::each(locals) |local| {
it(*local);
}
}
_ => {/* fall through */ }
}
@ -1789,7 +1787,7 @@ fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
match variant.node.kind {
ast::tuple_variant_kind(args) if args.len() > 0 => {
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);
}
ast::tuple_variant_kind(_) => {
@ -1910,7 +1908,9 @@ fn trans_trait(ccx: @crate_ctxt, tps: ~[ast::ty_param],
// and control visibility.
fn trans_mod(ccx: @crate_ctxt, m: ast::_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 {
@ -2355,10 +2355,11 @@ fn gather_local_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
ast::item_fn(*) => {
let attr_metas = attr::attr_metas(
attr::find_attrs_by_name(item.attrs, ~"rt"));
do vec::iter(attr_metas) |attr_meta| {
match attr::get_meta_item_list(attr_meta) {
for vec::each(attr_metas) |attr_meta| {
match attr::get_meta_item_list(*attr_meta) {
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,
node: item.id});
}
@ -2413,8 +2414,8 @@ fn gather_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
let expected_rtcalls =
~[~"exchange_free", ~"exchange_malloc", ~"fail_", ~"free", ~"malloc"];
for vec::each(expected_rtcalls) |name| {
if !ccx.rtcalls.contains_key(name) {
fail fmt!("no definition for runtime call %s", name);
if !ccx.rtcalls.contains_key(*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.
fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> 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");
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 {
ArgExprs(arg_exprs) => {
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, {
trans_arg_expr(bcx, arg_tys[i], arg_expr, &mut temp_cleanups,
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
// temporary cleanups, as they are only needed if argument construction
// should fail (for example, cleanup of copy mode args).
do vec::iter(temp_cleanups) |c| {
revoke_clean(bcx, c)
for vec::each(temp_cleanups) |c| {
revoke_clean(bcx, *c)
}
return {bcx: bcx, args: llargs, retslot: llretslot};

View File

@ -209,7 +209,7 @@ fn store_environment(bcx: block,
// Copy expr values into boxed bindings.
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));
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};
}
@ -251,8 +253,8 @@ fn build_closure(bcx0: block,
// Package up the captured upvars
let mut env_vals = ~[];
do vec::iter(cap_vars) |cap_var| {
debug!("Building closure: captured variable %?", cap_var);
for vec::each(cap_vars) |cap_var| {
debug!("Building closure: captured variable %?", *cap_var);
let datum = expr::trans_local_var(bcx, id, cap_var.def);
match cap_var.mode {
capture::cap_ref => {
@ -316,7 +318,7 @@ fn load_environment(fcx: fn_ctxt,
// Populate the upvars from the environment.
let mut i = 0u;
do vec::iter(cap_vars) |cap_var| {
for vec::each(cap_vars) |cap_var| {
match cap_var.mode {
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 {
let mut r = ~"", first = true;
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; }
else { r += ~"::"; }
r += sess.str_of(s);
} }
}
}
}
r
}
@ -1269,8 +1271,8 @@ fn find_vtable(tcx: ty::ctxt, ps: &param_substs,
// somewhat awkward
for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; }
for vec::each(*bounds) |bound| {
match bound { ty::bound_trait(_) => vtable_off += 1u, _ => () }
for vec::each(**bounds) |bound| {
match *bound { ty::bound_trait(_) => vtable_off += 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| {
debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s);
bcx = trans_stmt(bcx, **s);
}
match b.node.expr {
Some(e) => {
@ -85,7 +85,7 @@ fn join_blocks(parent_bcx: block, in_cxs: ~[block]) -> block {
let mut reachable = false;
for vec::each(in_cxs) |bcx| {
if !bcx.unreachable {
Br(bcx, out.llbb);
Br(*bcx, out.llbb);
reachable = true;
}
}

View File

@ -1027,7 +1027,9 @@ fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: Dest) -> block {
let mut bcx = bcx;
let addr = match dest {
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;
}
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);
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;
}

View File

@ -165,9 +165,9 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
} else {
let mut field_off = off;
for vec::each(tys) |ty| {
field_off = align(field_off, ty);
classify(ty, cls, i, field_off);
field_off += ty_size(ty);
field_off = align(field_off, *ty);
classify(*ty, cls, i, field_off);
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 {
let mut len = 1u;
for vec::each(cls) |c| {
if c != sseup_class {
if *c != sseup_class {
break;
}
len += 1u;
@ -377,7 +377,7 @@ fn x86_64_tys(atys: ~[TypeRef],
let mut arg_tys = ~[];
let mut attrs = ~[];
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(attrs, attr);
}
@ -410,7 +410,7 @@ fn decl_x86_64_fn(tys: x86_64_tys,
let fnty = T_fn(atys, rty);
let llfn = decl(fnty);
do vec::iteri(tys.attrs) |i, a| {
for vec::eachi(tys.attrs) |i, a| {
match a {
option::Some(attr) => {
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");
match tys.x86_64_tys {
Some(x86_64) => {
do vec::iteri(x86_64.attrs) |i, a| {
for vec::eachi(x86_64.attrs) |i, a| {
match a {
Some(attr) => {
llvm::LLVMAddInstrAttribute(
@ -771,9 +771,9 @@ fn trans_foreign_mod(ccx: @crate_ctxt,
let tys = c_stack_tys(ccx, id);
if attr::attrs_contains_name(foreign_item.attrs,
~"rust_stack") {
build_direct_fn(ccx, llwrapfn, foreign_item, tys, cc);
build_direct_fn(ccx, llwrapfn, *foreign_item, tys, cc);
} 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);
}
} else {

View File

@ -35,7 +35,7 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
if method.tps.len() == 0u {
let llfn = get_item_val(ccx, method.id);
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| {
let mut v = ~[];
for vec::each(*bounds) |bound| {
match bound {
match *bound {
ty::bound_trait(_) => {
vec::push(v, meth::vtable_id(ccx, vts[i]));
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) {
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) {
if !traverse_exports(cx, m.view_items) {
// 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_foreign_mod(nm) => {
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) => {

View File

@ -323,7 +323,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
ty::ty_tup(elts) => {
let mut s = ~[shape_struct], sub = ~[];
for vec::each(elts) |elt| {
sub += shape_of(ccx, elt);
sub += shape_of(ccx, *elt);
}
add_substr(s, sub);
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] {
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;
}
@ -391,10 +391,10 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
while i < ccx.shape_cx.tag_order.len() {
let {did, substs} = ccx.shape_cx.tag_order[i];
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];
let variant_shape = shape_of_variant(ccx, v);
let variant_shape = shape_of_variant(ccx, *v);
add_substr(data, variant_shape);
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);
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.
assert !vec::any(*variants, |v| {
@ -482,13 +482,13 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
let mut bounded = true;
let mut min_size = 0u, min_align = 0u;
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
// conservatively assume that (int, T) has minimum size 0,
// when in fact it has minimum size sizeof(int).
bounded = false;
} 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_align += llalign_of_pref(ccx, llty);
}
@ -553,8 +553,8 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
for vec::each(largest_variants) |vid| {
// We increment a "virtual data pointer" to compute the size.
let mut lltys = ~[];
for vec::each(variants[vid].args) |typ| {
lltys += ~[type_of::type_of(ccx, typ)];
for vec::each(variants[*vid].args) |typ| {
lltys += ~[type_of::type_of(ccx, *typ)];
}
let llty = trans::common::T_struct(lltys);

View File

@ -335,7 +335,7 @@ fn write_content(bcx: block,
vec::push(temp_cleanups, lleltptr);
}
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| {
revoke_clean(bcx, cleanup);
revoke_clean(bcx, *cleanup);
}
return bcx;

View File

@ -158,7 +158,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
ty::ty_tup(elts) => {
let mut tys = ~[];
for vec::each(elts) |elt| {
vec::push(tys, type_of(cx, elt));
vec::push(tys, type_of(cx, *elt));
}
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) {
// 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_ {
type_needs_inner(cx, use_, ty, @Nil);
return;
@ -144,7 +144,7 @@ fn type_needs_inner(cx: ctx, use_: uint, ty: ty::t,
let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
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);
}
}
@ -247,14 +247,16 @@ fn mark_for_expr(cx: ctx, e: @expr) {
node_type_needs(cx, use_tydesc, val.id);
}
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 {
expl(by_move) | expl(by_copy) | expl(by_val) => {
type_needs(cx, use_repr, a.ty);
}
_ => ()
}
})
}
}
expr_match(*) | expr_block(_) | expr_if(*) |
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 {
let mut kind = kind_noncopyable();
for vec::each(*bounds) |bound| {
match bound {
match *bound {
bound_copy => {
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 {
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
}
pure fn hash_substs(h: uint, substs: &substs) -> uint {

View File

@ -57,7 +57,6 @@ use std::smallintmap;
use std::map;
use std::map::{HashMap, int_hash};
use std::serialization::{serialize_uint, deserialize_uint};
use vec::each;
use syntax::print::pprust::*;
use util::ppaux::{ty_to_str, tys_to_str, region_to_str,
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 bounds = tcx.ty_param_bounds.get(param_ty.def_id.node);
for vec::each(*bounds) |bound| {
let bound_t = match bound {
let bound_t = match *bound {
ty::bound_trait(bound_t) => bound_t,
ty::bound_copy | ty::bound_send |

View File

@ -49,7 +49,7 @@ fn lookup_vtables(fcx: @fn_ctxt,
let mut result = ~[], i = 0u;
for substs.tps.each |ty| {
for vec::each(*bounds[i]) |bound| {
match bound {
match *bound {
ty::bound_trait(i_ty) => {
let i_ty = ty::subst(tcx, substs, 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}) => {
let mut n_bound = 0;
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_owned => {
/* ignore */
@ -215,7 +215,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
// unify it with trait_ty in order to get all
// the ty vars sorted out.
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, _, _) => {
// Not the trait we're looking for
if id != trait_id { loop; }
@ -271,8 +271,8 @@ fn lookup_vtable(fcx: @fn_ctxt,
debug!("(checking vtable) @2 relating trait \
ty %s to of_ty %s",
fcx.infcx().ty_to_str(trait_ty),
fcx.infcx().ty_to_str(of_ty));
let of_ty = ty::subst(tcx, &substs, of_ty);
fcx.infcx().ty_to_str(*of_ty));
let of_ty = ty::subst(tcx, &substs, *of_ty);
relate_trait_tys(fcx, expr, trait_ty, of_ty);
// 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 {
ast::expr_fn(_, 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);
// 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, _}) => {
compare_impl_method(
ccx.tcx, span, impl_m, vec::len(tps),
trait_m, tpt.substs, selfty);
*trait_m, tpt.substs, selfty);
}
None => {
// 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]) {
do vec::iter(sections) |section| {
write_section(ctxt, section);
for vec::each(sections) |section| {
write_section(ctxt, *section);
}
}
@ -609,7 +609,9 @@ fn write_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(~"");
}
@ -666,7 +668,9 @@ fn write_trait(ctxt: Ctxt, doc: doc::TraitDoc) {
}
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) {

View File

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

View File

@ -73,7 +73,10 @@ fn run(args: &[~str]) {
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");
to_child.send(stop);
move_out!(to_child);

View File

@ -70,7 +70,10 @@ fn run(args: &[~str]) {
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");
to_child.send(stop);
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);
let result = comm::recv(from_child);
let end = std::time::precise_time_s();

View File

@ -9,8 +9,8 @@ fn print_complements() {
let all = ~[Blue, Red, Yellow];
for vec::each(all) |aa| {
for vec::each(all) |bb| {
io::println(show_color(aa) + ~" + " + show_color(bb) +
~" -> " + show_color(transform(aa,bb)));
io::println(show_color(*aa) + ~" + " + show_color(*bb) +
~" -> " + show_color(transform(*aa, *bb)));
}
}
}
@ -171,7 +171,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
// print each creature's stats
for vec::each(report) |rep| {
io::println(rep);
io::println(*rep);
}
// 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) {
start => {
do vec::iter (child_chs) |child_ch| {
comm::send(child_ch, start);
for vec::each(child_chs) |child_ch| {
comm::send(*child_ch, start);
}
}
_ => fail ~"task-perf-one-million failed (port not in start state)"

View File

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

View File

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

View File

@ -1,5 +1,6 @@
fn main() {
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 = ~[];
// Earlier versions of our type checker accepted this:
vec::iter(v, |&&inner: ~[T]| {
vec::each(v, |inner: &~[T]| {
//~^ ERROR values differ in mutability
r += inner;
r += *inner; true
});
return r;

View File

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

View File

@ -1,5 +1,7 @@
fn main() {
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);
}

View File

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

View File

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

View File

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

View File

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