diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ab5f04ace79c..1be0daf21ba9 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -211,40 +211,41 @@ pub pure fn build_sized_opt(size: Option, // 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] { - slice(v, 1u, len(v)).to_vec() +pub pure fn head(v: &r/[T]) -> &r/T { + if v.len() == 0 { fail!(~"head: 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)).to_vec() +/// 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] { slice(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] { slice(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).to_vec() +pub pure fn init(v: &r/[T]) -> &r/[T] { slice(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] { + slice(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 { fail!(~"last_unsafe: empty vector") } - v[len(v) - 1u] +pub pure fn last(v: &r/[T]) -> &r/T { + if v.len() == 0 { fail!(~"last: 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]) } } /// Return a slice that points into another slice. @@ -1692,41 +1693,29 @@ impl Container for &[const T] { } 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 CopyableVector for &[const T] { - /// 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) } - +impl CopyableVector for &[const T] { /// 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).to_vec() } - - /// 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 foldr(&self, z: U, p: fn(t: &T, u: U) -> U) -> U; + 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]; fn map_r(&self, f: fn(x: &T) -> U) -> ~[U]; @@ -1743,6 +1732,38 @@ impl ImmutableVector for &[T] { slice(*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 { @@ -2570,27 +2591,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] @@ -3262,12 +3373,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 } @@ -3332,13 +3437,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/librust/rust.rc b/src/librust/rust.rc index 37e0f874b40d..235ed6412a35 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -130,7 +130,7 @@ fn cmd_help(args: &[~str]) -> ValidUsage { UsgExec(commandline) => { let words = str::words(commandline); let (prog, args) = (words.head(), words.tail()); - run::run_program(prog, args); + run::run_program(*prog, args); } } Valid @@ -186,7 +186,10 @@ fn do_command(command: &Command, args: &[~str]) -> ValidUsage { Exec(commandline) => { let words = str::words(commandline); let (prog, prog_args) = (words.head(), words.tail()); - let exitstatus = run::run_program(prog, prog_args + args); + let exitstatus = run::run_program( + *prog, + vec::append(vec::from_slice(prog_args), args) + ); os::set_exit_status(exitstatus); Valid } @@ -221,11 +224,12 @@ fn usage() { } pub fn main() { - let args = os::args().tail(); + let os_args = os::args(); + let args = os_args.tail(); if !args.is_empty() { for commands.each |command| { - if command.cmd == args.head() { + if command.cmd == *args.head() { let result = do_command(command, args.tail()); if result.is_valid() { return; } } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index c7c81d0b1c06..ff26000af974 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -65,7 +65,7 @@ struct cache_entry { metas: @~[@ast::meta_item] } -fn dump_crates(+crate_cache: @mut ~[cache_entry]) { +fn dump_crates(crate_cache: @mut ~[cache_entry]) { debug!("resolved crates:"); for crate_cache.each |entry| { debug!("cnum: %?", entry.cnum); @@ -81,7 +81,9 @@ fn warn_if_multiple_versions(e: @mut Env, if crate_cache.len() != 0u { let name = loader::crate_name_from_metas( - /*bad*/copy *crate_cache.last().metas); + *crate_cache[crate_cache.len() - 1].metas + ); + let (matches, non_matches) = partition(crate_cache.map_to_vec(|&entry| { let othername = loader::crate_name_from_metas( diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index aa18c1eb450b..0bf1fc387044 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -558,7 +558,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 => { @@ -566,8 +569,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/loader.rs b/src/librustc/metadata/loader.rs index da7f3635c0e2..d45cefdbf081 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -84,11 +84,12 @@ fn libname(cx: Context) -> (~str, ~str) { (str::from_slice(dll_prefix), str::from_slice(dll_suffix)) } -fn find_library_crate_aux(cx: Context, - (prefix, suffix): (~str, ~str), - filesearch: filesearch::FileSearch) -> - Option<(~str, @~[u8])> { - let crate_name = crate_name_from_metas(/*bad*/copy cx.metas); +fn find_library_crate_aux( + cx: Context, + (prefix, suffix): (~str, ~str), + filesearch: filesearch::FileSearch +) -> Option<(~str, @~[u8])> { + let crate_name = crate_name_from_metas(cx.metas); let prefix: ~str = prefix + *crate_name + ~"-"; let suffix: ~str = /*bad*/copy suffix; @@ -96,7 +97,7 @@ fn find_library_crate_aux(cx: Context, filesearch::search(filesearch, |path| { debug!("inspecting file %s", path.to_str()); let f: ~str = path.filename().get(); - if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) { + if !(f.starts_with(prefix) && f.ends_with(suffix)) { debug!("skipping %s, doesn't look like %s*%s", path.to_str(), prefix, suffix); option::None::<()> @@ -140,11 +141,11 @@ fn find_library_crate_aux(cx: Context, } } -pub fn crate_name_from_metas(+metas: &[@ast::meta_item]) -> @~str { +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) { + match name_items.last_opt() { Some(i) => { - match attr::get_meta_item_value_str(i) { + match attr::get_meta_item_value_str(*i) { Some(n) => 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 016daf3ac9f5..cf88a0eb9024 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -105,7 +105,7 @@ pub fn encode_inlined_item(ecx: @e::EncodeContext, 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 = @DecodeContext { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 51cb305ab028..f9f655d50218 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -71,7 +71,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 => { // This is good, wildcard pattern isn't reachable return; @@ -165,7 +165,7 @@ pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) { ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { match *ctor { vec(n) => Some(@fmt!("vectors of length %u", n)), - _ => None + _ => None } } _ => None @@ -205,10 +205,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) } @@ -264,8 +264,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, r)), - vec::tail(v)) { + &m.filter_mapped(|r| default(cx, *r)), + v.tail()) { useful_ => useful(left_ty, (/*bad*/copy *ctor)), ref u => (/*bad*/copy *u) } @@ -280,15 +280,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 = m.filter_mapped(|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) @@ -347,7 +347,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 { @@ -475,7 +475,7 @@ pub fn wild() -> @pat { } pub fn specialize(cx: @MatchCheckCtxt, - +r: &[@pat], + r: &[@pat], ctor_id: ctor, arity: uint, left_ty: ty::t) @@ -485,13 +485,17 @@ pub fn specialize(cx: @MatchCheckCtxt, match r0 { pat{id: pat_id, node: n, span: pat_span} => match n { - pat_wild => Some(vec::append(vec::from_elem(arity, wild()), - vec::tail(r))), + pat_wild => { + Some(vec::append(vec::from_elem(arity, wild()), 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 = @@ -506,10 +510,20 @@ pub fn specialize(cx: @MatchCheckCtxt, single => true, _ => fail!(~"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()), + r.tail() + ) + ) } - _ => Some(vec::append(vec::from_elem(arity, wild()), - vec::tail(r))) } } pat_enum(_, args) => { @@ -519,7 +533,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(*) => { @@ -529,7 +543,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 } @@ -545,7 +559,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? @@ -560,7 +574,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 } @@ -587,13 +601,14 @@ 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_box(a) | pat_uniq(a) | pat_region(a) => - Some(vec::append(~[a], vec::tail(r))), + pat_tup(args) => Some(vec::append(args, r.tail())), + pat_box(a) | pat_uniq(a) | pat_region(a) => { + Some(vec::append(~[a], r.tail())) + } pat_lit(expr) => { let e_v = eval_const_expr(cx.tcx, expr); let match_ = match ctor_id { @@ -605,21 +620,21 @@ pub fn specialize(cx: @MatchCheckCtxt, single => true, _ => fail!(~"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())), _ => fail!(~"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 { @@ -630,10 +645,10 @@ 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, r.tail())) } else { None } @@ -645,8 +660,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/pat_util.rs b/src/librustc/middle/pat_util.rs index df9b9aa13746..77ad7df53197 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -26,7 +26,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap { do pat_bindings(dm, pat) |_bm, p_id, _s, n| { 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 004d5ee14ad5..49898885a660 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1438,7 +1438,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); @@ -4087,7 +4087,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 @@ -4110,7 +4110,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); } @@ -4296,7 +4296,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, @@ -4418,7 +4418,7 @@ pub impl Resolver { namespace); } - return self.resolve_identifier(path.idents.last(), + return self.resolve_identifier(*path.idents.last(), namespace, check_ribs, path.span); @@ -4552,7 +4552,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, @@ -4601,7 +4601,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/base.rs b/src/librustc/middle/trans/base.rs index 76c62919dfa0..1926b2f2e5df 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2207,7 +2207,7 @@ pub fn register_fn_fuller(ccx: @CrateContext, 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 bbc19cf86eaa..1d7314f75187 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -71,8 +71,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 { @@ -131,8 +131,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 da8e27ba4fff..61d0594d2274 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -792,12 +792,14 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) match arg.pat.node { ast::pat_ident(_, path, _) => { // XXX: This is wrong; it should work for multiple bindings. - let mdnode = create_var(tg, - context.node, - *cx.sess.str_of(path.idents.last()), - filemd.node, - loc.line as int, - tymd.node); + let mdnode = create_var( + tg, + context.node, + *cx.sess.str_of(*path.idents.last()), + filemd.node, + loc.line as int, + tymd.node + ); let mdval = @Metadata { node: mdnode, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 644b2c514544..12a2011ad256 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3815,7 +3815,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/librustdoc/config.rs b/src/librustdoc/config.rs index 21c0393f68f6..83ef5a6f3a85 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -130,18 +130,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, 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)) } } } @@ -262,7 +262,7 @@ fn should_find_pandoc() { output_format: PandocHtml, .. default_config(&Path("test")) }; - let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |prog, _| { + let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| { ProgramOutput { status: 0, out: ~"pandoc 1.8.2.1", err: ~"" } }; let result = maybe_find_pandoc(&config, None, mock_program_output); diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index b4d990ccdd24..3a4cd9e1379f 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -142,16 +142,16 @@ fn parse_desc(desc: ~str) -> Option<~str> { } fn first_sentence(s: ~str) -> Option<~str> { - let paras = paragraphs(copy s); + let paras = paragraphs(s); if !paras.is_empty() { - let first_para = vec::head(paras); - Some(str::replace(first_sentence_(first_para), ~"\n", ~" ")) + let first_para = paras.head(); + Some(str::replace(first_sentence_(*first_para), ~"\n", ~" ")) } else { None } } -fn first_sentence_(s: ~str) -> ~str { +fn first_sentence_(s: &str) -> ~str { let mut dotcount = 0; // The index of the character following a single dot. This allows // Things like [0..1) to appear in the brief description @@ -169,20 +169,20 @@ fn first_sentence_(s: ~str) -> ~str { } }; match idx { - Some(idx) if idx > 2u => { - str::slice(s, 0u, idx - 1u) - } - _ => { - if str::ends_with(s, ~".") { - str::slice(s, 0u, str::len(s)) - } else { - copy s + Some(idx) if idx > 2u => { + str::from_slice(str::view(s, 0, idx - 1)) + } + _ => { + if str::ends_with(s, ~".") { + str::from_slice(s) + } else { + str::from_slice(s) + } } - } } } -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 d5b9756faa5e..06595a23d961 100644 --- a/src/librustdoc/unindent_pass.rs +++ b/src/librustdoc/unindent_pass.rs @@ -78,8 +78,8 @@ fn unindent(s: &str) -> ~str { }; if !lines.is_empty() { - let unindented = ~[str::trim(vec::head(lines))] - + do vec::tail(lines).map |line| { + let unindented = ~[lines.head().trim()] + + do lines.tail().map |line| { if str::is_whitespace(*line) { copy *line } else { diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 57d456f1bbf0..d7428ae15e7e 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -57,7 +57,7 @@ pub fn parse_name(id: ~str) -> result::Result<~str, ~str> { } } - result::Ok(parts.last()) + result::Ok(copy *parts.last()) } struct ListenerFn { @@ -516,9 +516,11 @@ pub fn get_pkg(id: ~str, return result::Err(~"package not found"); } - result::Ok(sort::merge_sort(possibs, |v1, v2| { + let possibs = sort::merge_sort(possibs, |v1, v2| { v1.vers <= v2.vers - }).last()) + }); + + result::Ok(copy *possibs.last()) } pub fn add_pkg(pkg: &Package) -> bool { diff --git a/src/libstd/bigint.rs b/src/libstd/bigint.rs index 5a0928e6a118..e8836c586628 100644 --- a/src/libstd/bigint.rs +++ b/src/libstd/bigint.rs @@ -346,7 +346,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; @@ -384,7 +384,7 @@ pub impl BigUint { } let an = vec::slice(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/json.rs b/src/libstd/json.rs index d1a65517aad0..7993f15f622c 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -759,7 +759,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/priority_queue.rs b/src/libstd/priority_queue.rs index 4b92bd7543a7..2a2c655cca9e 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -197,7 +197,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/workcache.rs b/src/libstd/workcache.rs index 1dd7bfd75db8..c46c2d17ed0c 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -174,7 +174,7 @@ pub 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(v) => Some(json_decode(*v)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 680101e673c9..ba683004aeec 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: @path) -> ident { copy *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 7739a862432e..fb7143f7c143 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -229,7 +229,7 @@ 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) diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 79264f7adf03..116ecc37d2e1 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -167,7 +167,7 @@ pub fn tt_next_token(r: @mut TtReader) -> 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 { None => { diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 05781b20a9b3..4a372d016f9c 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -93,7 +93,7 @@ fn recurse_or_fail(depth: int, st: Option) { fn_box: || @Cons((), fn_box()), 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 1ade9e8246fd..fdb6989b7bb3 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 core::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)); }