diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 7846d3d030240..ede3c0eb3279c 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -218,40 +218,39 @@ pub pure fn cast_from_mut(v: ~[mut T]) -> ~[T] { // Accessors /// Returns the first element of a vector -pub pure fn head(v: &[const T]) -> T { v[0] } - -/// Returns a vector containing all but the first element of a slice -pub pure fn tail(v: &[const T]) -> ~[T] { - return slice(v, 1u, len(v)); +pub pure fn head(v: &r/[T]) -> &r/T { + if v.len() == 0 { die!(~"last_unsafe: empty vector") } + &v[0] } -/** - * Returns a vector containing all but the first `n` \ - * elements of a slice - */ -pub pure fn tailn(v: &[const T], n: uint) -> ~[T] { - slice(v, n, len(v)) +/// Returns `Some(x)` where `x` is the first element of the slice `v`, +/// or `None` if the vector is empty. +pub pure fn head_opt(v: &r/[T]) -> Option<&r/T> { + if v.len() == 0 { None } else { Some(&v[0]) } } +/// Returns a vector containing all but the first element of a slice +pub pure fn tail(v: &r/[T]) -> &r/[T] { view(v, 1, v.len()) } + +/// Returns a vector containing all but the first `n` * elements of a slice +pub pure fn tailn(v: &r/[T], n: uint) -> &r/[T] { view(v, n, v.len()) } + /// Returns a vector containing all but the last element of a slice -pub pure fn init(v: &[const T]) -> ~[T] { - assert len(v) != 0u; - slice(v, 0u, len(v) - 1u) -} +pub pure fn init(v: &r/[T]) -> &r/[T] { view(v, 0, v.len() - 1) } + +/// Returns a vector containing all but the last `n' elements of a slice +pub pure fn initn(v: &r/[T], n: uint) -> &r/[T] { view(v, 0, v.len() - n) } /// Returns the last element of the slice `v`, failing if the slice is empty. -pub pure fn last(v: &[const T]) -> T { - if len(v) == 0u { die!(~"last_unsafe: empty vector") } - v[len(v) - 1u] +pub pure fn last(v: &r/[T]) -> &r/T { + if v.len() == 0 { die!(~"last_unsafe: empty vector") } + &v[v.len() - 1] } -/** - * Returns `Some(x)` where `x` is the last element of the slice `v`, - * or `none` if the vector is empty. - */ -pub pure fn last_opt(v: &[const T]) -> Option { - if len(v) == 0u { return None; } - Some(v[len(v) - 1u]) +/// Returns `Some(x)` where `x` is the last element of the slice `v`, or +/// `None` if the vector is empty. +pub pure fn last_opt(v: &r/[T]) -> Option<&r/T> { + if v.len() == 0 { None } else { Some(&v[v.len() - 1]) } } /// Returns a copy of the elements from [`start`..`end`) from `v`. @@ -1655,40 +1654,28 @@ impl &[const T]: Container { } pub trait CopyableVector { - pure fn head(&self) -> T; - pure fn init(&self) -> ~[T]; - pure fn last(&self) -> T; pure fn slice(&self, start: uint, end: uint) -> ~[T]; - pure fn tail(&self) -> ~[T]; } /// Extension methods for vectors impl &[const T]: CopyableVector { - /// Returns the first element of a vector - #[inline] - pure fn head(&self) -> T { head(*self) } - - /// Returns all but the last elemnt of a vector - #[inline] - pure fn init(&self) -> ~[T] { init(*self) } - - /// Returns the last element of a `v`, failing if the vector is empty. - #[inline] - pure fn last(&self) -> T { last(*self) } - /// Returns a copy of the elements from [`start`..`end`) from `v`. #[inline] pure fn slice(&self, start: uint, end: uint) -> ~[T] { slice(*self, start, end) } - - /// Returns all but the first element of a vector - #[inline] - pure fn tail(&self) -> ~[T] { tail(*self) } } pub trait ImmutableVector { pure fn view(&self, start: uint, end: uint) -> &self/[T]; + pure fn head(&self) -> &self/T; + pure fn head_opt(&self) -> Option<&self/T>; + pure fn tail(&self) -> &self/[T]; + pure fn tailn(&self, n: uint) -> &self/[T]; + pure fn init(&self) -> &self/[T]; + pure fn initn(&self, n: uint) -> &self/[T]; + pure fn last(&self) -> &self/T; + pure fn last_opt(&self) -> Option<&self/T>; pure fn foldr(&self, z: U, p: fn(t: &T, u: U) -> U) -> U; pure fn map(&self, f: fn(t: &T) -> U) -> ~[U]; pure fn mapi(&self, f: fn(uint, t: &T) -> U) -> ~[U]; @@ -1706,6 +1693,38 @@ impl &[T]: ImmutableVector { view(*self, start, end) } + /// Returns the first element of a vector, failing if the vector is empty. + #[inline] + pure fn head(&self) -> &self/T { head(*self) } + + /// Returns the first element of a vector + #[inline] + pure fn head_opt(&self) -> Option<&self/T> { head_opt(*self) } + + /// Returns all but the first element of a vector + #[inline] + pure fn tail(&self) -> &self/[T] { tail(*self) } + + /// Returns all but the first `n' elements of a vector + #[inline] + pure fn tailn(&self, n: uint) -> &self/[T] { tailn(*self, n) } + + /// Returns all but the last elemnt of a vector + #[inline] + pure fn init(&self) -> &self/[T] { init(*self) } + + /// Returns all but the last `n' elemnts of a vector + #[inline] + pure fn initn(&self, n: uint) -> &self/[T] { initn(*self, n) } + + /// Returns the last element of a `v`, failing if the vector is empty. + #[inline] + pure fn last(&self) -> &self/T { last(*self) } + + /// Returns the last element of a `v`, failing if the vector is empty. + #[inline] + pure fn last_opt(&self) -> Option<&self/T> { last_opt(*self) } + /// Reduce a vector from right to left #[inline] pure fn foldr(&self, z: U, p: fn(t: &T, u: U) -> U) -> U { @@ -2527,27 +2546,117 @@ mod tests { #[test] fn test_head() { - let a = ~[11, 12]; - assert (head(a) == 11); + let mut a = ~[11]; + assert a.head() == &11; + a = ~[11, 12]; + assert a.head() == &11; + } + + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_head_empty() { + let a: ~[int] = ~[]; + a.head(); + } + + #[test] + fn test_head_opt() { + let mut a = ~[]; + assert a.head_opt() == None; + a = ~[11]; + assert a.head_opt().unwrap() == &11; + a = ~[11, 12]; + assert a.head_opt().unwrap() == &11; } #[test] fn test_tail() { let mut a = ~[11]; - assert (tail(a) == ~[]); + assert a.tail() == &[]; + a = ~[11, 12]; + assert a.tail() == &[12]; + } + + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_tail_empty() { + let a: ~[int] = ~[]; + a.tail(); + } + #[test] + fn test_tailn() { + let mut a = ~[11, 12, 13]; + assert a.tailn(0) == &[11, 12, 13]; + a = ~[11, 12, 13]; + assert a.tailn(2) == &[13]; + } + + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_tailn_empty() { + let a: ~[int] = ~[]; + a.tailn(2); + } + + #[test] + fn test_init() { + let mut a = ~[11]; + assert a.init() == &[]; a = ~[11, 12]; - assert (tail(a) == ~[12]); + assert a.init() == &[11]; + } + + #[init] + #[should_fail] + #[ignore(cfg(windows))] + fn test_init_empty() { + let a: ~[int] = ~[]; + a.init(); + } + + #[test] + fn test_initn() { + let mut a = ~[11, 12, 13]; + assert a.initn(0) == &[11, 12, 13]; + a = ~[11, 12, 13]; + assert a.initn(2) == &[11]; + } + + #[init] + #[should_fail] + #[ignore(cfg(windows))] + fn test_initn_empty() { + let a: ~[int] = ~[]; + a.initn(2); } #[test] fn test_last() { - let mut n = last_opt(~[]); - assert (n.is_none()); - n = last_opt(~[1, 2, 3]); - assert (n == Some(3)); - n = last_opt(~[1, 2, 3, 4, 5]); - assert (n == Some(5)); + let mut a = ~[11]; + assert a.last() == &11; + a = ~[11, 12]; + assert a.last() == &12; + } + + #[test] + #[should_fail] + fn test_last_empty() { + let a: ~[int] = ~[]; + a.last(); + } + + #[test] + fn test_last_opt() { + let mut a = ~[]; + assert a.last_opt() == None; + a = ~[11]; + assert a.last_opt().unwrap() == &11; + a = ~[11, 12]; + assert a.last_opt().unwrap() == &12; } #[test] @@ -3177,12 +3286,6 @@ mod tests { assert (v2[1] == 10); } - #[test] - fn test_init() { - let v = init(~[1, 2, 3]); - assert v == ~[1, 2]; - } - #[test] fn test_split() { fn f(x: &int) -> bool { *x == 3 } @@ -3247,13 +3350,6 @@ mod tests { (~[], ~[1, 2, 3]); } - #[test] - #[should_fail] - #[ignore(cfg(windows))] - fn test_init_empty() { - init::(~[]); - } - #[test] fn test_concat() { assert concat(~[~[1], ~[2,3]]) == ~[1, 2, 3]; diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 9a6a2f7e95415..cfd6ee5a01423 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -552,7 +552,10 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt, -> csearch::found_ast { debug!("Looking up item: %d", id); let item_doc = lookup_item(id, cdata.data); - let path = vec::init(item_path(intr, item_doc)); + let path = { + let item_path = item_path(intr, item_doc); + vec::from_slice(item_path.init()) + }; match decode_inlined_item(cdata, tcx, path, item_doc) { Some(ref ii) => csearch::found((/*bad*/copy *ii)), None => { @@ -560,8 +563,7 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt, Some(did) => { let did = translate_def_id(cdata, did); let parent_item = lookup_item(did.node, cdata.data); - match decode_inlined_item(cdata, tcx, path, - parent_item) { + match decode_inlined_item(cdata, tcx, path, parent_item) { Some(ref ii) => csearch::found_parent(did, (/*bad*/copy *ii)), None => csearch::not_found } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 072b974d0422a..46100095349ab 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -719,7 +719,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, match ty.node { ast::ty_path(path, _) if path.idents.len() == 1 => { encode_impl_type_basename(ecx, ebml_w, - ast_util::path_to_ident(path)); + *ast_util::path_to_ident(path)); } _ => {} } diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index c4cb154e21f0d..49d91758d279c 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -146,7 +146,7 @@ pub fn crate_name_from_metas(+metas: ~[@ast::meta_item]) -> ~str { let name_items = attr::find_meta_items_by_name(metas, ~"name"); match vec::last_opt(name_items) { Some(i) => { - match attr::get_meta_item_value_str(i) { + match attr::get_meta_item_value_str(*i) { Some(ref n) => (/*bad*/copy *n), // FIXME (#2406): Probably want a warning here since the user // is using the wrong type of meta item. diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 7159946338296..c3c4d94c8a0b3 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -115,7 +115,7 @@ pub fn encode_inlined_item(ecx: @e::encode_ctxt, pub fn decode_inlined_item(cdata: cstore::crate_metadata, tcx: ty::ctxt, maps: Maps, - +path: ast_map::path, + path: ast_map::path, par_doc: ebml::Doc) -> Option { let dcx = @{cdata: cdata, tcx: tcx, maps: maps}; @@ -137,7 +137,7 @@ pub fn decode_inlined_item(cdata: cstore::crate_metadata, ast_map::path_to_str(path, tcx.sess.parse_sess.interner), tcx.sess.str_of(ii.ident())); ast_map::map_decoded_item(tcx.sess.diagnostic(), - dcx.tcx.items, path, ii); + dcx.tcx.items, /*bad*/ copy path, ii); decode_side_tables(xcx, ast_doc); match ii { ast::ii_item(i) => { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 978aaacb18a91..8258ab3c54b86 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -75,7 +75,7 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) { arm.pats); } - check_arms(cx, (/*bad*/copy *arms)); + check_arms(cx, *arms); /* Check for exhaustiveness */ // Check for empty enum, because is_useful only works on inhabited // types. @@ -108,12 +108,12 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) { } // Check for unreachable patterns -pub fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) { +pub fn check_arms(cx: @MatchCheckCtxt, arms: &[arm]) { let mut seen = ~[]; for arms.each |arm| { for arm.pats.each |pat| { let v = ~[*pat]; - match is_useful(cx, copy seen, v) { + match is_useful(cx, &seen, v) { not_useful => { cx.tcx.sess.span_err(pat.span, ~"unreachable pattern"); } @@ -133,7 +133,7 @@ pub fn raw_pat(p: @pat) -> @pat { pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) { assert(!pats.is_empty()); - let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) { + let ext = match is_useful(cx, &pats.map(|p| ~[*p]), ~[wild()]) { not_useful => return, // This is good, wildcard pattern isn't reachable useful_ => None, useful(ty, ref ctor) => { @@ -171,12 +171,12 @@ pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) { cx.tcx.sess.span_err(sp, msg); } -pub type matrix = ~[~[@pat]]; +type matrix = ~[~[@pat]]; -pub enum useful { useful(ty::t, ctor), useful_, not_useful } +enum useful { useful(ty::t, ctor), useful_, not_useful } #[deriving_eq] -pub enum ctor { +enum ctor { single, variant(def_id), val(const_val), @@ -197,10 +197,10 @@ pub enum ctor { // Note: is_useful doesn't work on empty types, as the paper notes. // So it assumes that v is non-empty. -pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful { +pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful { if m.len() == 0u { return useful_; } if m[0].len() == 0u { return not_useful; } - let real_pat = match vec::find(m, |r| r[0].id != 0) { + let real_pat = match m.find(|r| r[0].id != 0) { Some(r) => r[0], None => v[0] }; let left_ty = if real_pat.id == 0 { ty::mk_nil(cx.tcx) } @@ -255,8 +255,8 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful { } } Some(ref ctor) => { - match is_useful(cx, vec::filter_map(m, |r| default(cx, copy *r)), - vec::tail(v)) { + match is_useful(cx, &m.filter_map(|r| default(cx, *r)), + v.tail()) { useful_ => useful(left_ty, (/*bad*/copy *ctor)), ref u => (/*bad*/copy *u) } @@ -271,16 +271,15 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful { } pub fn is_useful_specialized(cx: @MatchCheckCtxt, - m: matrix, - +v: &[@pat], + m: &matrix, + v: &[@pat], +ctor: ctor, arity: uint, lty: ty::t) -> useful { - let ms = vec::filter_map(m, |r| specialize(cx, *r, - ctor, arity, lty)); + let ms = m.filter_map(|r| specialize(cx, *r, ctor, arity, lty)); let could_be_useful = is_useful( - cx, ms, specialize(cx, v, ctor, arity, lty).get()); + cx, &ms, specialize(cx, v, ctor, arity, lty).get()); match could_be_useful { useful_ => useful(lty, ctor), ref u => (/*bad*/copy *u) @@ -339,7 +338,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool { } pub fn missing_ctor(cx: @MatchCheckCtxt, - m: matrix, + m: &matrix, left_ty: ty::t) -> Option { match ty::get(left_ty).sty { @@ -467,7 +466,7 @@ pub fn wild() -> @pat { } pub fn specialize(cx: @MatchCheckCtxt, - +r: &[@pat], + r: &[@pat], ctor_id: ctor, arity: uint, left_ty: ty::t) @@ -478,12 +477,13 @@ pub fn specialize(cx: @MatchCheckCtxt, pat{id: pat_id, node: n, span: pat_span} => match n { pat_wild => Some(vec::append(vec::from_elem(arity, wild()), - vec::tail(r))), + vec::from_slice(r.tail()))), pat_ident(_, _, _) => { match cx.tcx.def_map.find(&pat_id) { Some(def_variant(_, id)) => { - if variant(id) == ctor_id { Some(vec::tail(r)) } - else { None } + if variant(id) == ctor_id { + Some(vec::from_slice(r.tail())) + } else { None } } Some(def_const(did)) => { let const_expr = @@ -498,10 +498,12 @@ pub fn specialize(cx: @MatchCheckCtxt, single => true, _ => die!(~"type error") }; - if match_ { Some(vec::tail(r)) } else { None } + if match_ { + Some(vec::from_slice(r.tail())) + } else { None } } _ => Some(vec::append(vec::from_elem(arity, wild()), - vec::tail(r))) + vec::from_slice(r.tail()))) } } pat_enum(_, args) => { @@ -511,7 +513,7 @@ pub fn specialize(cx: @MatchCheckCtxt, Some(args) => args, None => vec::from_elem(arity, wild()) }; - Some(vec::append(args, vec::tail(r))) + Some(vec::append(args, vec::from_slice(r.tail()))) } def_variant(_, _) => None, def_struct(*) => { @@ -521,7 +523,7 @@ pub fn specialize(cx: @MatchCheckCtxt, Some(args) => new_args = args, None => new_args = vec::from_elem(arity, wild()) } - Some(vec::append(new_args, vec::tail(r))) + Some(vec::append(new_args, vec::from_slice(r.tail()))) } _ => None } @@ -537,7 +539,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => wild() } }); - Some(vec::append(args, vec::tail(r))) + Some(vec::append(args, vec::from_slice(r.tail()))) } pat_struct(_, ref flds, _) => { // Is this a struct or an enum variant? @@ -552,7 +554,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => wild() } }); - Some(vec::append(args, vec::tail(r))) + Some(vec::append(args, vec::from_slice(r.tail()))) } else { None } @@ -579,13 +581,15 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => wild() } }); - Some(vec::append(args, vec::tail(r))) + Some(vec::append(args, vec::from_slice(r.tail()))) } } } - pat_tup(args) => Some(vec::append(args, vec::tail(r))), + pat_tup(args) => { + Some(vec::append(args, vec::from_slice(r.tail()))) + } pat_box(a) | pat_uniq(a) | pat_region(a) => - Some(vec::append(~[a], vec::tail(r))), + Some(vec::append(~[a], vec::from_slice(r.tail()))), pat_lit(expr) => { let e_v = eval_const_expr(cx.tcx, expr); let match_ = match ctor_id { @@ -597,21 +601,21 @@ pub fn specialize(cx: @MatchCheckCtxt, single => true, _ => die!(~"type error") }; - if match_ { Some(vec::tail(r)) } else { None } + if match_ { Some(vec::from_slice(r.tail())) } else { None } } pat_range(lo, hi) => { let (c_lo, c_hi) = match ctor_id { val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)), range(ref lo, ref hi) => ((/*bad*/copy *lo), (/*bad*/copy *hi)), - single => return Some(vec::tail(r)), + single => return Some(vec::from_slice(r.tail())), _ => die!(~"type error") }; let v_lo = eval_const_expr(cx.tcx, lo), v_hi = eval_const_expr(cx.tcx, hi); let match_ = compare_const_vals(c_lo, v_lo) >= 0 && compare_const_vals(c_hi, v_hi) <= 0; - if match_ { Some(vec::tail(r)) } else { None } + if match_ { Some(vec::from_slice(r.tail())) } else { None } } pat_vec(elems, tail) => { match ctor_id { @@ -622,10 +626,11 @@ pub fn specialize(cx: @MatchCheckCtxt, vec::append(elems, vec::from_elem( arity - num_elements, wild() )), - vec::tail(r) + vec::from_slice(r.tail()) )) } else if num_elements == arity { - Some(vec::append(elems, vec::tail(r))) + Some(vec::append(elems, + vec::from_slice(r.tail()))) } else { None } @@ -637,8 +642,8 @@ pub fn specialize(cx: @MatchCheckCtxt, } } -pub fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> { - if is_wild(cx, r[0]) { Some(vec::tail(r)) } +pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> { + if is_wild(cx, r[0]) { Some(vec::from_slice(r.tail())) } else { None } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 9240bc5fbc88e..d622da1a6af7f 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -448,7 +448,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, do pat_util::pat_bindings(self.tcx.def_map, arg.pat) |_bm, arg_id, _x, path| { debug!("adding argument %d", arg_id); - let ident = ast_util::path_to_ident(path); + let ident = *ast_util::path_to_ident(path); (*fn_maps).add_variable(Arg(arg_id, ident, mode)); } }; @@ -513,7 +513,7 @@ fn visit_local(local: @local, &&self: @IrMaps, vt: vt<@IrMaps>) { let def_map = self.tcx.def_map; do pat_util::pat_bindings(def_map, local.node.pat) |_bm, p_id, sp, path| { debug!("adding local variable %d", p_id); - let name = ast_util::path_to_ident(path); + let name = *ast_util::path_to_ident(path); self.add_live_node_for_node(p_id, VarDefNode(sp)); let kind = match local.node.init { Some(_) => FromLetWithInitializer, @@ -535,7 +535,7 @@ fn visit_arm(arm: arm, &&self: @IrMaps, vt: vt<@IrMaps>) { do pat_util::pat_bindings(def_map, *pat) |bm, p_id, sp, path| { debug!("adding local variable %d from match with bm %?", p_id, bm); - let name = ast_util::path_to_ident(path); + let name = *ast_util::path_to_ident(path); self.add_live_node_for_node(p_id, VarDefNode(sp)); self.add_variable(Local(LocalInfo { id: p_id, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 823af16c6054c..f760fac0e7991 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -27,9 +27,9 @@ pub type PatIdMap = HashMap; pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap { let map = HashMap(); do pat_bindings(dm, pat) |_bm, p_id, _s, n| { - map.insert(path_to_ident(n), p_id); + map.insert(*path_to_ident(n), p_id); }; - return map; + map } pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index c647e4db262a6..524ec722d18aa 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1202,7 +1202,7 @@ pub impl Resolver { (None, @Ty { node: ty_path(path, _), _ }) if has_static_methods && path.idents.len() == 1 => { // Create the module. - let name = path_to_ident(path); + let name = *path_to_ident(path); let (name_bindings, new_parent) = self.add_child(name, parent, @@ -1422,7 +1422,7 @@ pub impl Resolver { type_value_ns => AnyNS }; - let source_ident = full_path.idents.last(); + let source_ident = *full_path.idents.last(); let subclass = @SingleImport(binding, source_ident, ns); @@ -4055,7 +4055,7 @@ pub impl Resolver { fn binding_mode_map(pat: @pat) -> BindingMap { let result = HashMap(); do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { - let ident = path_to_ident(path); + let ident = *path_to_ident(path); result.insert(ident, binding_info {span: sp, binding_mode: binding_mode}); @@ -4158,7 +4158,7 @@ pub impl Resolver { // First, check to see whether the name is a primitive type. if path.idents.len() == 1 { - let name = path.idents.last(); + let name = *path.idents.last(); match self.primitive_type_table .primitive_types @@ -4181,7 +4181,7 @@ pub impl Resolver { debug!("(resolving type) resolved `%s` to \ type %?", self.session.str_of( - path.idents.last()), + *path.idents.last()), def); result_def = Some(def); } @@ -4367,7 +4367,7 @@ pub impl Resolver { path.span, fmt!("not an enum variant: %s", self.session.str_of( - path.idents.last()))); + *path.idents.last()))); } None => { self.session.span_err(path.span, @@ -4490,7 +4490,7 @@ pub impl Resolver { namespace); } - return self.resolve_identifier(path.idents.last(), + return self.resolve_identifier(*path.idents.last(), namespace, check_ribs, path.span); @@ -4624,7 +4624,7 @@ pub impl Resolver { } } - let name = path.idents.last(); + let name = *path.idents.last(); match self.resolve_definition_of_name_in_module(containing_module, name, namespace, @@ -4671,7 +4671,7 @@ pub impl Resolver { } } - let name = path.idents.last(); + let name = *path.idents.last(); match self.resolve_definition_of_name_in_module(containing_module, name, namespace, diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 7dca4174019cb..6ca9413b73ad3 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -377,7 +377,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r], vec::view(br.pats, col + 1u, br.pats.len()))); let binding_info = - br.data.bindings_map.get(&path_to_ident(path)); + br.data.bindings_map.get(path_to_ident(path)); Store(bcx, val, binding_info.llmatch); @Match {pats: pats, data: br.data} @@ -425,7 +425,7 @@ pub fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r], if pat_is_binding(dm, self) { let binding_info = br.data.bindings_map.get( - &path_to_ident(path)); + path_to_ident(path)); Store(bcx, val, binding_info.llmatch); } } @@ -1576,7 +1576,7 @@ pub fn trans_match_inner(scope_cx: block, // from the various alternatives. let bindings_map = HashMap(); do pat_bindings(tcx.def_map, arm.pats[0]) |bm, p_id, _s, path| { - let ident = path_to_ident(path); + let ident = *path_to_ident(path); let variable_ty = node_id_type(bcx, p_id); let llvariable_ty = type_of::type_of(bcx.ccx(), variable_ty); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a2b1de692beb0..283fec091db5f 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1402,8 +1402,8 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block { }; let val = alloc_ty(cx, t); if cx.sess().opts.debuginfo { - do option::iter(&simple_name) |name| { - str::as_c_str(cx.ccx().sess.str_of(*name), |buf| { + do simple_name.iter |name| { + str::as_c_str(cx.ccx().sess.str_of(**name), |buf| { unsafe { llvm::LLVMSetValueName(val, buf) } @@ -2160,7 +2160,7 @@ pub fn register_fn_fuller(ccx: @crate_ctxt, ast_map::path_to_str(path, ccx.sess.parse_sess.interner)); let ps = if attr::attrs_contains_name(attrs, "no_mangle") { - path_elt_to_str(path.last(), ccx.sess.parse_sess.interner) + path_elt_to_str(*path.last(), ccx.sess.parse_sess.interner) } else { mangle_exported_name(ccx, /*bad*/copy path, node_type) }; diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 908c567761411..ef8757d9a87a0 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -67,8 +67,8 @@ pub impl FnType { let llretptr = GEPi(bcx, llargbundle, [0u, n]); let llretloc = Load(bcx, llretptr); llargvals = ~[llretloc]; - atys = vec::tail(atys); - attrs = vec::tail(attrs); + atys = vec::from_slice(atys.tail()); + attrs = vec::from_slice(attrs.tail()); } while i < n { @@ -127,8 +127,8 @@ pub impl FnType { let mut attrs = /*bad*/copy self.attrs; let mut j = 0u; let llretptr = if self.sret { - atys = vec::tail(atys); - attrs = vec::tail(attrs); + atys = vec::from_slice(atys.tail()); + attrs = vec::from_slice(attrs.tail()); j = 1u; get_param(llwrapfn, 0u) } else if self.ret_ty.cast { diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ecb63c19811c6..bc985f351eb4d 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -662,7 +662,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) } let name = match local.node.pat.node { - ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth), + ast::pat_ident(_, pth, _) => *ast_util::path_to_ident(pth), // FIXME this should be handled (#2533) _ => die!(~"no single variable name for local") }; @@ -723,7 +723,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) // XXX: This is wrong; it should work for multiple bindings. let mdnode = create_var(tg, context.node, - cx.sess.str_of(path.idents.last()), + cx.sess.str_of(*path.idents.last()), filemd.node, loc.line as int, tymd.node); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 4466e4e1b288c..492232510342b 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -44,7 +44,7 @@ pub fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id, ccx.tcx, fn_id, |a,b,c,d| { astencode::decode_inlined_item(a, b, ccx.maps, - /*bad*/ copy c, d) + /*bad*/vec::from_slice(c), d) }) { csearch::not_found => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 915bb07df8e03..73add8a4a7bff 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3846,7 +3846,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { } ast_map::node_variant(ref variant, _, path) => { - vec::append_one(vec::init(*path), + vec::append_one(vec::from_slice(vec::init(*path)), ast_map::path_name((*variant).node.name)) } diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 1d84cb32c94b5..f22fe25107ff6 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -386,7 +386,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } } - let canon_id = pcx.map.get(&ast_util::path_to_ident(name)); + let canon_id = pcx.map.get(ast_util::path_to_ident(name)); if canon_id != pat.id { let ct = fcx.local_ty(pat.span, canon_id); demand::eqtype(fcx, pat.span, ct, typ); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 9ba23a20b5095..956927134c9b0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -140,18 +140,18 @@ pub fn parse_config_( let args = args.tail(); let opts = vec::unzip(opts()).first(); match getopts::getopts(args, opts) { - result::Ok(matches) => { + Ok(matches) => { if matches.free.len() == 1 { - let input_crate = Path(vec::head(matches.free)); + let input_crate = Path(*matches.free.head()); config_from_opts(&input_crate, &matches, move program_output) } else if matches.free.is_empty() { - result::Err(~"no crates specified") + Err(~"no crates specified") } else { - result::Err(~"multiple crates specified") + Err(~"multiple crates specified") } } - result::Err(f) => { - result::Err(getopts::fail_str(f)) + Err(f) => { + Err(getopts::fail_str(f)) } } } diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 225b62f72cb83..4f2c76602ed14 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -145,7 +145,7 @@ fn parse_desc(desc: ~str) -> Option<~str> { fn first_sentence(s: ~str) -> Option<~str> { let paras = paragraphs(copy s); if !paras.is_empty() { - let first_para = vec::head(paras); + let first_para = /*bad*/copy *paras.head(); Some(str::replace(first_sentence_(first_para), ~"\n", ~" ")) } else { None @@ -183,7 +183,7 @@ fn first_sentence_(s: ~str) -> ~str { } } -fn paragraphs(s: ~str) -> ~[~str] { +fn paragraphs(s: &str) -> ~[~str] { let lines = str::lines_any(s); let mut whitespace_lines = 0; let mut accum = ~""; diff --git a/src/librustdoc/unindent_pass.rs b/src/librustdoc/unindent_pass.rs index 1c53ed5dcce04..c058956833777 100644 --- a/src/librustdoc/unindent_pass.rs +++ b/src/librustdoc/unindent_pass.rs @@ -79,7 +79,7 @@ fn unindent(s: &str) -> ~str { }; if !lines.is_empty() { - let unindented = ~[str::trim(vec::head(lines))] + let unindented = ~[str::trim(*lines.head())] + do par::map(vec::tail(lines)) |line| { if str::is_whitespace(*line) { copy *line diff --git a/src/libstd/bigint.rs b/src/libstd/bigint.rs index 092a0d18a0fe4..dade01fe1c3a8 100644 --- a/src/libstd/bigint.rs +++ b/src/libstd/bigint.rs @@ -343,7 +343,7 @@ pub impl BigUint { } let mut shift = 0; - let mut n = other.data.last(); + let mut n = *other.data.last(); while n < (1 << BigDigit::bits - 2) { n <<= 1; shift += 1; @@ -381,7 +381,7 @@ pub impl BigUint { } let an = vec::view(a.data, a.data.len() - n, a.data.len()); - let bn = b.data.last(); + let bn = *b.data.last(); let mut d = ~[]; let mut carry = 0; for vec::rev_each(an) |elt| { diff --git a/src/libstd/fun_treemap.rs b/src/libstd/fun_treemap.rs index e0d4b95a7e425..eb0fe2c7705d4 100644 --- a/src/libstd/fun_treemap.rs +++ b/src/libstd/fun_treemap.rs @@ -9,6 +9,7 @@ // except according to those terms. #[forbid(deprecated_mode)]; +#[allow(vecs_implicitly_copyable)]; /*! * A functional key,value store that works on anything. diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 4b34f318e91b2..e9cfda31de1ec 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -729,7 +729,7 @@ pub fn Decoder(json: Json) -> Decoder { priv impl Decoder { fn peek(&self) -> &self/Json { if self.stack.len() == 0 { self.stack.push(&self.json); } - vec::last(self.stack) + self.stack[self.stack.len() - 1] } fn pop(&self) -> &self/Json { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 429bd6ae47455..06900ca60c72b 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1560,7 +1560,10 @@ pub mod test { let cont_ch = SharedChan(cont_ch); // server let hl_loop_clone = hl_loop.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1u)) | + copy server_ip, + copy expected_resp + | { let cont_ch = cont_ch.clone(); let actual_req = run_tcp_test_server( server_ip, @@ -1598,10 +1601,13 @@ pub mod test { let cont_ch = SharedChan(cont_ch); // server let hl_loop_clone = hl_loop.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1u)) | + copy server_ip, + copy expected_resp + | { let cont_ch = cont_ch.clone(); run_tcp_test_server( - server_ip, + /*bad*/copy server_ip, server_port, expected_resp, cont_ch.clone(), @@ -1658,7 +1664,10 @@ pub mod test { let cont_ch = SharedChan(cont_ch); // server let hl_loop_clone = hl_loop.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1u)) | + copy server_ip, + copy expected_resp + | { let cont_ch = cont_ch.clone(); run_tcp_test_server( server_ip, @@ -1723,7 +1732,10 @@ pub mod test { let cont_ch = SharedChan(cont_ch); // server let iotask_clone = iotask.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1u)) | + copy server_ip, + copy expected_resp + | { let cont_ch = cont_ch.clone(); let actual_req = run_tcp_test_server( server_ip, @@ -1770,7 +1782,10 @@ pub mod test { let cont_ch = SharedChan(cont_ch); // server let hl_loop_clone = hl_loop.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1u)) | + copy server_ip, + copy expected_resp + | { let cont_ch = cont_ch.clone(); run_tcp_test_server( server_ip, diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index fcd9f8379b2f4..df1c867e235dd 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -186,7 +186,7 @@ mod tests { let mut sorted = merge_sort(data, le); let mut heap = from_vec(data); while !heap.is_empty() { - assert *heap.top() == sorted.last(); + assert heap.top() == sorted.last(); assert heap.pop() == sorted.pop(); } } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 1105d65a4ed6f..6259099433bdf 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -13,6 +13,7 @@ //! `Ord`, and that the `lt` method provides a total ordering. #[forbid(deprecated_mode)]; +#[allow(vecs_implicitly_copyable)]; use core::container::{Container, Mutable, Map, Set}; use core::cmp::{Eq, Ord}; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 95deec08feb5e..42086b7038abd 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -176,7 +176,7 @@ impl Database { let db_cache = copy self.db_cache; match db_cache.find(&k) { None => None, - Some(&v) => Some(json_decode(copy v)) + Some(ref v) => Some(json_decode(**v)) } } @@ -187,7 +187,7 @@ impl Database { let k = json_encode(&(fn_name, declared_inputs)); match self.db_cache.find(&k) { None => None, - Some(&v) => Some(json_decode(copy v)) + Some(ref v) => Some(json_decode(**v)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c659d6d602048..634c5a3e813b4 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -31,7 +31,7 @@ pub pure fn path_name_i(idents: &[ident], intr: @token::ident_interner) } -pub pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) } +pub pure fn path_to_ident(p: &r/path) -> &r/ident { p.idents.last() } pub pure fn local_def(id: node_id) -> def_id { ast::def_id { crate: local_crate, node: id } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index ca28641c4a3bc..dcd6d532612fd 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -213,7 +213,7 @@ pub fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool { !find_attrs_by_name(attrs, name).is_empty() } -pub fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: ~str) +pub fn first_attr_value_str_by_name(attrs: &[ast::attribute], name: ~str) -> Option<~str> { let mattrs = find_attrs_by_name(attrs, name); @@ -223,14 +223,14 @@ pub fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: ~str) return option::None; } -fn last_meta_item_by_name(items: ~[@ast::meta_item], name: ~str) +fn last_meta_item_by_name(items: &[@ast::meta_item], name: ~str) -> Option<@ast::meta_item> { let items = attr::find_meta_items_by_name(items, name); - vec::last_opt(items) + items.last_opt().map(|item| **item) } -pub fn last_meta_item_value_str_by_name(items: ~[@ast::meta_item], name: ~str) +pub fn last_meta_item_value_str_by_name(items: &[@ast::meta_item], name: ~str) -> Option<~str> { match last_meta_item_by_name(items, name) { @@ -242,7 +242,7 @@ pub fn last_meta_item_value_str_by_name(items: ~[@ast::meta_item], name: ~str) } } -pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: ~str) +pub fn last_meta_item_list_by_name(items: &[@ast::meta_item], name: ~str) -> Option<~[@ast::meta_item]> { match last_meta_item_by_name(items, name) { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 6f57ca38f1f1a..01af8f01db548 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -155,7 +155,7 @@ pub fn tt_next_token(&&r: tt_reader) -> TokenAndSpan { while r.cur.idx >= r.cur.readme.len() { /* done with this set; pop or repeat? */ if ! r.cur.dotdotdoted - || r.repeat_idx.last() == r.repeat_len.last() - 1 { + || { *r.repeat_idx.last() == *r.repeat_len.last() - 1 } { match r.cur.up { tt_frame_up(None) => { diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 20dcb079597e5..e958acbfe77d3 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -94,7 +94,7 @@ fn recurse_or_fail(depth: int, st: Option) { { ~Cons((), @*fn_unique()) }, tuple: (@Cons((), st.tuple.first()), ~Cons((), @*st.tuple.second())), - vec: st.vec + ~[@Cons((), st.vec.last())], + vec: st.vec + ~[@Cons((), *st.vec.last())], res: r(@Cons((), st.res._l)) } } diff --git a/src/test/run-pass/zip-same-length.rs b/src/test/run-pass/zip-same-length.rs index 167448cfe25b1..fdb6989b7bb37 100644 --- a/src/test/run-pass/zip-same-length.rs +++ b/src/test/run-pass/zip-same-length.rs @@ -10,7 +10,6 @@ // In this case, the code should compile and should // succeed at runtime -use vec::{head, last, same_length, zip}; fn enum_chars(start: u8, end: u8) -> ~[char] { assert start < end; @@ -33,8 +32,8 @@ pub fn main() { let chars = enum_chars(a, j); let ints = enum_uints(k, l); - let ps = zip(chars, ints); + let ps = vec::zip(chars, ints); - assert (head(ps) == ('a', 1u)); - assert (last(ps) == (j as char, 10u)); + assert (ps.head() == &('a', 1u)); + assert (ps.last() == &(j as char, 10u)); }