diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-09-27 22:20:47 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-09-28 13:27:45 -0700 |
| commit | 21519bc7e0a32e388e8b12be5d36d4440129f417 (patch) | |
| tree | bcdd50c7816a21a5d5422c114e722df1a5dcc65d | |
| parent | 6c15dd6d8217a166cfd0d364a434771803123432 (diff) | |
| download | rust-21519bc7e0a32e388e8b12be5d36d4440129f417.tar.gz rust-21519bc7e0a32e388e8b12be5d36d4440129f417.zip | |
demode vec
83 files changed, 541 insertions, 464 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index dd0e53143f5..6136652c873 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -527,7 +527,7 @@ fn load_one_source_package(src: @Source, p: &json::Object) { Some(json::List(js)) => { for js.each |j| { match *j { - json::String(j) => vec::grow(tags, 1u, j), + json::String(ref j) => tags.grow(1u, j), _ => () } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index dae5105ce71..ff695f64088 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -503,10 +503,7 @@ fn make_run_args(config: config, _props: test_props, testfile: &Path) -> fn split_maybe_args(argstr: Option<~str>) -> ~[~str] { fn rm_whitespace(v: ~[~str]) -> ~[~str] { - fn flt(&&s: ~str) -> Option<~str> { - if !str::is_whitespace(s) { option::Some(s) } else { option::None } - } - vec::filter_map(v, flt) + vec::filter(v, |s| !str::is_whitespace(*s)) } match argstr { diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index ab3c2c7c2ca..ace96c389ef 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -229,7 +229,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap, filename: &Path, cx: context) { let stolen = steal(crate, cx.mode); let extra_exprs = vec::filter(common_exprs(), - |a| safe_to_use_expr(a, cx.mode) ); + |a| safe_to_use_expr(*a, cx.mode) ); check_variants_T(crate, codemap, filename, ~"expr", extra_exprs + stolen.exprs, pprust::expr_to_str, replace_expr_in_crate, cx); diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index fcf8146200d..0bdf5caec0c 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -99,7 +99,7 @@ pub pure fn from_elem<T>(+data: T) -> DList<T> { pub fn from_vec<T: Copy>(+vec: &[T]) -> DList<T> { do vec::foldl(DList(), vec) |list,data| { - list.push(data); // Iterating left-to-right -- add newly to the tail. + list.push(*data); // Iterating left-to-right -- add newly to the tail. list } } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index eb221926fc1..d360eab3c8a 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -157,7 +157,7 @@ impl<A> DVec<A> { fn pop() -> A { do self.check_out |v| { let mut v <- v; - let result = vec::pop(v); + let result = v.pop(); self.give_back(move v); move result } @@ -187,7 +187,7 @@ impl<A> DVec<A> { fn shift() -> A { do self.check_out |v| { let mut v = move v; - let result = vec::shift(v); + let result = v.shift(); self.give_back(move v); move result } @@ -305,10 +305,10 @@ impl<A: Copy> DVec<A> { * growing the vector if necessary. New elements will be initialized * with `initval` */ - fn grow_set_elt(idx: uint, initval: A, +val: A) { + fn grow_set_elt(idx: uint, initval: &A, +val: A) { do self.swap |v| { let mut v = move v; - vec::grow_set(v, idx, initval, val); + v.grow_set(idx, initval, val); move v } } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index aff6db3c10f..098e82f5fad 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -140,7 +140,7 @@ pub fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { // turn digits into string // using stack of digits while fractionalParts.is_not_empty() { - let mut adjusted_digit = carry + vec::pop(fractionalParts); + let mut adjusted_digit = carry + fractionalParts.pop(); if adjusted_digit == 10 { carry = 1; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 47ea01af677..667aaaf7b0e 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -64,11 +64,11 @@ trait ReaderUtil { impl<T: Reader> T : ReaderUtil { fn read_bytes(len: uint) -> ~[u8] { let mut buf = vec::with_capacity(len); - unsafe { vec::raw::set_len(buf, len); } + unsafe { vec::raw::set_len(&mut buf, len); } let count = self.read(buf, len); - unsafe { vec::raw::set_len(buf, count); } + unsafe { vec::raw::set_len(&mut buf, count); } move buf } fn read_line() -> ~str { @@ -695,7 +695,7 @@ impl BytesWriter: Writer { let count = uint::max(buf_len, self.pos + v_len); vec::reserve(&mut buf, count); - unsafe { vec::raw::set_len(buf, count); } + unsafe { vec::raw::set_len(&mut buf, count); } { let view = vec::mut_view(buf, self.pos, count); diff --git a/src/libcore/os.rs b/src/libcore/os.rs index c1ea71c181b..644cef42b41 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -582,7 +582,7 @@ pub fn list_dir(p: &Path) -> ~[~str] { fn star(p: &Path) -> Path { p.push("*") } do rustrt::rust_list_files(star(p).to_str()).filter |filename| { - filename != ~"." && filename != ~".." + *filename != ~"." && *filename != ~".." } } @@ -857,10 +857,10 @@ mod tests { let mut e = env(); setenv(n, ~"VALUE"); - assert !vec::contains(e, (copy n, ~"VALUE")); + assert !vec::contains(e, &(copy n, ~"VALUE")); e = env(); - assert vec::contains(e, (n, ~"VALUE")); + assert vec::contains(e, &(n, ~"VALUE")); } #[test] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index c384745bb5e..1afcc7ba09d 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -221,7 +221,7 @@ impl PosixPath : GenericPath { pure fn pop() -> PosixPath { let mut cs = copy self.components; if cs.len() != 0 { - unsafe { vec::pop(cs); } + unsafe { cs.pop(); } } return PosixPath { components: move cs, ..self } } @@ -415,7 +415,7 @@ impl WindowsPath : GenericPath { pure fn pop() -> WindowsPath { let mut cs = copy self.components; if cs.len() != 0 { - unsafe { vec::pop(cs); } + unsafe { cs.pop(); } } return WindowsPath { components: move cs, ..self } } @@ -437,7 +437,7 @@ pub pure fn normalize(components: &[~str]) -> ~[~str] { if *c == ~"." && components.len() > 1 { loop; } if *c == ~"" { loop; } if *c == ~".." && cs.len() != 0 { - vec::pop(cs); + cs.pop(); loop; } cs.push(copy *c); diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 3559753410f..7a4d15ac4fe 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -704,7 +704,7 @@ pub fn select<T: Send, Tb: Send>(+endpoints: ~[RecvPacketBuffered<T, Tb>]) { let ready = wait_many(endpoints.map(|p| p.header())); let mut remaining <- endpoints; - let port = vec::swap_remove(remaining, ready); + let port = remaining.swap_remove(ready); let result = try_recv(move port); (ready, move result, move remaining) } @@ -1067,7 +1067,7 @@ impl<T: Send> PortSet<T> : Recv<T> { } None => { // Remove this port. - let _ = vec::swap_remove(ports, i); + let _ = ports.swap_remove(i); } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 72fa2cda1a7..7f1f1e4b345 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -127,7 +127,7 @@ pub unsafe fn memset<T>(dst: *mut T, c: int, count: uint) { reinterpret_cast. */ #[inline(always)] -pub fn to_unsafe_ptr<T>(thing: &T) -> *T { +pub pure fn to_unsafe_ptr<T>(thing: &T) -> *T { unsafe { cast::reinterpret_cast(&thing) } } @@ -137,7 +137,7 @@ pub fn to_unsafe_ptr<T>(thing: &T) -> *T { reinterpret_cast. */ #[inline(always)] -pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T { +pub pure fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T { unsafe { cast::reinterpret_cast(&thing) } } @@ -147,7 +147,7 @@ pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T { reinterpret_cast. */ #[inline(always)] -pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T { +pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T { unsafe { cast::reinterpret_cast(&thing) } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index d7e90c1a42d..a932a6133c5 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -450,7 +450,7 @@ Section: Transforming strings */ pure fn to_bytes(s: &str) -> ~[u8] unsafe { let mut v: ~[u8] = ::cast::transmute(from_slice(s)); - vec::raw::set_len(v, len(s)); + vec::raw::set_len(&mut v, len(s)); move v } @@ -1945,7 +1945,7 @@ fn reserve_at_least(s: &const ~str, n: uint) { */ pure fn capacity(s: &const ~str) -> uint { do as_bytes(s) |buf| { - let vcap = vec::capacity(*buf); + let vcap = vec::capacity(buf); assert vcap > 0u; vcap - 1u } @@ -2008,7 +2008,7 @@ mod raw { vec::as_mut_buf(v, |vbuf, _len| { ptr::memcpy(vbuf, buf as *u8, len) }); - vec::raw::set_len(v, len); + vec::raw::set_len(&mut v, len); v.push(0u8); assert is_utf8(v); @@ -2065,7 +2065,7 @@ mod raw { let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } - vec::raw::set_len(v, end - begin); + vec::raw::set_len(&mut v, end - begin); v.push(0u8); ::cast::transmute(move v) } diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index a89661c3291..50f55383167 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -35,35 +35,44 @@ impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> { } trait ExtendedTupleOps<A,B> { - fn zip() -> ~[(A, B)]; - fn map<C>(f: &fn(A, B) -> C) -> ~[C]; + fn zip(&self) -> ~[(A, B)]; + fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; } impl<A: Copy, B: Copy> (&[A], &[B]): ExtendedTupleOps<A,B> { - - fn zip() -> ~[(A, B)] { - let (a, b) = self; - vec::zip_slice(a, b) + fn zip(&self) -> ~[(A, B)] { + match *self { + (ref a, ref b) => { + vec::zip_slice(*a, *b) + } + } } - fn map<C>(f: &fn(A, B) -> C) -> ~[C] { - let (a, b) = self; - vec::map2(a, b, f) + fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { + match *self { + (ref a, ref b) => { + vec::map2(*a, *b, f) + } + } } } impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> { - fn zip() -> ~[(A, B)] { - // FIXME #2543: Bad copy - let (a, b) = copy self; - vec::zip(move a, move b) + fn zip(&self) -> ~[(A, B)] { + match *self { + (ref a, ref b) => { + vec::zip_slice(*a, *b) + } + } } - fn map<C>(f: &fn(A, B) -> C) -> ~[C] { - // FIXME #2543: Bad copy - let (a, b) = copy self; - vec::map2(a, b, f) + fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { + match *self { + (ref a, ref b) => { + vec::map2(*a, *b, f) + } + } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 07ccb244ddd..914434c9d46 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1,5 +1,9 @@ //! Vectors +#[warn(deprecated_mode)]; +#[warn(deprecated_pattern)]; +#[warn(non_camel_case_types)]; + use cmp::{Eq, Ord}; use option::{Some, None}; use ptr::addr_of; @@ -140,7 +144,7 @@ pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool { */ fn reserve<T>(+v: &mut ~[T], +n: uint) { // Only make the (slow) call into the runtime if we have to - if capacity(*v) < n { + if capacity(v) < n { unsafe { let ptr: **raw::VecRepr = cast::transmute(v); rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), @@ -170,16 +174,16 @@ fn reserve_at_least<T>(v: &mut ~[T], n: uint) { /// Returns the number of elements the vector can hold without reallocating #[inline(always)] -pure fn capacity<T>(&&v: ~[const T]) -> uint { +pure fn capacity<T>(v: &const ~[T]) -> uint { unsafe { - let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::transmute(v); (**repr).unboxed.alloc / sys::size_of::<T>() } } /// Returns the length of a vector #[inline(always)] -pure fn len<T>(&&v: &[const T]) -> uint { +pure fn len<T>(v: &[const T]) -> uint { as_const_buf(v, |_p, len| len) } @@ -190,11 +194,18 @@ pure fn len<T>(&&v: &[const T]) -> uint { * to the value returned by the function `op`. */ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] { - let mut v = with_capacity(n_elts); - let mut i: uint = 0u; - while i < n_elts unsafe { raw::set(v, i, op(i)); i += 1u; } - unsafe { raw::set_len(v, n_elts); } - move v + unsafe { + let mut v = with_capacity(n_elts); + do as_mut_buf(v) |p, _len| { + let mut i: uint = 0u; + while i < n_elts { + rusti::move_val_init(*ptr::mut_offset(p, i), op(i)); + i += 1u; + } + } + raw::set_len(&mut v, n_elts); + return move v; + } } /** @@ -203,14 +214,8 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T] { - let mut v = with_capacity(n_elts); - let mut i: uint = 0u; - unsafe { // because unsafe::set is unsafe - while i < n_elts { raw::set(v, i, t); i += 1u; } - unsafe { raw::set_len(v, n_elts); } - } - move v +pure fn from_elem<T: Copy>(n_elts: uint, +t: T) -> ~[T] { + from_fn(n_elts, |_i| copy t) } /// Creates a new unique vector with the same contents as the slice @@ -378,7 +383,7 @@ pure fn const_view<T>(v: &r/[const T], start: uint, } /// Split the vector `v` by applying each element against the predicate `f`. -fn split<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { +fn split<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -401,7 +406,7 @@ fn split<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { * Split the vector `v` by applying each element against the predicate `f` up * to `n` times. */ -fn splitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { +fn splitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -427,7 +432,7 @@ fn splitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f`. */ -fn rsplit<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { +fn rsplit<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -451,7 +456,7 @@ fn rsplit<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f` up to `n times. */ -fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { +fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -477,12 +482,12 @@ fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { // Mutators /// Removes the first element from a vector and return it -fn shift<T>(&v: ~[T]) -> T { - let ln = len::<T>(v); +fn shift<T>(v: &mut ~[T]) -> T { + let ln = v.len(); assert (ln > 0); let mut vv = ~[]; - v <-> vv; + *v <-> vv; unsafe { let mut rr; @@ -495,22 +500,22 @@ fn shift<T>(&v: ~[T]) -> T { v.push(move r); } } - raw::set_len(vv, 0); + raw::set_len(&mut vv, 0); move rr } } /// Prepend an element to the vector -fn unshift<T>(&v: ~[T], +x: T) { +fn unshift<T>(v: &mut ~[T], +x: T) { let mut vv = ~[move x]; - v <-> vv; - while len(vv) > 0 { - v.push(shift(vv)); - } + *v <-> vv; + v.push_all_move(vv); } fn consume<T>(+v: ~[T], f: fn(uint, +v: T)) unsafe { + let mut v = move v; // FIXME(#3488) + do as_imm_buf(v) |p, ln| { for uint::range(0, ln) |i| { let x <- *ptr::offset(p, i); @@ -518,29 +523,22 @@ fn consume<T>(+v: ~[T], f: fn(uint, +v: T)) unsafe { } } - raw::set_len(v, 0); + raw::set_len(&mut v, 0); } -fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +v: T)) unsafe { - do as_imm_buf(v) |p, ln| { - for uint::range(0, ln) |i| { - let x <- *ptr::offset(p, i); - f(i, move x); - } - } - - raw::set_len(v, 0); +fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +v: T)) { + consume(vec::from_mut(v), f) } /// Remove the last element from a vector and return it -fn pop<T>(&v: ~[const T]) -> T { - let ln = len(v); +fn pop<T>(v: &mut ~[T]) -> T { + let ln = v.len(); if ln == 0 { fail ~"sorry, cannot vec::pop an empty vector" } - let valptr = ptr::mut_addr_of(v[ln - 1u]); + let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]); unsafe { - let val <- *valptr; + let val = move *valptr; raw::set_len(v, ln - 1u); move val } @@ -552,21 +550,15 @@ fn pop<T>(&v: ~[const T]) -> T { * * Fails if index >= length. */ -fn swap_remove<T>(&v: ~[const T], index: uint) -> T { - let ln = len(v); +fn swap_remove<T>(v: &mut ~[T], index: uint) -> T { + let ln = v.len(); if index >= ln { fail fmt!("vec::swap_remove - index %u >= length %u", index, ln); } - let lastptr = ptr::mut_addr_of(v[ln - 1]); - unsafe { - let mut val <- *lastptr; - if index < ln - 1 { - let valptr = ptr::mut_addr_of(v[index]); - *valptr <-> val; - } - raw::set_len(v, ln - 1); - move val + if index < ln - 1 { + v[index] <-> v[ln - 1]; } + vec::pop(v) } /// Append an element to a vector @@ -611,7 +603,8 @@ fn push_all<T: Copy>(+v: &mut ~[T], rhs: &[const T]) { } #[inline(always)] -fn push_all_move<T>(v: &mut ~[T], -rhs: ~[const T]) { +fn push_all_move<T>(v: &mut ~[T], +rhs: ~[T]) { + let mut rhs = move rhs; // FIXME(#3488) reserve(v, v.len() + rhs.len()); unsafe { do as_imm_buf(rhs) |p, len| { @@ -620,13 +613,13 @@ fn push_all_move<T>(v: &mut ~[T], -rhs: ~[const T]) { push(v, move x); } } - raw::set_len(rhs, 0); + raw::set_len(&mut rhs, 0); } } /// Shorten a vector, dropping excess elements. -fn truncate<T>(&v: ~[const T], newlen: uint) { - do as_imm_buf(v) |p, oldlen| { +fn truncate<T>(v: &mut ~[T], newlen: uint) { + do as_imm_buf(*v) |p, oldlen| { assert(newlen <= oldlen); unsafe { // This loop is optimized out for non-drop types. @@ -642,10 +635,10 @@ fn truncate<T>(&v: ~[const T], newlen: uint) { * Remove consecutive repeated elements from a vector; if the vector is * sorted, this removes all duplicates. */ -fn dedup<T: Eq>(&v: ~[const T]) unsafe { +fn dedup<T: Eq>(v: &mut ~[T]) unsafe { if v.len() < 1 { return; } let mut last_written = 0, next_to_read = 1; - do as_const_buf(v) |p, ln| { + do as_const_buf(*v) |p, ln| { // We have a mutable reference to v, so we can make arbitrary changes. // (cf. push and pop) let p = p as *mut T; @@ -704,12 +697,12 @@ pure fn append_mut<T: Copy>(+lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] { * * n - The number of elements to add * * initval - The value for the new elements */ -fn grow<T: Copy>(&v: ~[T], n: uint, initval: T) { - reserve_at_least(&mut v, len(v) + n); +fn grow<T: Copy>(v: &mut ~[T], n: uint, initval: &T) { + reserve_at_least(v, v.len() + n); let mut i: uint = 0u; while i < n { - v.push(initval); + v.push(*initval); i += 1u; } } @@ -727,8 +720,8 @@ fn grow<T: Copy>(&v: ~[T], n: uint, initval: T) { * * init_op - A function to call to retreive each appended element's * value */ -fn grow_fn<T>(&v: ~[T], n: uint, op: iter::InitOp<T>) { - reserve_at_least(&mut v, len(v) + n); +fn grow_fn<T>(v: &mut ~[T], n: uint, op: iter::InitOp<T>) { + reserve_at_least(v, v.len() + n); let mut i: uint = 0u; while i < n { v.push(op(i)); @@ -744,15 +737,16 @@ fn grow_fn<T>(&v: ~[T], n: uint, op: iter::InitOp<T>) { * of the vector, expands the vector by replicating `initval` to fill the * intervening space. */ -fn grow_set<T: Copy>(&v: ~[T], index: uint, initval: T, val: T) { - if index >= len(v) { grow(v, index - len(v) + 1u, initval); } - v[index] = val; +fn grow_set<T: Copy>(v: &mut ~[T], index: uint, initval: &T, +val: T) { + let l = v.len(); + if index >= l { grow(v, index - l + 1u, initval); } + v[index] = move val; } // Functional utilities /// Apply a function to each element of a vector and return the results -pure fn map<T, U>(v: &[T], f: fn(v: &T) -> U) -> ~[U] { +pure fn map<T, U>(v: &[T], f: fn(t: &T) -> U) -> ~[U] { let mut result = with_capacity(len(v)); for each(v) |elem| { unsafe { @@ -771,7 +765,7 @@ fn map_consume<T, U>(+v: ~[T], f: fn(+v: T) -> U) -> ~[U] { } /// Apply a function to each element of a vector and return the results -pure fn mapi<T, U>(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] { +pure fn mapi<T, U>(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] { let mut i = 0; do map(v) |e| { i += 1; @@ -783,21 +777,21 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] { * Apply a function to each element of a vector and return a concatenation * of each result vector */ -pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] { +pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) |elem| { unsafe{ result.push_all_move(f(*elem)); } } + for each(v) |elem| { unsafe{ result.push_all_move(f(elem)); } } move result } /// Apply a function to each pair of elements and return the results pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U], - f: fn(T, U) -> V) -> ~[V] { + f: fn(t: &T, v: &U) -> V) -> ~[V] { let v0_len = len(v0); if v0_len != len(v1) { fail; } let mut u: ~[V] = ~[]; let mut i = 0u; while i < v0_len { - unsafe { u.push(f(copy v0[i], copy v1[i])) }; + unsafe { u.push(f(&v0[i], &v1[i])) }; i += 1u; } move u @@ -809,11 +803,11 @@ pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U], * If function `f` returns `none` then that element is excluded from * the resulting vector. */ -pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>) +pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>) -> ~[U] { let mut result = ~[]; for each(v) |elem| { - match f(*elem) { + match f(elem) { None => {/* no-op */ } Some(result_elem) => unsafe { result.push(result_elem); } } @@ -828,10 +822,10 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>) * Apply function `f` to each element of `v` and return a vector containing * only those elements for which `f` returned true. */ -pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] { +pure fn filter<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; for each(v) |elem| { - if f(*elem) { unsafe { result.push(*elem); } } + if f(elem) { unsafe { result.push(*elem); } } } move result } @@ -848,30 +842,32 @@ pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] { } /// Concatenate a vector of vectors, placing a given separator between each -pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] { +pure fn connect<T: Copy>(v: &[~[T]], sep: &T) -> ~[T] { let mut r: ~[T] = ~[]; let mut first = true; for each(v) |inner| { - if first { first = false; } else { unsafe { r.push(sep); } } + if first { first = false; } else { unsafe { r.push(*sep); } } unsafe { r.push_all(*inner) }; } move r } /// Reduce a vector from left to right -pure fn foldl<T: Copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T { +pure fn foldl<T: Copy, U>(+z: T, v: &[U], p: fn(+t: T, u: &U) -> T) -> T { let mut accum = z; for each(v) |elt| { - accum = p(accum, *elt); + // it should be possible to move accum in, but the liveness analysis + // is not smart enough. + 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 { +pure fn foldr<T, U: Copy>(v: &[T], +z: U, p: fn(t: &T, +u: U) -> U) -> U { let mut accum = z; for rev_each(v) |elt| { - accum = p(*elt, accum); + accum = p(elt, accum); } return accum; } @@ -881,8 +877,8 @@ 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; } } +pure fn any<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { + for each(v) |elem| { if f(elem) { return true; } } return false; } @@ -892,12 +888,12 @@ pure fn any<T>(v: &[T], f: fn(T) -> bool) -> bool { * If the vectors contains no elements then false is returned. */ pure fn any2<T, U>(v0: &[T], v1: &[U], - f: fn(T, U) -> bool) -> bool { + f: fn(a: &T, b: &U) -> bool) -> bool { let v0_len = len(v0); let v1_len = len(v1); let mut i = 0u; while i < v0_len && i < v1_len { - if f(v0[i], v1[i]) { return true; }; + if f(&v0[i], &v1[i]) { return true; }; i += 1u; } return false; @@ -908,8 +904,8 @@ 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; } } +pure fn all<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { + for each(v) |elem| { if !f(elem) { return false; } } return true; } @@ -918,8 +914,8 @@ pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool { * * If the vector contains no elements then true is returned. */ -pure fn alli<T>(v: &[T], f: fn(uint, T) -> bool) -> bool { - for eachi(v) |i, elem| { if !f(i, *elem) { return false; } } +pure fn alli<T>(v: &[T], f: fn(uint, t: &T) -> bool) -> bool { + for eachi(v) |i, elem| { if !f(i, elem) { return false; } } return true; } @@ -929,24 +925,24 @@ pure fn alli<T>(v: &[T], f: fn(uint, T) -> bool) -> bool { * If the vectors are not the same size then false is returned. */ pure fn all2<T, U>(v0: &[T], v1: &[U], - f: fn(T, U) -> bool) -> bool { + f: fn(t: &T, u: &U) -> bool) -> bool { let v0_len = len(v0); if v0_len != len(v1) { return false; } let mut i = 0u; - while i < v0_len { if !f(v0[i], v1[i]) { return false; }; i += 1u; } + while i < v0_len { if !f(&v0[i], &v1[i]) { return false; }; i += 1u; } return true; } /// 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; } } +pure fn contains<T: Eq>(v: &[T], x: &T) -> bool { + 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 { +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; } @@ -957,7 +953,7 @@ pure fn count<T: Eq>(v: &[T], x: T) -> uint { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { +pure fn find<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { find_between(v, 0u, len(v), f) } @@ -969,7 +965,7 @@ pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { * the element is returned. If `f` matches no elements then none is returned. */ pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option<T> { + f: fn(t: &T) -> bool) -> Option<T> { position_between(v, start, end, f).map(|i| v[*i]) } @@ -980,7 +976,7 @@ pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint, * `f` returns true then an option containing the element is returned. If `f` * matches no elements then none is returned. */ -pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { +pure fn rfind<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { rfind_between(v, 0u, len(v), f) } @@ -989,16 +985,16 @@ pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { * * Apply function `f` to each element of `v` in reverse order within the range * [`start`, `end`). When function `f` returns true then an option containing - * the element is returned. If `f` matches no elements then none is returned. + * the element is returned. If `f` matches no elements then none is return. */ pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option<T> { + f: fn(t: &T) -> bool) -> Option<T> { rposition_between(v, start, end, f).map(|i| v[*i]) } /// Find the first index containing a matching value -pure fn position_elem<T: Eq>(v: &[T], x: T) -> Option<uint> { - position(v, |y| x == y) +pure fn position_elem<T: Eq>(v: &[T], x: &T) -> Option<uint> { + position(v, |y| *x == *y) } /** @@ -1008,7 +1004,7 @@ pure fn position_elem<T: Eq>(v: &[T], x: T) -> Option<uint> { * then an option containing the index is returned. If `f` matches no elements * then none is returned. */ -pure fn position<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> { +pure fn position<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { position_between(v, 0u, len(v), f) } @@ -1020,17 +1016,17 @@ pure fn position<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> { * the index is returned. If `f` matches no elements then none is returned. */ pure fn position_between<T>(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option<uint> { + f: fn(t: &T) -> bool) -> Option<uint> { assert start <= end; assert end <= len(v); let mut i = start; - while i < end { if f(v[i]) { return Some::<uint>(i); } i += 1u; } + while i < end { if f(&v[i]) { return Some::<uint>(i); } i += 1u; } return None; } /// Find the last index containing a matching value -pure fn rposition_elem<T: Eq>(v: &[T], x: T) -> Option<uint> { - rposition(v, |y| x == y) +pure fn rposition_elem<T: Eq>(v: &[T], x: &T) -> Option<uint> { + rposition(v, |y| *x == *y) } /** @@ -1040,7 +1036,7 @@ pure fn rposition_elem<T: Eq>(v: &[T], x: T) -> Option<uint> { * `f` returns true then an option containing the index is returned. If `f` * matches no elements then none is returned. */ -pure fn rposition<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> { +pure fn rposition<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { rposition_between(v, 0u, len(v), f) } @@ -1053,12 +1049,12 @@ pure fn rposition<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> { * returned. */ pure fn rposition_between<T>(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option<uint> { + f: fn(t: &T) -> bool) -> Option<uint> { assert start <= end; assert end <= len(v); let mut i = end; while i > start { - if f(v[i - 1u]) { return Some::<uint>(i - 1u); } + if f(&v[i - 1u]) { return Some::<uint>(i - 1u); } i -= 1u; } return None; @@ -1122,12 +1118,13 @@ pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U]) * Returns a vector of tuples, where the i-th tuple contains contains the * i-th elements from each of the input vectors. */ -pure fn zip<T, U>(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] { - let mut v = move v, u = move u, i = len(v); +pure fn zip<T, U>(+v: ~[T], +u: ~[U]) -> ~[(T, U)] { + let mut v = move v, u = move u; // FIXME(#3488) + let mut i = len(v); assert i == len(u); let mut w = with_capacity(i); while i > 0 { - unsafe { w.push((pop(v),pop(u))); } + unsafe { w.push((v.pop(),u.pop())); } i -= 1; } unsafe { reverse(w); } @@ -1269,10 +1266,10 @@ pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) { * Both vectors must have the same length */ #[inline] -fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(U, T)) { +fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T)) { assert len(v1) == len(v2); for uint::range(0u, len(v1)) |i| { - f(v1[i], v2[i]) + f(&v1[i], &v2[i]) } } @@ -1286,20 +1283,24 @@ fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(U, T)) { * The total number of permutations produced is `len(v)!`. If `v` contains * repeated elements, then some permutations are repeated. */ -pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) { +pure fn each_permutation<T: Copy>(+v: &[T], put: fn(ts: &[T]) -> bool) { let ln = len(v); - if ln == 0u { - put(~[]); + if ln <= 1 { + put(v); } else { + // This does not seem like the most efficient implementation. You + // could make far fewer copies if you put your mind to it. let mut i = 0u; while i < ln { let elt = v[i]; let mut rest = slice(v, 0u, i); unsafe { rest.push_all(const_view(v, i+1u, ln)); - permute(rest, |permutation| { - put(append(~[elt], permutation)) - }) + for each_permutation(rest) |permutation| { + if !put(append(~[elt], permutation)) { + return; + } + } } i += 1u; } @@ -1528,20 +1529,20 @@ impl<T: Copy> &[const T]: CopyableVector<T> { trait ImmutableVector<T> { pure fn view(start: uint, end: uint) -> &self/[T]; - pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U; - pure fn map<U>(f: fn(v: &T) -> U) -> ~[U]; - pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U]; + pure fn foldr<U: Copy>(z: U, p: fn(t: &T, +u: U) -> U) -> U; + pure fn map<U>(f: fn(t: &T) -> U) -> ~[U]; + pure fn mapi<U>(f: fn(uint, t: &T) -> U) -> ~[U]; fn map_r<U>(f: fn(x: &T) -> U) -> ~[U]; - pure fn alli(f: fn(uint, T) -> bool) -> bool; - pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U]; - pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U]; + pure fn alli(f: fn(uint, t: &T) -> bool) -> bool; + pure fn flat_map<U>(f: fn(t: &T) -> ~[U]) -> ~[U]; + pure fn filter_map<U: Copy>(f: fn(t: &T) -> Option<U>) -> ~[U]; } trait ImmutableEqVector<T: Eq> { - pure fn position(f: fn(T) -> bool) -> Option<uint>; - pure fn position_elem(x: T) -> Option<uint>; - pure fn rposition(f: fn(T) -> bool) -> Option<uint>; - pure fn rposition_elem(x: T) -> Option<uint>; + pure fn position(f: fn(t: &T) -> bool) -> Option<uint>; + pure fn position_elem(t: &T) -> Option<uint>; + pure fn rposition(f: fn(t: &T) -> bool) -> Option<uint>; + pure fn rposition_elem(t: &T) -> Option<uint>; } /// Extension methods for vectors @@ -1552,15 +1553,17 @@ 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) } + pure fn foldr<U: Copy>(z: U, p: fn(t: &T, +u: U) -> U) -> U { + foldr(self, z, p) + } /// Apply a function to each element of a vector and return the results #[inline] - pure fn map<U>(f: fn(v: &T) -> U) -> ~[U] { map(self, f) } + pure fn map<U>(f: fn(t: &T) -> U) -> ~[U] { map(self, f) } /** * Apply a function to the index and value of each element in the vector * and return the results */ - pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U] { + pure fn mapi<U>(f: fn(uint, t: &T) -> U) -> ~[U] { mapi(self, f) } @@ -1580,7 +1583,7 @@ impl<T> &[T]: ImmutableVector<T> { * * If the vector is empty, true is returned. */ - pure fn alli(f: fn(uint, T) -> bool) -> bool { + pure fn alli(f: fn(uint, t: &T) -> bool) -> bool { alli(self, f) } /** @@ -1588,7 +1591,9 @@ impl<T> &[T]: ImmutableVector<T> { * of each result vector */ #[inline] - pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U] { flat_map(self, f) } + pure fn flat_map<U>(f: fn(t: &T) -> ~[U]) -> ~[U] { + flat_map(self, f) + } /** * Apply a function to each element of a vector and return the results * @@ -1596,7 +1601,7 @@ impl<T> &[T]: ImmutableVector<T> { * the resulting vector. */ #[inline] - pure fn filter_map<U: Copy>(f: fn(T) -> Option<U>) -> ~[U] { + pure fn filter_map<U: Copy>(f: fn(t: &T) -> Option<U>) -> ~[U] { filter_map(self, f) } } @@ -1610,10 +1615,16 @@ impl<T: Eq> &[T]: ImmutableEqVector<T> { * elements then none is returned. */ #[inline] - pure fn position(f: fn(T) -> bool) -> Option<uint> { position(self, f) } + pure fn position(f: fn(t: &T) -> bool) -> Option<uint> { + position(self, f) + } + /// Find the first index containing a matching value #[inline] - pure fn position_elem(x: T) -> Option<uint> { position_elem(self, x) } + pure fn position_elem(x: &T) -> Option<uint> { + position_elem(self, x) + } + /** * Find the last index matching some predicate * @@ -1622,15 +1633,21 @@ impl<T: Eq> &[T]: ImmutableEqVector<T> { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rposition(f: fn(T) -> bool) -> Option<uint> { rposition(self, f) } + pure fn rposition(f: fn(t: &T) -> bool) -> Option<uint> { + rposition(self, f) + } + /// Find the last index containing a matching value #[inline] - pure fn rposition_elem(x: T) -> Option<uint> { rposition_elem(self, x) } + pure fn rposition_elem(t: &T) -> Option<uint> { + rposition_elem(self, t) + } } trait ImmutableCopyableVector<T> { - pure fn filter(f: fn(T) -> bool) -> ~[T]; - pure fn rfind(f: fn(T) -> bool) -> Option<T>; + pure fn filter(f: fn(t: &T) -> bool) -> ~[T]; + + pure fn rfind(f: fn(t: &T) -> bool) -> Option<T>; } /// Extension methods for vectors @@ -1643,7 +1660,10 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> { * containing only those elements for which `f` returned true. */ #[inline] - pure fn filter(f: fn(T) -> bool) -> ~[T] { filter(self, f) } + pure fn filter(f: fn(t: &T) -> bool) -> ~[T] { + filter(self, f) + } + /** * Search for the last element that matches a given predicate * @@ -1652,16 +1672,28 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rfind(f: fn(T) -> bool) -> Option<T> { rfind(self, f) } + pure fn rfind(f: fn(t: &T) -> bool) -> Option<T> { rfind(self, f) } } trait MutableVector<T> { fn push(&mut self, +t: T); - fn push_all_move(&mut self, -rhs: ~[const T]); + fn push_all_move(&mut self, +rhs: ~[T]); + fn pop(&mut self) -> T; + fn shift(&mut self) -> T; + fn unshift(&mut self, +x: T); + fn swap_remove(&mut self, index: uint) -> T; + fn truncate(&mut self, newlen: uint); } trait MutableCopyableVector<T: Copy> { fn push_all(&mut self, rhs: &[const T]); + fn grow(&mut self, n: uint, initval: &T); + fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>); + fn grow_set(&mut self, index: uint, initval: &T, +val: T); +} + +trait MutableEqVector<T: Eq> { + fn dedup(&mut self); } impl<T> ~[T]: MutableVector<T> { @@ -1669,15 +1701,53 @@ impl<T> ~[T]: MutableVector<T> { push(self, move t); } - fn push_all_move(&mut self, -rhs: ~[const T]) { + fn push_all_move(&mut self, +rhs: ~[T]) { push_all_move(self, move rhs); } + + fn pop(&mut self) -> T { + pop(self) + } + + fn shift(&mut self) -> T { + shift(self) + } + + fn unshift(&mut self, +x: T) { + unshift(self, x) + } + + fn swap_remove(&mut self, index: uint) -> T { + swap_remove(self, index) + } + + fn truncate(&mut self, newlen: uint) { + truncate(self, newlen); + } } impl<T: Copy> ~[T]: MutableCopyableVector<T> { fn push_all(&mut self, rhs: &[const T]) { push_all(self, rhs); } + + fn grow(&mut self, n: uint, initval: &T) { + grow(self, n, initval); + } + + fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>) { + grow_fn(self, n, op); + } + + fn grow_set(&mut self, index: uint, initval: &T, +val: T) { + grow_set(self, index, initval, val); + } +} + +impl<T: Eq> ~[T]: MutableEqVector<T> { + fn dedup(&mut self) { + dedup(self) + } } /// Unsafe operations @@ -1714,7 +1784,7 @@ mod raw { #[inline(always)] unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] { let mut dst = with_capacity(elts); - set_len(dst, elts); + set_len(&mut dst, elts); as_mut_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts)); move dst } @@ -1727,8 +1797,8 @@ mod raw { * the vector is actually the specified size. */ #[inline(always)] - unsafe fn set_len<T>(&&v: ~[const T], new_len: uint) { - let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) { + let repr: **VecRepr = ::cast::transmute(v); (**repr).unboxed.fill = new_len * sys::size_of::<T>(); } @@ -1742,22 +1812,22 @@ mod raw { * would also make any pointers to it invalid. */ #[inline(always)] - unsafe fn to_ptr<T>(v: &[T]) -> *T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_ptr<T>(+v: &[T]) -> *T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] - unsafe fn to_const_ptr<T>(v: &[const T]) -> *const T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_const_ptr<T>(+v: &[const T]) -> *const T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] - unsafe fn to_mut_ptr<T>(v: &[mut T]) -> *mut T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_mut_ptr<T>(+v: &[mut T]) -> *mut T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } @@ -1782,10 +1852,12 @@ mod raw { } /** - * Unchecked vector index assignment. + * Unchecked vector index assignment. Does not drop the + * old value and hence is only suitable when the vector + * is newly allocated. */ #[inline(always)] - unsafe fn set<T>(v: &[mut T], i: uint, +val: T) { + unsafe fn init_elem<T>(v: &[mut T], i: uint, +val: T) { let mut box = Some(move val); do as_mut_buf(v) |p, _len| { let mut box2 = None; @@ -1963,17 +2035,17 @@ mod tests { fn square_ref(n: &uint) -> uint { return square(*n); } - pure fn is_three(&&n: uint) -> bool { return n == 3u; } + pure fn is_three(n: &uint) -> bool { return *n == 3u; } - pure fn is_odd(&&n: uint) -> bool { return n % 2u == 1u; } + pure fn is_odd(n: &uint) -> bool { return *n % 2u == 1u; } - pure fn is_equal(&&x: uint, &&y:uint) -> bool { return x == y; } + pure fn is_equal(x: &uint, y:&uint) -> bool { return *x == *y; } - fn square_if_odd(&&n: uint) -> Option<uint> { - return if n % 2u == 1u { Some(n * n) } else { None }; + fn square_if_odd(n: &uint) -> Option<uint> { + return if *n % 2u == 1u { Some(*n * *n) } else { None }; } - fn add(&&x: uint, &&y: uint) -> uint { return x + y; } + fn add(+x: uint, y: &uint) -> uint { return x + *y; } #[test] fn test_unsafe_ptrs() { @@ -2103,7 +2175,7 @@ mod tests { fn test_pop() { // Test on-stack pop. let mut v = ~[1, 2, 3]; - let mut e = pop(v); + let mut e = v.pop(); assert (len(v) == 2u); assert (v[0] == 1); assert (v[1] == 2); @@ -2111,7 +2183,7 @@ mod tests { // Test on-heap pop. v = ~[1, 2, 3, 4, 5]; - e = pop(v); + e = v.pop(); assert (len(v) == 4u); assert (v[0] == 1); assert (v[1] == 2); @@ -2123,11 +2195,11 @@ mod tests { #[test] fn test_swap_remove() { let mut v = ~[1, 2, 3, 4, 5]; - let mut e = swap_remove(v, 0); + let mut e = v.swap_remove(0); assert (len(v) == 4); assert e == 1; assert (v[0] == 5); - e = swap_remove(v, 3); + e = v.swap_remove(3); assert (len(v) == 3); assert e == 4; assert (v[0] == 5); @@ -2140,11 +2212,11 @@ mod tests { // Tests that we don't accidentally run destructors twice. let mut v = ~[::private::exclusive(()), ::private::exclusive(()), ::private::exclusive(())]; - let mut _e = swap_remove(v, 0); + let mut _e = v.swap_remove(0); assert (len(v) == 2); - _e = swap_remove(v, 1); + _e = v.swap_remove(1); assert (len(v) == 1); - _e = swap_remove(v, 0); + _e = v.swap_remove(0); assert (len(v) == 0); } @@ -2167,13 +2239,13 @@ mod tests { fn test_grow() { // Test on-stack grow(). let mut v = ~[]; - grow(v, 2u, 1); + v.grow(2u, &1); assert (len(v) == 2u); assert (v[0] == 1); assert (v[1] == 1); // Test on-heap grow(). - grow(v, 3u, 2); + v.grow(3u, &2); assert (len(v) == 5u); assert (v[0] == 1); assert (v[1] == 1); @@ -2185,7 +2257,7 @@ mod tests { #[test] fn test_grow_fn() { let mut v = ~[]; - grow_fn(v, 3u, square); + v.grow_fn(3u, square); assert (len(v) == 3u); assert (v[0] == 0u); assert (v[1] == 1u); @@ -2195,7 +2267,7 @@ mod tests { #[test] fn test_grow_set() { let mut v = ~[1, 2, 3]; - grow_set(v, 4u, 4, 5); + v.grow_set(4u, &4, 5); assert (len(v) == 5u); assert (v[0] == 1); assert (v[1] == 2); @@ -2207,7 +2279,7 @@ mod tests { #[test] fn test_truncate() { let mut v = ~[@6,@5,@4]; - truncate(v, 1); + v.truncate(1); assert(v.len() == 1); assert(*(v[0]) == 6); // If the unsafe block didn't drop things properly, we blow up here. @@ -2217,7 +2289,7 @@ mod tests { fn test_dedup() { fn case(-a: ~[uint], -b: ~[uint]) { let mut v = a; - dedup(v); + v.dedup(); assert(v == b); } case(~[], ~[]); @@ -2233,11 +2305,11 @@ mod tests { #[test] fn test_dedup_unique() { let mut v0 = ~[~1, ~1, ~2, ~3]; - dedup(v0); + v0.dedup(); let mut v1 = ~[~1, ~2, ~2, ~3]; - dedup(v1); + v1.dedup(); let mut v2 = ~[~1, ~2, ~3, ~3]; - dedup(v2); + v2.dedup(); /* * If the ~pointers were leaked or otherwise misused, valgrind and/or * rustrt should raise errors. @@ -2247,11 +2319,11 @@ mod tests { #[test] fn test_dedup_shared() { let mut v0 = ~[@1, @1, @2, @3]; - dedup(v0); + v0.dedup(); let mut v1 = ~[@1, @2, @2, @3]; - dedup(v1); + v1.dedup(); let mut v2 = ~[@1, @2, @3, @3]; - dedup(v2); + v2.dedup(); /* * If the @pointers were leaked or otherwise misused, valgrind and/or * rustrt should raise errors. @@ -2281,7 +2353,7 @@ mod tests { #[test] fn test_map2() { - fn times(&&x: int, &&y: int) -> int { return x * y; } + fn times(x: &int, y: &int) -> int { return *x * *y; } let f = times; let v0 = ~[1, 2, 3, 4, 5]; let v1 = ~[5, 4, 3, 2, 1]; @@ -2307,9 +2379,9 @@ mod tests { assert (w[1] == 9u); assert (w[2] == 25u); - fn halve(&&i: int) -> Option<int> { - if i % 2 == 0 { - return option::Some::<int>(i / 2); + fn halve(i: &int) -> Option<int> { + if *i % 2 == 0 { + return option::Some::<int>(*i / 2); } else { return option::None::<int>; } } fn halve_for_sure(i: &int) -> int { return *i / 2; } @@ -2345,8 +2417,8 @@ mod tests { #[test] fn test_foldl2() { - fn sub(&&a: int, &&b: int) -> int { - a - b + fn sub(+a: int, b: &int) -> int { + a - *b } let mut v = ~[1, 2, 3, 4]; let sum = foldl(0, v, sub); @@ -2355,8 +2427,8 @@ mod tests { #[test] fn test_foldr() { - fn sub(&&a: int, &&b: int) -> int { - a - b + fn sub(a: &int, +b: int) -> int { + *a - b } let mut v = ~[1, 2, 3, 4]; let sum = foldr(v, 0, sub); @@ -2419,23 +2491,23 @@ mod tests { } #[test] - fn test_permute() { + fn test_each_permutation() { let mut results: ~[~[int]]; results = ~[]; - permute(~[], |v| results.push(copy v)); + for each_permutation(~[]) |v| { results.push(from_slice(v)); } assert results == ~[~[]]; results = ~[]; - permute(~[7], |v| results.push(copy v)); + for each_permutation(~[7]) |v| { results.push(from_slice(v)); } assert results == ~[~[7]]; results = ~[]; - permute(~[1,1], |v| results.push(copy v)); + for each_permutation(~[1,1]) |v| { results.push(from_slice(v)); } assert results == ~[~[1,1],~[1,1]]; results = ~[]; - permute(~[5,2,0], |v| results.push(copy v)); + for each_permutation(~[5,2,0]) |v| { results.push(from_slice(v)); } assert results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]; } @@ -2487,19 +2559,19 @@ mod tests { #[test] fn test_position_elem() { - assert position_elem(~[], 1).is_none(); + assert position_elem(~[], &1).is_none(); let v1 = ~[1, 2, 3, 3, 2, 5]; - assert position_elem(v1, 1) == Some(0u); - assert position_elem(v1, 2) == Some(1u); - assert position_elem(v1, 5) == Some(5u); - assert position_elem(v1, 4).is_none(); + assert position_elem(v1, &1) == Some(0u); + assert position_elem(v1, &2) == Some(1u); + assert position_elem(v1, &5) == Some(5u); + assert position_elem(v1, &4).is_none(); } #[test] fn test_position() { - fn less_than_three(&&i: int) -> bool { return i < 3; } - fn is_eighteen(&&i: int) -> bool { return i == 18; } + fn less_than_three(i: &int) -> bool { return *i < 3; } + fn is_eighteen(i: &int) -> bool { return *i == 18; } assert position(~[], less_than_three).is_none(); @@ -2512,7 +2584,7 @@ mod tests { fn test_position_between() { assert position_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert position_between(v, 0u, 0u, f).is_none(); @@ -2540,8 +2612,8 @@ mod tests { fn test_find() { assert find(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert find(v, f) == Some((1, 'b')); @@ -2552,7 +2624,7 @@ mod tests { fn test_find_between() { assert find_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert find_between(v, 0u, 0u, f).is_none(); @@ -2580,8 +2652,8 @@ mod tests { fn test_rposition() { assert find(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert position(v, f) == Some(1u); @@ -2592,7 +2664,7 @@ mod tests { fn test_rposition_between() { assert rposition_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rposition_between(v, 0u, 0u, f).is_none(); @@ -2620,8 +2692,8 @@ mod tests { fn test_rfind() { assert rfind(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rfind(v, f) == Some((3, 'b')); @@ -2632,7 +2704,7 @@ mod tests { fn test_rfind_between() { assert rfind_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rfind_between(v, 0u, 0u, f).is_none(); @@ -2692,7 +2764,7 @@ mod tests { #[test] fn test_split() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert split(~[], f) == ~[]; assert split(~[1, 2], f) == ~[~[1, 2]]; @@ -2703,7 +2775,7 @@ mod tests { #[test] fn test_splitn() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert splitn(~[], 1u, f) == ~[]; assert splitn(~[1, 2], 1u, f) == ~[~[1, 2]]; @@ -2715,7 +2787,7 @@ mod tests { #[test] fn test_rsplit() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert rsplit(~[], f) == ~[]; assert rsplit(~[1, 2], f) == ~[~[1, 2]]; @@ -2725,7 +2797,7 @@ mod tests { #[test] fn test_rsplitn() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert rsplitn(~[], 1u, f) == ~[]; assert rsplitn(~[1, 2], 1u, f) == ~[~[1, 2]]; @@ -2748,9 +2820,9 @@ mod tests { #[test] fn test_connect() { - assert connect(~[], 0) == ~[]; - assert connect(~[~[1], ~[2, 3]], 0) == ~[1, 0, 2, 3]; - assert connect(~[~[1], ~[2], ~[3]], 0) == ~[1, 0, 2, 0, 3]; + assert connect(~[], &0) == ~[]; + assert connect(~[~[1], ~[2, 3]], &0) == ~[1, 0, 2, 3]; + assert connect(~[~[1], ~[2], ~[3]], &0) == ~[1, 0, 2, 0, 3]; } #[test] @@ -2796,7 +2868,7 @@ mod tests { #[test] fn test_unshift() { let mut x = ~[1, 2, 3]; - unshift(x, 0); + x.unshift(0); assert x == ~[0, 1, 2, 3]; } @@ -2804,10 +2876,10 @@ mod tests { fn test_capacity() { let mut v = ~[0u64]; reserve(&mut v, 10u); - assert capacity(v) == 10u; + assert capacity(&v) == 10u; let mut v = ~[0u32]; reserve(&mut v, 10u); - assert capacity(v) == 10u; + assert capacity(&v) == 10u; } #[test] @@ -3012,7 +3084,7 @@ mod tests { #[should_fail] fn test_grow_fn_fail() { let mut v = ~[]; - do grow_fn(v, 100) |i| { + do v.grow_fn(100) |i| { if i == 50 { fail } @@ -3318,7 +3390,7 @@ mod tests { fn test_permute_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do permute(v) |_elt| { + for each_permutation(v) |_elt| { if i == 2 { fail } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 3f6bcd31a73..59de3631118 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -217,7 +217,7 @@ impl Writer { } fn end_tag() { - let last_size_pos = vec::pop::<uint>(self.size_positions); + let last_size_pos = self.size_positions.pop(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as int, io::SeekSet); let size = (cur_pos - last_size_pos - 4u); diff --git a/src/libstd/ebml2.rs b/src/libstd/ebml2.rs index 496010d579e..21a7d7817c9 100644 --- a/src/libstd/ebml2.rs +++ b/src/libstd/ebml2.rs @@ -226,7 +226,7 @@ impl Serializer { } fn end_tag() { - let last_size_pos = vec::pop::<uint>(self.size_positions); + let last_size_pos = self.size_positions.pop(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as int, io::SeekSet); let size = (cur_pos - last_size_pos - 4u); diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 8d27ea5783b..a04eadb7732 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -428,9 +428,8 @@ fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::<Optval>(vals) == 0u { return None::<~str>; } return match vals[0] { - Val(copy s) => - Some::<~str>(s), - _ => None::<~str> + Val(copy s) => Some(s), + _ => None }; } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 059b5c22545..247c13396d0 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -696,7 +696,7 @@ priv impl Deserializer { fn pop(&self) -> &self/Json { if self.stack.len() == 0 { self.stack.push(&self.json); } - vec::pop(self.stack) + self.stack.pop() } } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 1568c6c099f..2a7019f5a58 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -13,7 +13,7 @@ enum List<T> { /// Cregate a list from a vector fn from_vec<T: Copy>(v: &[T]) -> @List<T> { - vec::foldr(v, @Nil::<T>, |h, t| @Cons(h, t)) + vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t)) } /** diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 202ca548d6b..5b2ea0a84a6 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -163,7 +163,7 @@ mod v4 { if vec::len(parts) != 4u { result::Err(fmt!("'%s' doesn't have 4 parts", ip)) } - else if vec::contains(parts, 256u) { + else if vec::contains(parts, &256u) { result::Err(fmt!("invalid octal in addr '%s'", ip)) } else { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index f8347be3d08..699fec961c4 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -800,7 +800,7 @@ impl TcpSocketBuf: io::Reader { if self.read(bytes, 1u) == 0 { fail } else { bytes[0] as int } } fn unread_byte(amt: int) { - vec::unshift((*(self.data)).buf, amt as u8); + self.data.buf.unshift(amt as u8); } fn eof() -> bool { false // noop diff --git a/src/libstd/par.rs b/src/libstd/par.rs index a0c9a1b92fe..9cfcd8c2acb 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -123,17 +123,17 @@ pub fn alli<A: Copy Send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool { do vec::all(map_slices(xs, || { fn~(base: uint, slice : &[A], copy f) -> bool { vec::alli(slice, |i, x| { - f(i + base, x) + f(i + base, *x) }) } - })) |x| { x } + })) |x| { *x } } /// Returns true if the function holds for any elements in the vector. pub fn any<A: Copy Send>(xs: ~[A], f: fn~(A) -> bool) -> bool { do vec::any(map_slices(xs, || { fn~(_base : uint, slice: &[A], copy f) -> bool { - vec::any(slice, |x| f(x)) + vec::any(slice, |x| f(*x)) } - })) |x| { x } + })) |x| { *x } } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index e3927ef188c..1100485e7f1 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -30,7 +30,7 @@ fn mk<T: Copy>() -> SmallIntMap<T> { #[inline(always)] fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, +val: T) { //io::println(fmt!("%?", key)); - self.v.grow_set_elt(key, None, Some(val)); + self.v.grow_set_elt(key, &None, Some(val)); } /** diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 9ea43177cea..691f0e840e6 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -358,7 +358,7 @@ fn filter_tests(opts: &TestOpts, } else { return option::None; } } - vec::filter_map(filtered, |x| filter_fn(&x, filter_str)) + vec::filter_map(filtered, |x| filter_fn(x, filter_str)) }; // Maybe pull out the ignored test and unignore them @@ -374,7 +374,7 @@ fn filter_tests(opts: &TestOpts, } else { return option::None; } }; - vec::filter_map(filtered, |x| filter(&x)) + vec::filter_map(filtered, |x| filter(x)) }; // Sort the tests alphabetically diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index b6d4c2d0fe3..d05c6eadaf6 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -278,7 +278,7 @@ fn map_item(i: @item, cx: ctx, v: vt) { _ => cx.path.push(path_name(i.ident)) } visit::visit_item(i, cx, v); - vec::pop(cx.path); + cx.path.pop(); } fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index a2c935ea6f4..2431947184d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -275,14 +275,14 @@ fn ident_to_path(s: span, +i: ident) -> @path { rp: None, types: ~[]} } -pure fn is_unguarded(&&a: arm) -> bool { +pure fn is_unguarded(a: &arm) -> bool { match a.guard { None => true, _ => false } } -pure fn unguarded_pat(a: arm) -> Option<~[@pat]> { +pure fn unguarded_pat(a: &arm) -> Option<~[@pat]> { if is_unguarded(a) { Some(/* FIXME (#2543) */ copy a.pats) } else { None } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 7ef34d8eb0b..d08edd7af1d 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -163,9 +163,9 @@ fn get_name_value_str_pair(item: @ast::meta_item) -> Option<(~str, ~str)> { fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) -> ~[ast::attribute] { let filter = ( - fn@(a: ast::attribute) -> Option<ast::attribute> { - if get_attr_name(a) == name { - option::Some(a) + fn@(a: &ast::attribute) -> Option<ast::attribute> { + if get_attr_name(*a) == name { + option::Some(*a) } else { option::None } } ); @@ -175,9 +175,9 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) -> /// Searcha list of meta items and return only those with a specific name fn find_meta_items_by_name(metas: ~[@ast::meta_item], name: ~str) -> ~[@ast::meta_item] { - let filter = fn@(&&m: @ast::meta_item) -> Option<@ast::meta_item> { - if get_meta_item_name(m) == name { - option::Some(m) + let filter = fn@(m: &@ast::meta_item) -> Option<@ast::meta_item> { + if get_meta_item_name(*m) == name { + option::Some(*m) } else { option::None } }; return vec::filter_map(metas, filter); @@ -289,8 +289,8 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) -> ~[@ast::meta_item] { return vec::filter_map(items, |item| { - if get_meta_item_name(item) != name { - option::Some(/* FIXME (#2543) */ copy item) + if get_meta_item_name(*item) != name { + option::Some(/* FIXME (#2543) */ copy *item) } else { option::None } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 4ebb8501041..fa14d3b5e99 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -90,8 +90,8 @@ fn expand(cx: ext_ctxt, span: span, _mitem: ast::meta_item, in_items: ~[@ast::item]) -> ~[@ast::item] { - fn not_auto_serialize(a: ast::attribute) -> bool { - attr::get_attr_name(a) != ~"auto_serialize" + fn not_auto_serialize(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) != ~"auto_serialize" } fn filter_attrs(item: @ast::item) -> @ast::item { @@ -102,12 +102,12 @@ fn expand(cx: ext_ctxt, do vec::flat_map(in_items) |in_item| { match in_item.node { ast::item_ty(ty, tps) => { - vec::append(~[filter_attrs(in_item)], + vec::append(~[filter_attrs(*in_item)], ty_fns(cx, in_item.ident, ty, tps)) } ast::item_enum(enum_definition, tps) => { - vec::append(~[filter_attrs(in_item)], + vec::append(~[filter_attrs(*in_item)], enum_fns(cx, in_item.ident, in_item.span, enum_definition.variants, tps)) } @@ -116,7 +116,7 @@ fn expand(cx: ext_ctxt, cx.span_err(span, ~"#[auto_serialize] can only be \ applied to type and enum \ definitions"); - ~[in_item] + ~[*in_item] } } } diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index b51184eefd8..099ba67713f 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -75,8 +75,8 @@ fn expand(cx: ext_ctxt, span: span, _mitem: ast::meta_item, in_items: ~[@ast::item]) -> ~[@ast::item] { - fn not_auto_serialize2(a: ast::attribute) -> bool { - attr::get_attr_name(a) != ~"auto_serialize2" + fn not_auto_serialize2(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) != ~"auto_serialize2" } fn filter_attrs(item: @ast::item) -> @ast::item { @@ -88,19 +88,19 @@ fn expand(cx: ext_ctxt, match item.node { ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_rec_impl(cx, item.span, item.ident, fields, tps), ] }, ast::item_class(@{ fields, _}, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_struct_impl(cx, item.span, item.ident, fields, tps), ] }, ast::item_enum(enum_def, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_enum_impl(cx, item.span, item.ident, enum_def, tps), ] }, @@ -108,7 +108,7 @@ fn expand(cx: ext_ctxt, cx.span_err(span, ~"#[auto_serialize2] can only be applied \ to structs, record types, and enum \ definitions"); - ~[item] + ~[*item] } } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 566cdc4fa21..5f4d86b9860 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -161,7 +161,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn print_backtrace() { } fn backtrace() -> expn_info { self.backtrace } fn mod_push(i: ast::ident) { self.mod_path.push(i); } - fn mod_pop() { vec::pop(self.mod_path); } + fn mod_pop() { self.mod_path.pop(); } fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { match ei { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index dbe475c1b50..22e2cfcde6b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -144,7 +144,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, // decorated with "item decorators", then use that function to transform // the item into a new set of items. let new_items = do vec::flat_map(module_.items) |item| { - do vec::foldr(item.attrs, ~[item]) |attr, items| { + do vec::foldr(item.attrs, ~[*item]) |attr, items| { let mname = match attr.node.value.node { ast::meta_word(n) => n, ast::meta_name_value(n, _) => n, @@ -160,7 +160,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, } }; - return {items: new_items,.. module_}; + return {items: new_items, ..module_}; } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index f93fa830f92..b9b1484ce5a 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -47,7 +47,7 @@ impl message: gen_send { let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); let args_ast = (arg_names, tys).map( - |n, t| cx.arg_mode(n, t, ast::by_copy) + |n, t| cx.arg_mode(*n, *t, ast::by_copy) ); let pipe_ty = cx.ty_path_ast_builder( @@ -129,7 +129,7 @@ impl message: gen_send { let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str())); let args_ast = (arg_names, tys).map( - |n, t| cx.arg_mode(cx.ident_of(n), t, ast::by_copy) + |n, t| cx.arg_mode(cx.ident_of(*n), *t, ast::by_copy) ); let args_ast = vec::append( diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index 51239754635..e16e1c55349 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -307,7 +307,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], while idx < rc { idx_path.push(idx); res.push(recur(repeat_me)); // whew! - vec::pop(*idx_path); + idx_path.pop(); idx += 1u; } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 737694337e3..16e3454ca2c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -219,7 +219,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) /* we append new items to this while we go */ while cur_eis.len() > 0u { /* for each Earley Item */ - let mut ei = vec::pop(cur_eis); + let mut ei = cur_eis.pop(); let idx = ei.idx; let len = ei.elts.len(); @@ -350,13 +350,13 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } else if (next_eis.len() > 0u) { /* Now process the next token */ while(next_eis.len() > 0u) { - cur_eis.push(vec::pop(next_eis)); + cur_eis.push(next_eis.pop()); } rdr.next_token(); } else /* bb_eis.len() == 1 */ { let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE); - let ei = vec::pop(bb_eis); + let ei = bb_eis.pop(); match ei.elts[ei.idx].node { match_nonterminal(_, name, idx) => { ei.matches[idx].push(@matched_nonterminal( diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 558593579bf..a8a41cca6cb 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -82,13 +82,13 @@ pure fn dup_tt_reader(&&r: tt_reader) -> tt_reader { pure fn lookup_cur_matched_by_matched(r: tt_reader, start: @named_match) -> @named_match { - pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match { + pure fn red(+ad: @named_match, idx: &uint) -> @named_match { match *ad { matched_nonterminal(_) => { // end of the line; duplicate henceforth ad } - matched_seq(ads, _) => ads[idx] + matched_seq(ads, _) => ads[*idx] } } vec::foldl(start, r.repeat_idx, red) @@ -122,8 +122,8 @@ fn lockstep_iter_size(t: token_tree, r: tt_reader) -> lis { } match t { tt_delim(tts) | tt_seq(_, tts, _, _) => { - vec::foldl(lis_unconstrained, tts, {|lis, tt| - lis_merge(lis, lockstep_iter_size(tt, r), r) }) + vec::foldl(lis_unconstrained, tts, |lis, tt| + lis_merge(lis, lockstep_iter_size(*tt, r), r)) } tt_tok(*) => lis_unconstrained, tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { @@ -148,7 +148,8 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } tt_frame_up(Some(tt_f)) => { if r.cur.dotdotdoted { - vec::pop(r.repeat_idx); vec::pop(r.repeat_len); + r.repeat_idx.pop(); + r.repeat_len.pop(); } r.cur = tt_f; diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 4f3dafcb21b..088df01985e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -552,7 +552,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { // ...nor do modules fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { return {view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)), - items: vec::filter_map(m.items, |x| fld.fold_item(x))}; + items: vec::filter_map(m.items, |x| fld.fold_item(*x))}; } fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5d1067da762..240c9f34c81 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1111,7 +1111,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { ast::expr_call(func, args, has_block) => { let mut base_args = args; let blk = if has_block { - let blk_arg = vec::pop(base_args); + let blk_arg = base_args.pop(); match blk_arg.node { ast::expr_loop_body(_) => { head(s, ~"for"); } ast::expr_do_body(_) => { head(s, ~"do"); } diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index 38ce7a4fbac..8b1202e632e 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -122,7 +122,7 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { logging::console_off(); let mut args = args; - let binary = vec::shift(args); + let binary = args.shift(); if vec::len(args) == 0u { usage(binary); return; } diff --git a/src/rustc/front/config.rs b/src/rustc/front/config.rs index 7e0d9ec2e86..4577b54fb5c 100644 --- a/src/rustc/front/config.rs +++ b/src/rustc/front/config.rs @@ -50,13 +50,12 @@ fn filter_view_item(cx: ctxt, &&view_item: @ast::view_item fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { - let item_filter = |a| filter_item(cx, a); - let filtered_items = vec::filter_map(m.items, item_filter); - let view_item_filter = |a| filter_view_item(cx, a); - let filtered_view_items = vec::filter_map(m.view_items, view_item_filter); + let filtered_items = vec::filter_map(m.items, |a| filter_item(cx, *a)); + let filtered_view_items = vec::filter_map(m.view_items, + |a| filter_view_item(cx, *a)); return { view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)), - items: vec::filter_map(filtered_items, |x| fld.fold_item(x)) + items: vec::filter_map(filtered_items, |x| fld.fold_item(*x)) }; } @@ -69,11 +68,10 @@ fn filter_foreign_item(cx: ctxt, &&item: @ast::foreign_item) -> fn fold_foreign_mod(cx: ctxt, nm: ast::foreign_mod, fld: fold::ast_fold) -> ast::foreign_mod { - let item_filter = |a| filter_foreign_item(cx, a); - let filtered_items = vec::filter_map(nm.items, item_filter); - let view_item_filter = |a| filter_view_item(cx, a); - let filtered_view_items = vec::filter_map( - nm.view_items, view_item_filter); + let filtered_items = vec::filter_map(nm.items, + |a| filter_foreign_item(cx, *a)); + let filtered_view_items = vec::filter_map(nm.view_items, + |a| filter_view_item(cx, *a)); return { sort: nm.sort, view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)), @@ -100,8 +98,7 @@ fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) -> fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { - let filter = |a| filter_stmt(cx, a); - let filtered_stmts = vec::filter_map(b.stmts, filter); + let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a)); return {view_items: b.view_items, stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)), expr: option::map(&b.expr, |x| fld.fold_expr(*x)), @@ -136,7 +133,7 @@ fn metas_in_cfg(cfg: ast::crate_cfg, metas: ~[@ast::meta_item]) -> bool { // so we can match against them. This is the list of configurations for // which the item is valid let cfg_metas = vec::concat(vec::filter_map(cfg_metas, - |&&i| attr::get_meta_item_list(i) )); + |i| attr::get_meta_item_list(*i))); let has_cfg_metas = vec::len(cfg_metas) > 0u; if !has_cfg_metas { return true; } diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index 55d71ab6950..952d7b9ab79 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -81,8 +81,8 @@ fn fold_mod(cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { } let mod_nomain = - {view_items: m.view_items, items: vec::filter_map(m.items, - |i| nomain(cx, i))}; + {view_items: m.view_items, + items: vec::filter_map(m.items, |i| nomain(cx, *i))}; return fold::noop_fold_mod(mod_nomain, fld); } @@ -122,7 +122,7 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) -> } let res = fold::noop_fold_item(i, fld); - vec::pop(cx.path); + cx.path.pop(); return res; } @@ -152,7 +152,7 @@ fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool { let ignoreattrs = attr::find_attrs_by_name(i.attrs, ~"ignore"); let ignoreitems = attr::attr_metas(ignoreattrs); let cfg_metas = vec::concat(vec::filter_map(ignoreitems, - |&&i| attr::get_meta_item_list(i) )); + |i| attr::get_meta_item_list(*i))); return if vec::is_not_empty(ignoreitems) { config::metas_in_cfg(cx.crate.node.config, cfg_metas) } else { diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 49e79e009da..483f7ea06a9 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -114,7 +114,7 @@ fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) { } fn add_used_crate_file(cstore: cstore, lib: &Path) { - if !vec::contains(p(cstore).used_crate_files, copy *lib) { + if !vec::contains(p(cstore).used_crate_files, lib) { p(cstore).used_crate_files.push(copy *lib); } } @@ -126,7 +126,7 @@ fn get_used_crate_files(cstore: cstore) -> ~[Path] { fn add_used_library(cstore: cstore, lib: ~str) -> bool { assert lib != ~""; - if vec::contains(p(cstore).used_libraries, lib) { return false; } + if vec::contains(p(cstore).used_libraries, &lib) { return false; } p(cstore).used_libraries.push(lib); return true; } diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index d7fd8036c46..0e6bc2aee15 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -980,7 +980,7 @@ fn get_crate_module_paths(intr: @ident_interner, cdata: cmd) res.push((did, path)); } return do vec::filter(res) |x| { - let (_, xp) = x; + let (_, xp) = *x; mods.contains_key(xp) } } diff --git a/src/rustc/middle/borrowck/check_loans.rs b/src/rustc/middle/borrowck/check_loans.rs index 841d54c6b0d..b2469718140 100644 --- a/src/rustc/middle/borrowck/check_loans.rs +++ b/src/rustc/middle/borrowck/check_loans.rs @@ -527,7 +527,7 @@ impl check_loan_ctxt { do vec::iter2(args, arg_tys) |arg, arg_ty| { match ty::resolved_mode(self.tcx(), arg_ty.mode) { ast::by_move => { - self.check_move_out(arg); + self.check_move_out(*arg); } ast::by_mutbl_ref | ast::by_ref | ast::by_copy | ast::by_val => { diff --git a/src/rustc/middle/borrowck/gather_loans.rs b/src/rustc/middle/borrowck/gather_loans.rs index b3f846d47fd..85eae29529f 100644 --- a/src/rustc/middle/borrowck/gather_loans.rs +++ b/src/rustc/middle/borrowck/gather_loans.rs @@ -116,11 +116,11 @@ fn req_loans_in_expr(ex: @ast::expr, do vec::iter2(args, arg_tys) |arg, arg_ty| { match ty::resolved_mode(self.tcx(), arg_ty.mode) { ast::by_mutbl_ref => { - let arg_cmt = self.bccx.cat_expr(arg); + let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_mutbl, scope_r); } ast::by_ref => { - let arg_cmt = self.bccx.cat_expr(arg); + let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_imm, scope_r); } ast::by_val => { diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index a3e85ac56c3..efbeb490db9 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -195,7 +195,7 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful { } } Some(ctor) => { - match is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ), + match is_useful(tcx, vec::filter_map(m, |r| default(tcx, *r) ), vec::tail(v)) { useful_ => useful(left_ty, ctor), u => u @@ -212,7 +212,7 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful { fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor, arity: uint, lty: ty::t) -> useful { - let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) ); + let ms = vec::filter_map(m, |r| specialize(tcx, *r, ctor, arity, lty) ); let could_be_useful = is_useful( tcx, ms, specialize(tcx, v, ctor, arity, lty).get()); match could_be_useful { @@ -269,7 +269,9 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option<ctor> { let mut found = ~[]; for m.each |r| { do option::iter(&pat_ctor_id(tcx, r[0])) |id| { - if !vec::contains(found, *id) { found.push(*id); } + if !vec::contains(found, id) { + found.push(*id); + } } } let variants = ty::enum_variants(tcx, eid); diff --git a/src/rustc/middle/const_eval.rs b/src/rustc/middle/const_eval.rs index 463bf502036..5def18cacc3 100644 --- a/src/rustc/middle/const_eval.rs +++ b/src/rustc/middle/const_eval.rs @@ -41,7 +41,7 @@ enum constness { } fn join(a: constness, b: constness) -> constness { - match (a,b) { + match (a, b) { (integral_const, integral_const) => integral_const, (integral_const, general_const) | (general_const, integral_const) @@ -51,7 +51,7 @@ fn join(a: constness, b: constness) -> constness { } fn join_all(cs: &[constness]) -> constness { - vec::foldl(integral_const, cs, join) + vec::foldl(integral_const, cs, |a, b| join(a, *b)) } fn classify(e: @expr, diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 15a7d8f52b1..b1323d7fc93 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -273,7 +273,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { *bounds, (*bounds).len()); } do vec::iter2(*ts, *bounds) |ty, bound| { - check_bounds(cx, id_to_use, e.span, ty, bound) + check_bounds(cx, id_to_use, e.span, *ty, *bound) } } @@ -377,7 +377,7 @@ fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) { let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; do vec::iter2(*ts, *bounds) |ty, bound| { - check_bounds(cx, aty.id, aty.span, ty, bound) + check_bounds(cx, aty.id, aty.span, *ty, *bound) } } } diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index ce998378fe5..689f69f1ad0 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -955,7 +955,7 @@ impl Liveness { fn propagate_through_block(blk: blk, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.node.expr, succ); do blk.node.stmts.foldr(succ) |stmt, succ| { - self.propagate_through_stmt(stmt, succ) + self.propagate_through_stmt(*stmt, succ) } } @@ -975,7 +975,7 @@ impl Liveness { match decl.node { decl_local(locals) => { do locals.foldr(succ) |local, succ| { - self.propagate_through_local(local, succ) + self.propagate_through_local(*local, succ) } } decl_item(_) => { @@ -1007,7 +1007,7 @@ impl Liveness { fn propagate_through_exprs(exprs: ~[@expr], succ: LiveNode) -> LiveNode { do exprs.foldr(succ) |expr, succ| { - self.propagate_through_expr(expr, succ) + self.propagate_through_expr(*expr, succ) } } @@ -1575,7 +1575,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { match ty::resolved_mode(self.tcx, arg_ty.mode) { by_val | by_copy | by_ref | by_mutbl_ref => {} by_move => { - self.check_move_from_expr(arg_expr, vt); + self.check_move_from_expr(*arg_expr, vt); } } } diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 03efd67a9d5..fc66b5dc7a1 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -1560,7 +1560,7 @@ impl Resolver { path_entry.def_like); let mut pieces = split_str(path_entry.path_string, ~"::"); - let final_ident_str = pop(pieces); + let final_ident_str = pieces.pop(); let final_ident = self.session.ident_of(final_ident_str); // Find the module we need, creating modules along the way if we diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 165ca8e2fc4..6450e48486c 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -581,7 +581,7 @@ fn collect_record_or_struct_fields(m: &[@Match], col: uint) -> ~[ast::ident] { fn extend(idents: &mut ~[ast::ident], field_pats: &[ast::field_pat]) { for field_pats.each |field_pat| { let field_ident = field_pat.ident; - if !vec::any(*idents, |x| x == field_ident) { + if !vec::any(*idents, |x| *x == field_ident) { idents.push(field_ident); } } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 7c70d83bd76..70231357003 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -57,7 +57,7 @@ struct icx_popper { ccx: @crate_ctxt, drop { if self.ccx.sess.count_llvm_insns() { - vec::pop(*(self.ccx.stats.llvm_insn_ctxt)); + self.ccx.stats.llvm_insn_ctxt.pop(); } } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index e75d4db897f..907146be4fd 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -402,7 +402,7 @@ fn revoke_clean(cx: block, val: ValueRef) { do in_scope_cx(cx) |info| { let cleanup_pos = vec::position( info.cleanups, - |cu| match cu { + |cu| match *cu { clean_temp(v, _, _) if v == val => true, _ => false }); diff --git a/src/rustc/middle/trans/controlflow.rs b/src/rustc/middle/trans/controlflow.rs index 5d8b0fbbbe1..68ebf5fa189 100644 --- a/src/rustc/middle/trans/controlflow.rs +++ b/src/rustc/middle/trans/controlflow.rs @@ -158,7 +158,7 @@ fn trans_log(log_ex: @ast::expr, let modpath = vec::append( ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))], vec::filter(bcx.fcx.path, |e| - match e { path_mod(_) => true, _ => false } + match *e { path_mod(_) => true, _ => false } )); let modname = path_str(ccx.sess, modpath); diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index f1077912fec..74dadd2cab4 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -92,7 +92,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { Double => 8, Struct => { do vec::foldl(0, struct_tys(ty)) |a, t| { - uint::max(a, ty_align(t)) + uint::max(a, ty_align(*t)) } } Array => { @@ -113,7 +113,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { Double => 8, Struct => { do vec::foldl(0, struct_tys(ty)) |s, t| { - s + ty_size(t) + s + ty_size(*t) } } Array => { diff --git a/src/rustc/middle/trans/monomorphize.rs b/src/rustc/middle/trans/monomorphize.rs index bbcacec052e..cd8cffa297a 100644 --- a/src/rustc/middle/trans/monomorphize.rs +++ b/src/rustc/middle/trans/monomorphize.rs @@ -33,7 +33,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len()); let hash_id = make_mono_id(ccx, fn_id, substs, vtables, Some(param_uses)); if vec::any(hash_id.params, - |p| match p { mono_precise(_, _) => false, _ => true }) { + |p| match *p { mono_precise(_, _) => false, _ => true }) { must_cast = true; } @@ -243,7 +243,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], let mut i = 0u; vec::map2(*bounds, substs, |bounds, subst| { let mut v = ~[]; - for vec::each(*bounds) |bound| { + for bounds.each |bound| { match *bound { ty::bound_trait(_) => { v.push(meth::vtable_id(ccx, vts[i])); @@ -252,7 +252,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], _ => () } } - (subst, if v.len() > 0u { Some(v) } else { None }) + (*subst, if v.len() > 0u { Some(v) } else { None }) }) } None => { @@ -262,12 +262,12 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], let param_ids = match param_uses { Some(uses) => { vec::map2(precise_param_ids, uses, |id, uses| { - match id { + match *id { (a, b@Some(_)) => mono_precise(a, b), (subst, None) => { - if uses == 0u { + if *uses == 0u { mono_any - } else if uses == type_use::use_repr && + } else if *uses == type_use::use_repr && !ty::type_needs_drop(ccx.tcx, subst) { let llty = type_of::type_of(ccx, subst); diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index b29f40748ed..f0d67b92339 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -206,7 +206,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); vec::iter2(type_uses_for(cx.ccx, id, ts.len()), *ts, |uses, subst| { - type_needs(cx, uses, subst) + type_needs(cx, *uses, *subst) }) } } @@ -239,7 +239,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { typeck::method_static(did) => { do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| { do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), *ts) - |uses, subst| { type_needs(cx, uses, subst)} + |uses, subst| { type_needs(cx, *uses, *subst)} } } typeck::method_param({param_num: param, _}) => { diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 63720eaad2e..397a1cd6aa1 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -2238,7 +2238,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { false } - ty_class(did, _) if vec::contains(*seen, did) => { + ty_class(ref did, _) if vec::contains(*seen, did) => { false } @@ -2246,15 +2246,15 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { seen.push(did); let r = vec::any(class_items_as_fields(cx, did, substs), |f| type_requires(cx, seen, r_ty, f.mt.ty)); - vec::pop(*seen); + seen.pop(); r } ty_tup(ts) => { - vec::any(ts, |t| type_requires(cx, seen, r_ty, t)) + vec::any(ts, |t| type_requires(cx, seen, r_ty, *t)) } - ty_enum(did, _) if vec::contains(*seen, did) => { + ty_enum(ref did, _) if vec::contains(*seen, did) => { false } @@ -2263,11 +2263,11 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { let vs = enum_variants(cx, did); let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { vec::any(variant.args, |aty| { - let sty = subst(cx, substs, aty); + let sty = subst(cx, substs, *aty); type_requires(cx, seen, r_ty, sty) }) }); - vec::pop(*seen); + seen.pop(); r } }; @@ -3063,7 +3063,7 @@ fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { if !type_needs_infer(rt) { return; } // Occurs check! - if vec::contains(vars_in_type(rt), vid) { + if vec::contains(vars_in_type(rt), &vid) { // Maybe this should be span_err -- however, there's an // assertion later on that the type doesn't contain // variables, so in this case we have to be sure to die. diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index e1a0e8bc9ed..a1cfb91ebdc 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -309,7 +309,7 @@ fn check_fn(ccx: @crate_ctxt, fcx.write_ty(info.self_id, info.self_ty); } do vec::iter2(decl.inputs, arg_tys) |input, arg| { - fcx.write_ty(input.id, arg); + fcx.write_ty(input.id, *arg); } // If we don't have any enclosing function scope, it is time to @@ -352,7 +352,7 @@ fn check_fn(ccx: @crate_ctxt, // Add formal parameters. do vec::iter2(arg_tys, decl.inputs) |arg_ty, input| { - assign(input.ty.span, input.id, Some(arg_ty)); + assign(input.ty.span, input.id, Some(*arg_ty)); debug!("Argument %s is assigned to %s", tcx.sess.str_of(input.ident), fcx.inh.locals.get(input.id).to_str()); @@ -807,7 +807,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) { _ => () } } - ty::ty_enum(did, _) => { + ty::ty_enum(ref did, _) => { // Watch out for a type like `enum t = @t`. Such a // type would otherwise infinitely auto-deref. Only // autoderef loops during typeck (basically, this one @@ -818,7 +818,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) { if vec::contains(enum_dids, did) { return (t1, autoderefs); } - enum_dids.push(did); + enum_dids.push(*did); } _ => { /*ok*/ } } @@ -2294,7 +2294,7 @@ fn check_enum_variants(ccx: @crate_ctxt, } _ => () } - if vec::contains(*disr_vals, *disr_val) { + if vec::contains(*disr_vals, &*disr_val) { ccx.tcx.sess.span_err(v.span, ~"discriminator value already exists"); } diff --git a/src/rustc/middle/typeck/check/alt.rs b/src/rustc/middle/typeck/check/alt.rs index 3b299caf872..ace045ec4a7 100644 --- a/src/rustc/middle/typeck/check/alt.rs +++ b/src/rustc/middle/typeck/check/alt.rs @@ -165,7 +165,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, do subpats.iter() |pats| { do vec::iter2(*pats, arg_types) |subpat, arg_ty| { - check_pat(pcx, subpat, arg_ty); + check_pat(pcx, *subpat, *arg_ty); } }; } else if subpats_len > 0u { diff --git a/src/rustc/middle/typeck/check/vtable.rs b/src/rustc/middle/typeck/check/vtable.rs index 38ca571dae5..06f466f74d5 100644 --- a/src/rustc/middle/typeck/check/vtable.rs +++ b/src/rustc/middle/typeck/check/vtable.rs @@ -23,7 +23,7 @@ use util::common::indenter; fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool { vec::any(tps, |bs| { - vec::any(*bs, |b| { + bs.any(|b| { match b { ty::bound_trait(_) => true, _ => false } }) }) @@ -393,7 +393,7 @@ fn connect_trait_tps(fcx: @fn_ctxt, expr: @ast::expr, impl_tys: ~[ty::t], match ty::get(trait_ty).sty { ty::ty_trait(_, substs, _) => { vec::iter2(substs.tps, trait_tys, - |a, b| demand::suptype(fcx, expr.span, a, b)); + |a, b| demand::suptype(fcx, expr.span, *a, *b)); } _ => tcx.sess.impossible_case(expr.span, "connect_trait_tps: \ don't know how to handle a non-trait ty") diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index 630ac8c13a1..18e29981af3 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -725,7 +725,7 @@ fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item) fn compute_bounds(ccx: @crate_ctxt, ast_bounds: @~[ast::ty_param_bound]) -> ty::param_bounds { @do vec::flat_map(*ast_bounds) |b| { - match b { + match *b { ast::bound_send => ~[ty::bound_send], ast::bound_copy => ~[ty::bound_copy], ast::bound_const => ~[ty::bound_const], diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index a0bb828e412..e5aa0debfe1 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -507,7 +507,7 @@ fn rollback_to<V:Copy vid, T:Copy>( vb: &vals_and_bindings<V, T>, len: uint) { while vb.bindings.len() != len { - let (vid, old_v) = vec::pop(vb.bindings); + let (vid, old_v) = vb.bindings.pop(); vb.vals.insert(vid.to_uint(), old_v); } } diff --git a/src/rustc/middle/typeck/infer/region_var_bindings.rs b/src/rustc/middle/typeck/infer/region_var_bindings.rs index 8eabb2c0787..c86850e19d2 100644 --- a/src/rustc/middle/typeck/infer/region_var_bindings.rs +++ b/src/rustc/middle/typeck/infer/region_var_bindings.rs @@ -1192,7 +1192,7 @@ impl RegionVarBindings { set.insert(*orig_node_idx, ()); let mut result = ~[]; while !vec::is_empty(stack) { - let node_idx = vec::pop(stack); + let node_idx = stack.pop(); for self.each_edge(graph, node_idx, dir) |edge| { match edge.constraint { ConstrainVarSubVar(from_vid, to_vid) => { diff --git a/src/rustc/middle/typeck/infer/resolve.rs b/src/rustc/middle/typeck/infer/resolve.rs index a366a2ef1c7..2a851a5f7bb 100644 --- a/src/rustc/middle/typeck/infer/resolve.rs +++ b/src/rustc/middle/typeck/infer/resolve.rs @@ -170,7 +170,7 @@ impl resolve_state { } fn resolve_ty_var(vid: TyVid) -> ty::t { - if vec::contains(self.v_seen, vid) { + if vec::contains(self.v_seen, &vid) { self.err = Some(cyclic_ty(vid)); return ty::mk_var(self.infcx.tcx, vid); } else { @@ -197,7 +197,7 @@ impl resolve_state { ty::mk_var(tcx, vid) } }; - vec::pop(self.v_seen); + self.v_seen.pop(); return t1; } } diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index b3ba7f14109..71a32dc112f 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -236,7 +236,7 @@ fn merge_method_attrs( { desc: desc, - .. doc + ..*doc } } } diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index c57e712c020..d601d6d92d1 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -228,8 +228,8 @@ fn maybe_find_pandoc( }; let pandoc = do vec::find(possible_pandocs) |pandoc| { - let output = program_output(pandoc, ~[~"--version"]); - debug!("testing pandoc cmd %s: %?", pandoc, output); + let output = program_output(*pandoc, ~[~"--version"]); + debug!("testing pandoc cmd %s: %?", *pandoc, output); output.status == 0 }; diff --git a/src/rustdoc/desc_to_brief_pass.rs b/src/rustdoc/desc_to_brief_pass.rs index b517c2f2409..3fcce7db6c4 100644 --- a/src/rustdoc/desc_to_brief_pass.rs +++ b/src/rustdoc/desc_to_brief_pass.rs @@ -165,7 +165,7 @@ fn paragraphs(s: ~str) -> ~[~str] { let paras = do vec::foldl(~[], lines) |paras, line| { let mut res = paras; - if str::is_whitespace(line) { + if str::is_whitespace(*line) { whitespace_lines += 1; } else { if whitespace_lines > 0 { @@ -178,9 +178,9 @@ fn paragraphs(s: ~str) -> ~[~str] { whitespace_lines = 0; accum = if str::is_empty(accum) { - line + *line } else { - accum + ~"\n" + line + accum + ~"\n" + *line } } diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index 82bddf11d16..0764d9e2432 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -378,7 +378,7 @@ impl IndexEntry : cmp::Eq { impl Doc { fn CrateDoc() -> CrateDoc { option::get(&vec::foldl(None, self.pages, |_m, page| { - match page { + match *page { doc::CratePage(doc) => Some(doc), _ => None } @@ -395,7 +395,7 @@ impl ModDoc { fn mods() -> ~[ModDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ModTag(ModDoc) => Some(ModDoc), _ => None } @@ -404,7 +404,7 @@ impl ModDoc { fn nmods() -> ~[NmodDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { NmodTag(nModDoc) => Some(nModDoc), _ => None } @@ -413,7 +413,7 @@ impl ModDoc { fn fns() -> ~[FnDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { FnTag(FnDoc) => Some(FnDoc), _ => None } @@ -422,7 +422,7 @@ impl ModDoc { fn consts() -> ~[ConstDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ConstTag(ConstDoc) => Some(ConstDoc), _ => None } @@ -431,7 +431,7 @@ impl ModDoc { fn enums() -> ~[EnumDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { EnumTag(EnumDoc) => Some(EnumDoc), _ => None } @@ -440,7 +440,7 @@ impl ModDoc { fn traits() -> ~[TraitDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { TraitTag(TraitDoc) => Some(TraitDoc), _ => None } @@ -449,7 +449,7 @@ impl ModDoc { fn impls() -> ~[ImplDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ImplTag(ImplDoc) => Some(ImplDoc), _ => None } @@ -458,7 +458,7 @@ impl ModDoc { fn types() -> ~[TyDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { TyTag(TyDoc) => Some(TyDoc), _ => None } @@ -467,7 +467,7 @@ impl ModDoc { fn structs() -> ~[StructDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { StructTag(StructDoc) => Some(StructDoc), _ => None } @@ -490,7 +490,7 @@ impl ~[Page]: PageUtils { fn mods() -> ~[ModDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ModTag(ModDoc)) => Some(ModDoc), _ => None } @@ -499,7 +499,7 @@ impl ~[Page]: PageUtils { fn nmods() -> ~[NmodDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(NmodTag(nModDoc)) => Some(nModDoc), _ => None } @@ -508,7 +508,7 @@ impl ~[Page]: PageUtils { fn fns() -> ~[FnDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(FnTag(FnDoc)) => Some(FnDoc), _ => None } @@ -517,7 +517,7 @@ impl ~[Page]: PageUtils { fn consts() -> ~[ConstDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ConstTag(ConstDoc)) => Some(ConstDoc), _ => None } @@ -526,7 +526,7 @@ impl ~[Page]: PageUtils { fn enums() -> ~[EnumDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(EnumTag(EnumDoc)) => Some(EnumDoc), _ => None } @@ -535,7 +535,7 @@ impl ~[Page]: PageUtils { fn traits() -> ~[TraitDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(TraitTag(TraitDoc)) => Some(TraitDoc), _ => None } @@ -544,7 +544,7 @@ impl ~[Page]: PageUtils { fn impls() -> ~[ImplDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ImplTag(ImplDoc)) => Some(ImplDoc), _ => None } @@ -553,7 +553,7 @@ impl ~[Page]: PageUtils { fn types() -> ~[TyDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(TyTag(TyDoc)) => Some(TyDoc), _ => None } diff --git a/src/rustdoc/page_pass.rs b/src/rustdoc/page_pass.rs index 8710792f0e4..ad3f679a97c 100644 --- a/src/rustdoc/page_pass.rs +++ b/src/rustdoc/page_pass.rs @@ -105,7 +105,7 @@ fn fold_mod( fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc { doc::ModDoc_({ items: do vec::filter(doc.items) |item| { - match item { + match *item { doc::ModTag(_) => false, doc::NmodTag(_) => false, _ => true diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs index 96ed269a7e9..f6a241fdac8 100644 --- a/src/rustdoc/path_pass.rs +++ b/src/rustdoc/path_pass.rs @@ -45,7 +45,7 @@ fn fold_mod(fold: fold::Fold<Ctxt>, doc: doc::ModDoc) -> doc::ModDoc { if !is_topmod { fold.ctxt.path.push(doc.name()); } let doc = fold::default_any_fold_mod(fold, doc); - if !is_topmod { vec::pop(fold.ctxt.path); } + if !is_topmod { fold.ctxt.path.pop(); } doc::ModDoc_({ item: fold.fold_item(fold, doc.item), @@ -56,7 +56,7 @@ fn fold_mod(fold: fold::Fold<Ctxt>, doc: doc::ModDoc) -> doc::ModDoc { fn fold_nmod(fold: fold::Fold<Ctxt>, doc: doc::NmodDoc) -> doc::NmodDoc { fold.ctxt.path.push(doc.name()); let doc = fold::default_seq_fold_nmod(fold, doc); - vec::pop(fold.ctxt.path); + fold.ctxt.path.pop(); { item: fold.fold_item(fold, doc.item), diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs index 62db53b7600..5e2d141318a 100644 --- a/src/rustdoc/tystr_pass.rs +++ b/src/rustdoc/tystr_pass.rs @@ -177,7 +177,7 @@ fn get_method_sig( node: ast::item_trait(_, _, methods), _ }, _) => { match vec::find(methods, |method| { - match method { + match *method { ast::required(ty_m) => to_str(ty_m.ident) == method_name, ast::provided(m) => to_str(m.ident) == method_name, } diff --git a/src/rustdoc/unindent_pass.rs b/src/rustdoc/unindent_pass.rs index 42c9e80ab7b..aa31892d466 100644 --- a/src/rustdoc/unindent_pass.rs +++ b/src/rustdoc/unindent_pass.rs @@ -29,7 +29,7 @@ fn unindent(s: ~str) -> ~str { let ignore_previous_indents = saw_first_line && !saw_second_line && - !str::is_whitespace(line); + !str::is_whitespace(*line); let min_indent = if ignore_previous_indents { uint::max_value @@ -41,12 +41,12 @@ fn unindent(s: ~str) -> ~str { saw_second_line = true; } - if str::is_whitespace(line) { + if str::is_whitespace(*line) { min_indent } else { saw_first_line = true; let mut spaces = 0; - do str::all(line) |char| { + do str::all(*line) |char| { // Only comparing against space because I wouldn't // know what to do with mixed whitespace chars if char == ' ' { diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 9454ef7aec7..cf44d478356 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -47,7 +47,7 @@ fn shift_push() { let mut v2 = ~[]; while v1.len() > 0 { - v2.push(vec::shift(v1)); + v2.push(v1.shift()); } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index ef2fa8dfa9e..10b38f2572c 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -97,7 +97,7 @@ fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] { let k = r.gen_uint_range(0u, graph.len()); if graph[k].len() > 0u && vec::any(graph[k], |i| { - i != k as node_id + *i != k as node_id }) { map::set_add(keys, k as node_id); } @@ -160,8 +160,8 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } }; - fn is_gray(c: color) -> bool { - match c { + fn is_gray(c: &color) -> bool { + match *c { gray(_) => { true } _ => { false } } @@ -183,7 +183,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { let mut color = white; do neighbors.each() |k| { - if is_gray(colors[*k]) { + if is_gray(&colors[*k]) { color = gray(*k); false } @@ -314,7 +314,7 @@ fn validate(edges: ~[(node_id, node_id)], } else { while parent != root { - if vec::contains(path, parent) { + if vec::contains(path, &parent) { status = false; } @@ -336,8 +336,8 @@ fn validate(edges: ~[(node_id, node_id)], log(info, ~"Verifying tree edges..."); let status = do tree.alli() |k, parent| { - if parent != root && parent != -1i64 { - level[parent] == level[k] - 1 + if *parent != root && *parent != -1i64 { + level[*parent] == level[k] - 1 } else { true diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 2931cab248f..ec144b78a10 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -27,7 +27,7 @@ fn recv(p: &pipe) -> uint { while vec::is_empty(*state) { cond.wait(); } - vec::pop(*state) + state.pop() } } diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 525cf8f1c50..1b857b6caeb 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -27,7 +27,7 @@ fn recv(p: &pipe) -> uint { while vec::is_empty(*state) { cond.wait(); } - vec::pop(*state) + state.pop() } } diff --git a/src/test/compile-fail/block-arg-as-stmt-with-value.rs b/src/test/compile-fail/block-arg-as-stmt-with-value.rs index b8e34aefd6f..15154ab5a4e 100644 --- a/src/test/compile-fail/block-arg-as-stmt-with-value.rs +++ b/src/test/compile-fail/block-arg-as-stmt-with-value.rs @@ -2,7 +2,7 @@ fn compute1() -> float { let v = ~[0f, 1f, 2f, 3f]; - do vec::foldl(0f, v) |x, y| { x + y } - 10f + do vec::foldl(0f, v) |x, y| { x + *y } - 10f //~^ ERROR mismatched types: expected `()` } diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index 638f14f8794..276862ce106 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -7,7 +7,7 @@ fn broken() -> int { y += ~[&mut z]; //~ ERROR illegal borrow x += 1; } - vec::foldl(0, y, |v, p| v + *p ) + vec::foldl(0, y, |v, p| v + **p ) } fn main() { } \ No newline at end of file diff --git a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs index 53f158471e8..bab28a06934 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs @@ -2,7 +2,7 @@ fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; // Trailing expressions don't require parentheses: - let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f; + let y = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; assert y == 15f; } diff --git a/src/test/run-pass/block-arg-in-parentheses.rs b/src/test/run-pass/block-arg-in-parentheses.rs index 14b05b29dc3..1121cc4dd2f 100644 --- a/src/test/run-pass/block-arg-in-parentheses.rs +++ b/src/test/run-pass/block-arg-in-parentheses.rs @@ -1,20 +1,20 @@ fn w_semi(v: ~[int]) -> int { // the semicolon causes compiler not to // complain about the ignored return value: - do vec::foldl(0, v) |x,y| { x+y }; + do vec::foldl(0, v) |x,y| { x+*y }; -10 } fn w_paren1(v: ~[int]) -> int { - (do vec::foldl(0, v) |x,y| { x+y }) - 10 + (do vec::foldl(0, v) |x,y| { x+*y }) - 10 } fn w_paren2(v: ~[int]) -> int { - (do vec::foldl(0, v) |x,y| { x+y} - 10) + (do vec::foldl(0, v) |x,y| { x+*y} - 10) } fn w_ret(v: ~[int]) -> int { - return do vec::foldl(0, v) |x,y| { x+y } - 10; + return do vec::foldl(0, v) |x,y| { x+*y } - 10; } fn main() { diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 5953e0b85fb..0f77a0e0816 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -8,28 +8,28 @@ fn main() { } // Usable at all: - let mut any_negative = do vec::any(v) |e| { float::is_negative(e) }; + let mut any_negative = do vec::any(v) |e| { float::is_negative(*e) }; assert any_negative; // Higher precedence than assignments: - any_negative = do vec::any(v) |e| { float::is_negative(e) }; + any_negative = do vec::any(v) |e| { float::is_negative(*e) }; assert any_negative; // Higher precedence than unary operations: let abs_v = do vec::map(v) |e| { float::abs(*e) }; - assert do vec::all(abs_v) |e| { float::is_nonnegative(e) }; - assert !do vec::any(abs_v) |e| { float::is_negative(e) }; + assert do vec::all(abs_v) |e| { float::is_nonnegative(*e) }; + assert !do vec::any(abs_v) |e| { float::is_negative(*e) }; // Usable in funny statement-like forms: - if !do vec::any(v) |e| { float::is_positive(e) } { + if !do vec::any(v) |e| { float::is_positive(*e) } { assert false; } - match do vec::all(v) |e| { float::is_negative(e) } { + match do vec::all(v) |e| { float::is_negative(*e) } { true => { fail ~"incorrect answer."; } false => { } } match 3 { - _ if do vec::any(v) |e| { float::is_negative(e) } => { + _ if do vec::any(v) |e| { float::is_negative(*e) } => { } _ => { fail ~"wrong answer."; @@ -38,15 +38,15 @@ fn main() { // Lower precedence than binary operations: - let w = do vec::foldl(0f, v) |x, y| { x + y } + 10f; - let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f; - let z = 10f + do vec::foldl(0f, v) |x, y| { x + y }; + let w = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; + let y = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; + let z = 10f + do vec::foldl(0f, v) |x, y| { x + *y }; assert w == y; assert y == z; // In the tail of a block let w = - if true { do vec::any(abs_v) |e| { float::is_nonnegative(e) } } + if true { do vec::any(abs_v) |e| { float::is_nonnegative(*e) } } else { false }; assert w; } diff --git a/src/test/run-pass/block-vec-map2.rs b/src/test/run-pass/block-vec-map2.rs index 332afc65f72..d270800de11 100644 --- a/src/test/run-pass/block-vec-map2.rs +++ b/src/test/run-pass/block-vec-map2.rs @@ -4,7 +4,7 @@ fn main() { let v = vec::map2(~[1, 2, 3, 4, 5], ~[true, false, false, true, true], - |i, b| if b { -i } else { i } ); + |i, b| if *b { -(*i) } else { *i } ); log(error, v); assert (v == ~[-1, 2, 3, -4, -5]); } diff --git a/src/test/run-pass/ret-break-cont-in-block.rs b/src/test/run-pass/ret-break-cont-in-block.rs index 9013842ba8b..4e7e978cf55 100644 --- a/src/test/run-pass/ret-break-cont-in-block.rs +++ b/src/test/run-pass/ret-break-cont-in-block.rs @@ -43,10 +43,10 @@ fn ret_deep() -> ~str { fn main() { let mut last = 0; for vec::all(~[1, 2, 3, 4, 5, 6, 7]) |e| { - last = e; - if e == 5 { break; } - if e % 2 == 1 { loop; } - assert e % 2 == 0; + last = *e; + if *e == 5 { break; } + if *e % 2 == 1 { loop; } + assert *e % 2 == 0; }; assert last == 5; |
