Browse files

Revert "replace explicit calls to vec::each with vec::each_ref, parti…

…ally demode str"

This reverts commit 1be24f0.

Not quite ready.
  • Loading branch information...
1 parent 1be24f0 commit 8d4928f7808813de62fefcb89139bfb7382b250b @nikomatsakis nikomatsakis committed Sep 19, 2012
Showing with 600 additions and 564 deletions.
  1. +2 −2 src/compiletest/runtest.rs
  2. +3 −3 src/libcore/at_vec.rs
  3. +6 −6 src/libcore/either.rs
  4. +2 −6 src/libcore/hash.rs
  5. +2 −2 src/libcore/io.rs
  6. +1 −6 src/libcore/iter-trait/dvec.rs
  7. +5 −7 src/libcore/os.rs
  8. +1 −1 src/libcore/pipes.rs
  9. +3 −3 src/libcore/repr.rs
  10. +2 −2 src/libcore/result.rs
  11. +6 −6 src/libcore/run.rs
  12. +1 −1 src/libcore/send_map.rs
  13. +62 −72 src/libcore/str.rs
  14. +1 −1 src/libcore/to_str.rs
  15. +136 −24 src/libcore/vec.rs
  16. +5 −8 src/libstd/arc.rs
  17. +11 −11 src/libstd/getopts.rs
  18. +3 −3 src/libstd/json.rs
  19. +3 −6 src/libstd/map.rs
  20. +3 −3 src/libstd/net_ip.rs
  21. +1 −1 src/libstd/serialization.rs
  22. +5 −7 src/libstd/sha1.rs
  23. +2 −2 src/libstd/sort.rs
  24. +2 −2 src/libstd/sync.rs
  25. +2 −2 src/libstd/term.rs
  26. +23 −27 src/libstd/test.rs
  27. +8 −16 src/libstd/time.rs
  28. +2 −4 src/libsyntax/ast_map.rs
  29. +33 −35 src/libsyntax/ast_util.rs
  30. +1 −1 src/libsyntax/ext/qquote.rs
  31. +2 −2 src/libsyntax/ext/simplext.rs
  32. +2 −2 src/libsyntax/print/pprust.rs
  33. +2 −2 src/libsyntax/visit.rs
  34. +1 −1 src/rustc/back/link.rs
  35. +2 −2 src/rustc/metadata/cstore.rs
  36. +5 −7 src/rustc/metadata/encoder.rs
  37. +2 −2 src/rustc/metadata/tyencode.rs
  38. +8 −8 src/rustc/middle/capture.rs
  39. +1 −1 src/rustc/middle/check_alt.rs
  40. +4 −4 src/rustc/middle/kind.rs
  41. +1 −1 src/rustc/middle/lint.rs
  42. +3 −3 src/rustc/middle/resolve.rs
  43. +36 −38 src/rustc/middle/trans/alt.rs
  44. +39 −39 src/rustc/middle/trans/base.rs
  45. +1 −1 src/rustc/middle/trans/build.rs
  46. +3 −3 src/rustc/middle/trans/callee.rs
  47. +5 −7 src/rustc/middle/trans/closure.rs
  48. +9 −11 src/rustc/middle/trans/common.rs
  49. +4 −4 src/rustc/middle/trans/controlflow.rs
  50. +3 −7 src/rustc/middle/trans/expr.rs
  51. +13 −13 src/rustc/middle/trans/foreign.rs
  52. +2 −2 src/rustc/middle/trans/meth.rs
  53. +2 −2 src/rustc/middle/trans/monomorphize.rs
  54. +7 −13 src/rustc/middle/trans/reachable.rs
  55. +16 −16 src/rustc/middle/trans/shape.rs
  56. +4 −4 src/rustc/middle/trans/tvec.rs
  57. +3 −3 src/rustc/middle/trans/type_of.rs
  58. +12 −14 src/rustc/middle/trans/type_use.rs
  59. +14 −14 src/rustc/middle/ty.rs
  60. +1 −0 src/rustc/middle/typeck.rs
  61. +2 −2 src/rustc/middle/typeck/check/method.rs
  62. +9 −9 src/rustc/middle/typeck/check/vtable.rs
  63. +13 −13 src/rustc/middle/typeck/check/writeback.rs
  64. +2 −2 src/rustc/middle/typeck/collect.rs
  65. +4 −4 src/rustc/middle/typeck/infer/region_var_bindings.rs
  66. +5 −8 src/test/bench/graph500-bfs.rs
  67. +1 −4 src/test/bench/msgsend-pipes-shared.rs
  68. +1 −4 src/test/bench/msgsend-pipes.rs
  69. +1 −3 src/test/bench/msgsend.rs
  70. +7 −7 src/test/bench/shootout-chameneos-redux.rs
  71. +3 −3 src/test/bench/task-perf-one-million.rs
  72. +1 −1 src/test/compile-fail/block-must-not-have-result-for.rs
  73. +1 −1 src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs
  74. +1 −1 src/test/compile-fail/issue-2151.rs
  75. +1 −2 src/test/compile-fail/liveness-issue-2163.rs
  76. +2 −2 src/test/compile-fail/vec-concat-bug.rs
  77. +2 −2 src/test/run-pass/block-arg.rs
View
4 src/compiletest/runtest.rs
@@ -425,8 +425,8 @@ fn compose_and_run_compiler(
let extra_link_args = ~[~"-L",
aux_output_dir_name(config, testfile).to_str()];
- for vec::each_ref(props.aux_builds) |rel_ab| {
- let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
+ do vec::iter(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
6 src/libcore/at_vec.rs
@@ -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_ref(lhs) |x| { push(*x); }
+ for vec::each(lhs) |x| { push(x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
}
}
@@ -100,8 +100,8 @@ pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
/// Apply a function to each element of a vector and return the results
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
do build_sized(v.len()) |push| {
- for vec::each_ref(v) |elem| {
- push(f(*elem));
+ for vec::each(v) |elem| {
+ push(f(elem));
}
}
}
View
12 src/libcore/either.rs
@@ -33,8 +33,8 @@ fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
//! Extracts from a vector of either all the left values
let mut result: ~[T] = ~[];
- for vec::each_ref(eithers) |elt| {
- match *elt {
+ for vec::each(eithers) |elt| {
+ match elt {
Left(l) => vec::push(result, l),
_ => { /* fallthrough */ }
}
@@ -46,8 +46,8 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
//! Extracts from a vector of either all the right values
let mut result: ~[U] = ~[];
- for vec::each_ref(eithers) |elt| {
- match *elt {
+ for vec::each(eithers) |elt| {
+ match elt {
Right(r) => vec::push(result, r),
_ => { /* fallthrough */ }
}
@@ -66,8 +66,8 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[];
- for vec::each_ref(eithers) |elt| {
- match *elt {
+ for vec::each(eithers) |elt| {
+ match elt {
Left(l) => vec::push(lefts, l),
Right(r) => vec::push(rights, r)
}
View
8 src/libcore/hash.rs
@@ -390,9 +390,7 @@ impl &SipState : Streaming {
fn result_str() -> ~str {
let r = self.result_bytes();
let mut s = ~"";
- for vec::each_ref(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
}
@@ -485,9 +483,7 @@ fn test_siphash() {
fn to_hex_str(r: &[u8]/8) -> ~str {
let mut s = ~"";
- for vec::each_ref(*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
4 src/libcore/io.rs
@@ -450,8 +450,8 @@ fn mk_file_writer(path: &Path, flags: ~[FileFlag])
fn wb() -> c_int { O_WRONLY as c_int }
let mut fflags: c_int = wb();
- for vec::each_ref(flags) |f| {
- match *f {
+ for vec::each(flags) |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
7 src/libcore/iter-trait/dvec.rs
@@ -7,12 +7,7 @@ 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 {
- do self.swap |v| {
- vec::each(v, f);
- move v
- }
- }
+ unsafe { self.swap(|v| { vec::each(v, f); move v }) }
}
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
View
12 src/libcore/os.rs
@@ -210,8 +210,8 @@ mod global_env {
fn env() -> ~[(~str,~str)] {
let mut pairs = ~[];
- for vec::each_ref(rustrt::rust_env_pairs()) |p| {
- let vs = str::splitn_char(*p, '=', 1u);
+ for vec::each(rustrt::rust_env_pairs()) |p| {
+ let vs = str::splitn_char(p, '=', 1u);
assert vec::len(vs) == 2u;
vec::push(pairs, (copy vs[0], copy vs[1]));
}
@@ -892,8 +892,8 @@ mod tests {
fn test_env_getenv() {
let e = env();
assert vec::len(e) > 0u;
- for vec::each_ref(e) |p| {
- let (n, v) = copy *p;
+ for vec::each(e) |p| {
+ let (n, v) = copy p;
log(debug, n);
let v2 = getenv(n);
// MingW seems to set some funky environment variables like
@@ -985,9 +985,7 @@ mod tests {
// Just assuming that we've got some contents in the current directory
assert (vec::len(dirs) > 0u);
- for vec::each_ref(dirs) |dir| {
- log(debug, *dir);
- }
+ for vec::each(dirs) |dir| { log(debug, dir); }
}
#[test]
View
2 src/libcore/pipes.rs
@@ -1099,7 +1099,7 @@ impl<T: Send> PortSet<T> : Recv<T> {
pure fn peek() -> bool {
// It'd be nice to use self.port.each, but that version isn't
// pure.
- for vec::each_ref(self.ports) |p| {
+ for vec::each(self.ports) |p| {
if p.peek() { return true }
}
false
View
6 src/libcore/repr.rs
@@ -158,7 +158,7 @@ impl ReprVisitor {
fn write_escaped_slice(slice: &str) {
self.writer.write_char('"');
- for str::chars_each(slice) |ch| {
+ do str::chars_iter(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));
- for str::chars_each(slice) |ch| {
+ do str::chars_iter(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;
- for str::chars_each(slice) |ch| {
+ do str::chars_iter(slice) |ch| {
self.printer.writer.write_escaped_char(ch);
}
self.printer.writer.write_char('"');
View
4 src/libcore/result.rs
@@ -267,11 +267,11 @@ 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));
- for vec::each_ref(ts) |t| {
+ for vec::each(ts) |t| {
match op(t) {
Ok(v) => vec::push(vs, v),
Err(u) => return Err(u)
View
12 src/libcore/run.rs
@@ -86,8 +86,8 @@ fn with_argv<T>(prog: &str, args: &[~str],
cb: fn(**libc::c_char) -> T) -> T {
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
let mut tmps = ~[];
- for vec::each_ref(args) |arg| {
- let t = @copy *arg;
+ for vec::each(args) |arg| {
+ let t = @copy arg;
vec::push(tmps, t);
vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
}
@@ -105,8 +105,8 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
let mut tmps = ~[];
let mut ptrs = ~[];
- for vec::each_ref(es) |e| {
- let (k,v) = copy *e;
+ for vec::each(es) |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]));
@@ -130,8 +130,8 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
match *env {
Some(es) if !vec::is_empty(es) => {
let mut blk : ~[u8] = ~[];
- for vec::each_ref(es) |e| {
- let (k,v) = *e;
+ for vec::each(es) |e| {
+ let (k,v) = e;
let t = fmt!("%s=%s", k, v);
let mut v : ~[u8] = ::unsafe::reinterpret_cast(&t);
blk += v;
View
2 src/libcore/send_map.rs
@@ -312,7 +312,7 @@ mod linear {
}
pure fn each_ref(&self, blk: fn(k: &K, v: &V) -> bool) {
- for vec::each_ref(self.buckets) |slot| {
+ for vec::each(self.buckets) |slot| {
let mut broke = false;
do slot.iter |bucket| {
if !blk(&bucket.key, &bucket.value) {
View
134 src/libcore/str.rs
@@ -72,12 +72,12 @@ export
map,
each, eachi,
each_char, each_chari,
- bytes_each,
- chars_each,
- split_char_each,
- splitn_char_each,
- words_each,
- lines_each,
+ bytes_iter,
+ chars_iter,
+ split_char_iter,
+ splitn_char_iter,
+ words_iter,
+ lines_iter,
// Searching
find, find_from, find_between,
@@ -235,9 +235,7 @@ pure fn from_chars(chs: &[char]) -> ~str {
let mut buf = ~"";
unsafe {
reserve(buf, chs.len());
- for vec::each_ref(chs) |ch| {
- push_char(buf, *ch);
- }
+ for vec::each(chs) |ch| { push_char(buf, ch); }
}
move buf
}
@@ -291,18 +289,16 @@ 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_ref(v) |ss| {
- unsafe { push_str(s, *ss) };
- }
+ for vec::each(v) |ss| { unsafe { push_str(s, ss) }; }
move s
}
/// Concatenate a vector of strings, placing a given separator between each
pure fn connect(v: &[~str], sep: &str) -> ~str {
let mut s = ~"", first = true;
- for vec::each_ref(v) |ss| {
+ 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
}
@@ -883,20 +879,20 @@ pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
let mut result = ~"";
unsafe {
reserve(result, len(ss));
- for chars_each(ss) |cc| {
+ do chars_iter(ss) |cc| {
str::push_char(result, ff(cc));
}
}
move result
}
/// Iterate over the bytes in a string
-pure fn bytes_each(ss: &str, it: fn(u8) -> bool) {
+pure fn bytes_iter(ss: &str, it: fn(u8)) {
let mut pos = 0u;
let len = len(ss);
while (pos < len) {
- if !it(ss[pos]) { return; }
+ it(ss[pos]);
pos += 1u;
}
}
@@ -937,40 +933,40 @@ pure fn each_chari(s: &str, it: fn(uint, char) -> bool) {
}
/// Iterate over the characters in a string
-pure fn chars_each(s: &str, it: fn(char) -> bool) {
+pure fn chars_iter(s: &str, it: fn(char)) {
let mut pos = 0u;
let len = len(s);
while (pos < len) {
let {ch, next} = char_range_at(s, pos);
pos = next;
- if !it(ch) { return; }
+ it(ch);
}
}
/// Apply a function to each substring after splitting by character
-pure fn split_char_each(ss: &str, cc: char, ff: fn(v: &str) -> bool) {
- vec::each_ref(split_char(ss, cc), |s| ff(*s))
+pure fn split_char_iter(ss: &str, cc: char, ff: fn(&&~str)) {
+ vec::iter(split_char(ss, cc), ff)
}
/**
* Apply a function to each substring after splitting by character, up to
* `count` times
*/
-pure fn splitn_char_each(ss: &str, sep: char, count: uint,
- ff: fn(v: &str) -> bool) {
- vec::each_ref(splitn_char(ss, sep, count), |s| ff(*s))
+pure fn splitn_char_iter(ss: &str, sep: char, count: uint,
+ ff: fn(&&~str)) {
+ vec::iter(splitn_char(ss, sep, count), ff)
}
/// Apply a function to each word
-pure fn words_each(ss: &str, ff: fn(v: &str) -> bool) {
- vec::each_ref(words(ss), |s| ff(*s))
+pure fn words_iter(ss: &str, ff: fn(&&~str)) {
+ vec::iter(words(ss), ff)
}
/**
* Apply a function to each line (by '\n')
*/
-pure fn lines_each(ss: &str, ff: fn(v: &str) -> bool) {
- vec::each_ref(lines(ss), |s| ff(*s))
+pure fn lines_iter(ss: &str, ff: fn(&&~str)) {
+ vec::iter(lines(ss), ff)
}
/*
@@ -1522,7 +1518,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 = ~[];
- for chars_each(s) |cch| {
+ do chars_iter(s) |cch| {
// Arithmetic with u32 literals is easier on the eyes than chars.
let mut ch = cch as u32;
@@ -1951,9 +1947,7 @@ pure fn escape_default(s: &str) -> ~str {
let mut out: ~str = ~"";
unsafe {
reserve_at_least(out, str::len(s));
- for chars_each(s) |c| {
- push_str(out, char::escape_default(c));
- }
+ chars_iter(s, |c| push_str(out, char::escape_default(c)));
}
move out
}
@@ -1963,9 +1957,7 @@ pure fn escape_unicode(s: &str) -> ~str {
let mut out: ~str = ~"";
unsafe {
reserve_at_least(out, str::len(s));
- for chars_each(s) |c| {
- push_str(out, char::escape_unicode(c));
- }
+ chars_iter(s, |c| push_str(out, char::escape_unicode(c)));
}
move out
}
@@ -2102,7 +2094,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_ref(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).
@@ -3052,107 +3044,105 @@ mod tests {
}
#[test]
- fn test_chars_each() {
+ fn test_chars_iter() {
let mut i = 0;
- for chars_each(~"x\u03c0y") |ch| {
+ do chars_iter(~"x\u03c0y") |ch| {
match i {
0 => assert ch == 'x',
1 => assert ch == '\u03c0',
2 => assert ch == 'y',
- _ => fail ~"test_chars_each failed"
+ _ => fail ~"test_chars_iter failed"
}
i += 1;
}
- chars_each(~"", |_ch| fail ); // should not fail
+ chars_iter(~"", |_ch| fail ); // should not fail
}
#[test]
- fn test_bytes_each() {
+ fn test_bytes_iter() {
let mut i = 0;
- for bytes_each(~"xyz") |bb| {
+ do bytes_iter(~"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_each failed"
+ _ => fail ~"test_bytes_iter failed"
}
i += 1;
}
- for bytes_each(~"") |bb| {
- assert bb == 0u8;
- }
+ bytes_iter(~"", |bb| assert bb == 0u8);
}
#[test]
- fn test_split_char_each() {
+ fn test_split_char_iter() {
let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0;
- for split_char_each(data, ' ') |xx| {
+ do split_char_iter(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;
}
}
#[test]
- fn test_splitn_char_each() {
+ fn test_splitn_char_iter() {
let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0;
- for splitn_char_each(data, ' ', 2u) |xx| {
+ do splitn_char_iter(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;
}
}
#[test]
- fn test_words_each() {
+ fn test_words_iter() {
let data = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0;
- for words_each(data) |ww| {
+ do words_iter(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_each(~"", |_x| fail); // should not fail
+ words_iter(~"", |_x| fail); // should not fail
}
#[test]
- fn test_lines_each () {
+ fn test_lines_iter () {
let lf = ~"\nMary had a little lamb\nLittle lamb\n";
let mut ii = 0;
- for lines_each(lf) |x| {
+ do lines_iter(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;
@@ -3230,8 +3220,8 @@ mod tests {
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
0x000a_u16 ]) ];
- for vec::each_ref(pairs) |p| {
- let (s, u) = copy *p;
+ for vec::each(pairs) |p| {
+ let (s, u) = copy p;
assert to_utf16(s) == u;
assert from_utf16(u) == s;
assert from_utf16(to_utf16(s)) == s;
View
2 src/libcore/to_str.rs
@@ -75,7 +75,7 @@ impl<A: ToStr Copy, B: ToStr Copy, C: ToStr Copy> (A, B, C): ToStr {
impl<A: ToStr> ~[A]: ToStr {
fn to_str() -> ~str {
let mut acc = ~"[", first = true;
- for vec::each_ref(self) |elt| {
+ for vec::each(self) |elt| {
if first { first = false; }
else { str::push_str(acc, ~", "); }
str::push_str(acc, elt.to_str());
View
160 src/libcore/vec.rs
@@ -76,9 +76,12 @@ export zip, zip_slice;
export swap;
export reverse;
export reversed;
-export each, eachi, reach, reachi;
+export iter, iter_between, each, eachi, reach, reachi;
export each_ref, each_mut_ref, each_const_ref;
export iter2;
+export iteri;
+export riter;
+export riteri;
export permute;
export windowed;
export as_imm_buf;
@@ -854,16 +857,16 @@ 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;
- for each_ref(v) |elt| {
- accum = p(accum, *elt);
+ do iter(v) |elt| {
+ accum = p(accum, elt);
}
return accum;
}
/// 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;
- for reach(v) |elt| {
+ do riter(v) |elt| {
accum = p(elt, accum);
}
return accum;
@@ -1147,6 +1150,7 @@ 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] = ~[];
@@ -1160,6 +1164,43 @@ pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
}
/**
+ * 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.
@@ -1304,6 +1345,43 @@ 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`.
*
* Permutations are produced in lexicographic order with respect to the order
@@ -1336,12 +1414,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;
- for vec::eachi (xx) |ii, _x| {
+ vec::iteri (xx, |ii, _x| {
let len = vec::len(xx);
if ii+nn <= len unsafe {
vec::push(ww, vec::slice(xx, ii, ii+nn));
}
- }
+ });
move ww
}
@@ -1548,6 +1626,10 @@ 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];
@@ -1568,6 +1650,38 @@ 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) }
@@ -2351,57 +2465,55 @@ mod tests {
}
#[test]
- fn test_each_empty() {
- for each_ref::<int>(~[]) |_v| {
- fail; // should never be executed
- }
+ fn test_iter_empty() {
+ let mut i = 0;
+ iter::<int>(~[], |_v| i += 1);
+ assert i == 0;
}
#[test]
fn test_iter_nonempty() {
let mut i = 0;
- for each_ref(~[1, 2, 3]) |v| {
- i += *v;
- }
+ iter(~[1, 2, 3], |v| i += v);
assert i == 6;
}
#[test]
fn test_iteri() {
let mut i = 0;
- for eachi(~[1, 2, 3]) |j, v| {
+ iteri(~[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_reach_empty() {
- for reach::<int>(~[]) |_v| {
- fail; // should never execute
- }
+ fn test_riter_empty() {
+ let mut i = 0;
+ riter::<int>(~[], |_v| i += 1);
+ assert i == 0;
}
#[test]
fn test_riter_nonempty() {
let mut i = 0;
- for reach(~[1, 2, 3]) |v| {
+ riter(~[1, 2, 3], |v| {
if i == 0 { assert v == 3; }
i += v
- }
+ });
assert i == 6;
}
#[test]
- fn test_reachi() {
+ fn test_riteri() {
let mut i = 0;
- for reachi(~[0, 1, 2]) |j, v| {
+ riteri(~[0, 1, 2], |j, v| {
if i == 0 { assert v == 2; }
assert j == v as uint;
i += v;
- }
+ });
assert i == 3;
}
View
13 src/libstd/arc.rs
@@ -642,7 +642,6 @@ mod tests {
c.send(());
}
}
-
// Readers try to catch the writer in the act
let mut children = ~[];
for 5.times {
@@ -653,10 +652,8 @@ mod tests {
}
}
}
-
// Wait for children to pass their asserts
- for vec::each_ref(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; }
@@ -716,17 +713,17 @@ mod tests {
assert *state == 42;
*state = 31337;
// send to other readers
- for vec::each_ref(reader_convos) |x| {
- match *x {
+ for vec::each(reader_convos) |x| {
+ match x {
(rc, _) => rc.send(()),
}
}
}
let read_mode = arc.downgrade(write_mode);
do (&read_mode).read |state| {
// complete handshake with other readers
- for vec::each_ref(reader_convos) |x| {
- match *x {
+ for vec::each(reader_convos) |x| {
+ match x {
(_, rp) => rp.recv(),
}
}
View
22 src/libstd/getopts.rs
@@ -292,16 +292,16 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
}
}
let mut name_pos = 0u;
- for vec::each_ref(names) |nm| {
+ 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])); }
}
}
@@ -366,8 +366,8 @@ 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_ref(names) |nm| {
- match find_opt(mm.opts, mkname(*nm)) {
+ for vec::each(names) |nm| {
+ match find_opt(mm.opts, mkname(nm)) {
Some(_) => return true,
None => ()
}
@@ -393,8 +393,8 @@ fn opt_str(+mm: Matches, nm: &str) -> ~str {
* option took an argument
*/
fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
- for vec::each_ref(names) |nm| {
- match opt_val(mm, *nm) {
+ for vec::each(names) |nm| {
+ match opt_val(mm, nm) {
Val(s) => return s,
_ => ()
}
@@ -411,8 +411,8 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
*/
fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
- for vec::each_ref(opt_vals(mm, nm)) |v| {
- match *v { Val(s) => vec::push(acc, s), _ => () }
+ for vec::each(opt_vals(mm, nm)) |v| {
+ match v { Val(s) => vec::push(acc, s), _ => () }
}
return acc;
}
View
6 src/libstd/json.rs
@@ -179,7 +179,7 @@ fn to_writer_pretty(wr: io::Writer, j: Json, indent: uint) {
fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\"";
- for str::chars_each(s) |c| {
+ do str::chars_iter(s) |c| {
match c {
'"' => escaped += ~"\\\"",
'\\' => escaped += ~"\\\\",
@@ -834,8 +834,8 @@ mod tests {
fn mk_dict(items: &[(~str, Json)]) -> Json {
let d = map::str_hash();
- for vec::each_ref(items) |item| {
- let (key, value) = copy *item;
+ do vec::iter(items) |item| {
+ let (key, value) = copy item;
d.insert(key, value);
};
View
9 src/libstd/map.rs
@@ -435,12 +435,9 @@ 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();
- for vec::each_ref(items) |item| {
- match *item {
- (key, value) => {
- map.insert(key, value);
- }
- }
+ do vec::iter(items) |item| {
+ let (key, value) = item;
+ map.insert(key, value);
}
map
}
View
6 src/libstd/net_ip.rs
@@ -363,13 +363,13 @@ mod test {
let results = result::unwrap(ga_result);
log(debug, fmt!("test_get_addr: Number of results for %s: %?",
localhost_name, vec::len(results)));
- for vec::each_ref(results) |r| {
- let ipv_prefix = match *r {
+ for vec::each(results) |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
2 src/libstd/serialization.rs
@@ -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)) {
- for vec::eachi(v) |i,e| {
+ do vec::iteri(v) |i,e| {
do s.emit_vec_elt(i) {
f(e)
}
View
12 src/libstd/sha1.rs
@@ -65,8 +65,8 @@ fn sha1() -> Sha1 {
fn add_input(st: &Sha1State, msg: &[u8]) {
assert (!st.computed);
- for vec::each_ref(msg) |element| {
- st.msg_block[st.msg_block_idx] = *element;
+ for vec::each(msg) |element| {
+ st.msg_block[st.msg_block_idx] = element;
st.msg_block_idx += 1u;
st.len_low += 8u32;
if st.len_low == 0u32 {
@@ -240,9 +240,7 @@ fn sha1() -> Sha1 {
fn result_str() -> ~str {
let rr = mk_result(&self);
let mut s = ~"";
- for vec::each_ref(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;
}
}
@@ -331,7 +329,7 @@ mod tests {
// Test that it works when accepting the message all at once
let sh = sha1::sha1();
- for vec::each_ref(tests) |t| {
+ for vec::each(tests) |t| {
sh.input_str(t.input);
let out = sh.result();
check_vec_eq(t.output, out);
@@ -340,7 +338,7 @@ mod tests {
// Test that it works when accepting the message in pieces
- for vec::each_ref(tests) |t| {
+ for vec::each(tests) |t| {
let len = str::len(t.input);
let mut left = len;
while left > 0u {
View
4 src/libstd/sort.rs
@@ -259,8 +259,8 @@ mod test_qsort {
let immut_names = vec::from_mut(names);
let pairs = vec::zip(expected, immut_names);
- for vec::each_ref(pairs) |p| {
- let (a, b) = *p;
+ for vec::each(pairs) |p| {
+ let (a, b) = p;
debug!("%d %d", a, b);
assert (a == b);
}
View
4 src/libstd/sync.rs
@@ -941,7 +941,7 @@ mod tests {
}
}
}
- for vec::each_ref(sibling_convos) |p| {
+ for vec::each(sibling_convos) |p| {
let _ = p.recv(); // wait for sibling to get in the mutex
}
do m2.lock { }
@@ -950,7 +950,7 @@ mod tests {
};
assert result.is_err();
// child task must have finished by the time try returns
- for vec::each_ref(p.recv()) |p| { p.recv(); } // wait on all its siblings
+ for vec::each(p.recv()) |p| { p.recv(); } // wait on all its siblings
do m.lock_cond |cond| {
let woken = cond.broadcast();
assert woken == 0;
View
4 src/libstd/term.rs
@@ -39,8 +39,8 @@ fn color_supported() -> bool {
~"screen-bce", ~"xterm-256color"];
return match os::getenv(~"TERM") {
option::Some(env) => {
- for vec::each_ref(supported_terms) |term| {
- if *term == env { return true; }
+ for vec::each(supported_terms) |term| {
+ if term == env { return true; }
}
false
}
View
50 src/libstd/test.rs
@@ -226,8 +226,8 @@ fn print_failures(st: ConsoleTestState) {
let failures = copy st.failures;
let failures = vec::map(failures, |test| test.name);
let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures);
- for vec::each_ref(failures) |name| {
- st.out.write_line(fmt!(" %s", *name));
+ for vec::each(failures) |name| {
+ st.out.write_line(fmt!(" %s", name));
}
}
@@ -535,34 +535,30 @@ mod tests {
~"test::sort_tests"];
let tests =
{
- let testfn = fn~() { };
- let mut tests = ~[];
- for vec::each_ref(names) |name| {
- let test = {name: *name, testfn: copy testfn, ignore: false,
- should_fail: false};
- vec::push(tests, test);
- }
- tests
- };
- let filtered = filter_tests(opts, tests);
+ let testfn = fn~() { };
+ let mut tests = ~[];
+ for vec::each(names) |name| {
+ let test = {name: name, testfn: copy testfn, ignore: false,
+ should_fail: false};
+ tests += ~[test];
+ }
+ tests
+ };
+ let filtered = filter_tests(opts, tests);
- let expected =
- ~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
- ~"test::do_not_run_ignored_tests",
- ~"test::filter_for_ignored_option",
- ~"test::first_free_arg_should_be_a_filter",
- ~"test::ignored_tests_result_in_ignored",
- ~"test::parse_ignored_flag",
- ~"test::sort_tests"];
+ let expected =
+ ~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
+ ~"test::do_not_run_ignored_tests",
+ ~"test::filter_for_ignored_option",
+ ~"test::first_free_arg_should_be_a_filter",
+ ~"test::ignored_tests_result_in_ignored",
+ ~"test::parse_ignored_flag",
+ ~"test::sort_tests"];
- let pairs = vec::zip(expected, filtered);
+ let pairs = vec::zip(expected, filtered);
- for vec::each_ref(pairs) |p| {
- match *p {
- (a, b) => { assert (a == b.name); }
- }
- }
- }
+ for vec::each(pairs) |p| { let (a, b) = copy p; assert (a == b.name); }
+}
}
View
24 src/libstd/time.rs
@@ -1023,31 +1023,27 @@ mod tests {
}
}
- for vec::each_ref([
+ [
~"Sunday",
~"Monday",
~"Tuesday",
~"Wednesday",
~"Thursday",
~"Friday",
~"Saturday"
- ]) |day| {
- assert test(*day, ~"%A");
- }
+ ]/_.iter(|day| assert test(day, ~"%A"));
- for vec::each_ref([
+ [
~"Sun",
~"Mon",
~"Tue",
~"Wed",
~"Thu",
~"Fri",
~"Sat"
- ]) |day| {
- assert test(*day, ~"%a");
- }
+ ]/_.iter(|day| assert test(day, ~"%a"));
- for vec::each_ref([
+ [
~"January",
~"February",
~"March",
@@ -1060,11 +1056,9 @@ mod tests {
~"October",
~"November",
~"December"
- ]) |day| {
- assert test(*day, ~"%B");
- }
+ ]/_.iter(|day| assert test(day, ~"%B"));
- for vec::each_ref([
+ [
~"Jan",
~"Feb",
~"Mar",
@@ -1077,9 +1071,7 @@ mod tests {
~"Oct",
~"Nov",
~"Dec"
- ]) |day| {
- assert test(*day, ~"%b");
- }
+ ]/_.iter(|day| assert test(day, ~"%b"));
assert test(~"19", ~"%C");
assert test(~"Fri Feb 13 23:31:30 2009", ~"%c");
View
6 src/libsyntax/ast_map.rs
@@ -293,10 +293,8 @@ 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
- for vec::each_ref(struct_def.methods) |m| {
- map_method(d_id, p, *m, cx);
- }
+ // only need to handle methods
+ do vec::iter(struct_def.methods) |m| { map_method(d_id, p, m, cx); }
}
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
View
68 src/libsyntax/ast_util.rs
@@ -429,13 +429,13 @@ 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) => {
- for vec::each_ref(vps) |vp| {
- match vp.node {
- view_path_simple(_, _, _, id) => vfn(id),
- view_path_glob(_, id) => vfn(id),
- view_path_list(_, _, id) => vfn(id)
- }
- }
+ do vec::iter(vps) |vp| {
+ match vp.node {
+ view_path_simple(_, _, _, id) => vfn(id),
+ view_path_glob(_, id) => vfn(id),
+ view_path_list(_, _, id) => vfn(id)
+ }
+ }
}
}
},
@@ -490,44 +490,42 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
},
visit_ty_params: fn@(ps: ~[ty_param]) {
- for vec::each_ref(ps) |p| {
- vfn(p.id);
- }
+ vec::iter(ps, |p| vfn(p.id))
},
visit_fn: fn@(fk: visit::fn_kind, d: ast::fn_decl,
_b: ast::blk, _sp: span, id: ast::node_id) {
vfn(id);
match fk {
- visit::fk_ctor(_, _, tps, self_id, parent_id) => {
- for vec::each_ref(tps) |tp| { vfn(tp.id); }
- vfn(id);
- vfn(self_id);
- vfn(parent_id.node);
- }
- visit::fk_dtor(tps, _, self_id, parent_id) => {
- for vec::each_ref(tps) |tp| { vfn(tp.id); }
- vfn(id);
- vfn(self_id);
- vfn(parent_id.node);
- }
- visit::fk_item_fn(_, tps, _) => {
- for vec::each_ref(tps) |tp| { vfn(tp.id); }
- }
- visit::fk_method(_, tps, m) => {
- vfn(m.self_id);
- for vec::each_ref(tps) |tp| { vfn(tp.id); }
- }
- visit::fk_anon(_, capture_clause) |
- visit::fk_fn_block(capture_clause) => {
- for vec::each_ref(*capture_clause) |clause| {
- vfn(clause.id);
- }
+ visit::fk_ctor(_, _, tps, self_id, parent_id) => {
+ vec::iter(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));
+ vfn(id);
+ vfn(self_id);
+ vfn(parent_id.node);
+ }
+ visit::fk_item_fn(_, tps, _) => {
+ vec::iter(tps, |tp| vfn(tp.id));
+ }
+ visit::fk_method(_, tps, m) => {
+ vfn(m.self_id);
+ vec::iter(tps, |tp| vfn(tp.id));
+ }
+ visit::fk_anon(_, capture_clause)
+ | visit::fk_fn_block(capture_clause) => {
+ for vec::each(*capture_clause) |clause| {
+ vfn(clause.id);
}
+ }
}
- for vec::each_ref(d.inputs) |arg| {
+ do vec::iter(d.inputs) |arg| {
vfn(arg.id)
}
},
View
2 src/libsyntax/ext/qquote.rs
@@ -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();
- for str::chars_each(*str) |ch| {
+ do str::chars_iter(*str) |ch| {
if (j < g_len && i == cx.gather[j].lo) {
assert ch == '$';
let repl = fmt!("$%u ", j);
View
4 src/libsyntax/ext/simplext.rs
@@ -208,10 +208,10 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
pure fn follow(m: arb_depth<matchable>, idx_path: &[uint]) ->
arb_depth<matchable> {
let mut res: arb_depth<matchable> = m;
- for vec::each_ref(idx_path) |idx| {
+ 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
4 src/libsyntax/print/pprust.rs
@@ -1672,9 +1672,9 @@ fn print_arg_mode(s: ps, m: ast::mode) {
fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
if vec::len(*bounds) > 0u {
word(s.s, ~":");
- for vec::each_ref(*bounds) |bound| {
+ 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
4 src/libsyntax/visit.rs
@@ -262,8 +262,8 @@ 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_ref(*bounds) |bound| {
- match *bound {
+ for vec::each(*bounds) |bound| {
+ match bound {
bound_trait(t) => v.visit_ty(t, e, v),
bound_copy | bound_send | bound_const | bound_owned => ()
}
View
2 src/rustc/back/link.rs
@@ -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 = ~"";
- for str::chars_each(s) |c| {
+ do str::chars_iter(s) |c| {
match c {
'@' => result += ~"_sbox_",
'~' => result += ~"_ubox_",
View
4 src/rustc/metadata/cstore.rs
@@ -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);
- for vec::each_ref(decoder::get_crate_module_paths(cstore.intr, data)) |dp| {
- let (did, path) = *dp;
+ do vec::iter(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
12 src/rustc/metadata/encoder.rs
@@ -267,9 +267,7 @@ 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);
- for vec::each_ref(path) |pe| {
- encode_path_elt(ecx, ebml_w, *pe);
- }
+ do vec::iter(path) |pe| { encode_path_elt(ecx, ebml_w, pe); }
encode_path_elt(ecx, ebml_w, name);
}
}
@@ -739,7 +737,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item,
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
let mut i = 0u;
- for vec::each_ref(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
+ for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
match ms[i] {
required(ty_m) => {
ebml_w.start_tag(tag_item_trait_method);
@@ -769,8 +767,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item,
// method info, we output static methods with type signatures as
// written. Here, we output the *real* type signatures. I feel like
// maybe we should only ever handle the real type signatures.
- for vec::each_ref(ms) |m| {
- let ty_m = ast_util::trait_method_to_ty_method(*m);
+ for vec::each(ms) |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()});
@@ -890,7 +888,7 @@ fn encode_index<T>(ebml_w: ebml::Writer, buckets: ~[@~[entry<T>]],
for buckets.each |bucket| {
vec::push(bucket_locs, ebml_w.writer.tell());
ebml_w.start_tag(tag_index_buckets_bucket);
- for vec::each_ref(*bucket) |elt| {
+ for vec::each(*bucket) |elt| {
ebml_w.start_tag(tag_index_buckets_bucket_elt);
assert elt.pos < 0xffff_ffff;
writer.write_be_u32(elt.pos as u32);
View
4 src/rustc/metadata/tyencode.rs
@@ -365,8 +365,8 @@ 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_ref(*bs) |bound| {
- match *bound {
+ for vec::each(*bs) |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
16 src/rustc/middle/capture.rs
@@ -108,16 +108,16 @@ fn compute_capture_vars(tcx: ty::ctxt,
implicit_mode = cap_copy;
}
- for vec::each_ref(*freevars) |fvar| {
+ do vec::iter(*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 */ }
- option::None => {
- cap_map.insert(fvar_def_id, {def:fvar.def,
- span: fvar.span,
- cap_item: None,
- mode:implicit_mode});
- }
+ option::Some(_) => { /* was explicitly named, do nothing */ }
+ option::None => {
+ cap_map.insert(fvar_def_id, {def:fvar.def,
+ span: fvar.span,
+ cap_item: None,
+ mode:implicit_mode});
+ }
}
}
View
2 src/rustc/middle/check_alt.rs
@@ -274,7 +274,7 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option<ctor> {
}
let variants = ty::enum_variants(tcx, eid);
if found.len() != (*variants).len() {
- for vec::each_ref(*variants) |v| {
+ for vec::each(*variants) |v| {
if !found.contains(variant(v.id)) {
return Some(variant(v.id));
}
View
8 src/rustc/middle/kind.rs
@@ -195,7 +195,7 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
// Iterate over any free variables that may not have appeared in the
// capture list. Ensure that they too are of the appropriate kind.
- for vec::each_ref(*freevars::get_freevars(cx.tcx, fn_id)) |fv| {
+ for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| {
let id = ast_util::def_id_of_def(fv.def).node;
// skip over free variables that appear in the cap clause
@@ -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);
}
}
@@ -227,8 +227,8 @@ 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_ref(a.pats) |p| {
- do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _path| {
+ for vec::each(a.pats) |p| {
+ do pat_util::pat_bindings(cx.tcx.def_map, p) |mode, id, span, _path| {
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
2 src/rustc/middle/lint.rs
@@ -451,7 +451,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
decl: ast::fn_decl) {
let tys = vec::map(decl.inputs, |a| a.ty );
- for vec::each_ref(vec::append_one(tys, decl.output)) |ty| {
+ for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node {
ast::ty_path(_, id) => {
match cx.def_map.get(id) {
View
6 src/rustc/middle/resolve.rs
@@ -4343,11 +4343,11 @@ impl Resolver {
let rib = self.type_ribs.get_elt(i);
match rib.kind {
MethodRibKind(node_id, _) =>
- for vec::each_ref(self.crate.node.module.items) |item| {
+ for vec::each(self.crate.node.module.items) |item| {
if item.id == node_id {
match item.node {
item_class(class_def, _) => {
- for vec::each_ref(class_def.fields) |field| {
+ for vec::each(class_def.fields) |field| {
match field.node.kind {
syntax::ast::unnamed_field
=> {},
@@ -4360,7 +4360,7 @@ impl Resolver {
}
}
}
- for vec::each_ref(class_def.methods) |method| {
+ for vec::each(class_def.methods) |method| {
if str::eq_slice(self.session.str_of(method.ident),
name) {
return true
View
74 src/rustc/middle/trans/alt.rs
@@ -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 {