From 0169218047dc989acf9ea25e3122b9c659acb6b3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Sep 2014 12:56:31 -0700 Subject: [PATCH] Fix fallout from Vec stabilization --- src/compiletest/runtest.rs | 59 ++++++++++--------- src/doc/rust.md | 5 +- src/libcollections/bitv.rs | 4 +- src/libcollections/slice.rs | 10 +++- src/libcollections/str.rs | 3 +- src/libcollections/string.rs | 5 +- src/libcollections/vec.rs | 49 ++++----------- src/libgraphviz/maybe_owned_vec.rs | 2 +- src/librbml/io.rs | 2 +- src/libregex/compile.rs | 2 +- src/libregex/parse.rs | 10 ++-- src/libregex_macros/lib.rs | 2 +- src/librustdoc/clean/mod.rs | 8 +-- src/librustdoc/flock.rs | 4 +- src/librustdoc/html/render.rs | 5 +- src/librustrt/args.rs | 3 +- src/librustuv/net.rs | 2 +- src/librustuv/stream.rs | 2 +- src/libstd/dynamic_lib.rs | 5 +- src/libstd/io/comm_adapters.rs | 4 +- src/libstd/io/fs.rs | 4 +- src/libstd/os.rs | 50 ++++++++-------- src/libstd/path/mod.rs | 6 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 12 ++-- src/libterm/terminfo/parm.rs | 16 ++--- src/libterm/terminfo/parser/compiled.rs | 13 ++-- src/libtest/stats.rs | 6 +- .../borrowck-for-loop-head-linkage.rs | 2 +- 29 files changed, 141 insertions(+), 156 deletions(-) diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index d64d3317e2e..f3e9177fc6e 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -273,8 +273,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) { format!("--target={}", config.target), "-L".to_string(), aux_dir.as_str().unwrap().to_string()); - args.push_all_move(split_maybe_args(&config.target_rustcflags)); - args.push_all_move(split_maybe_args(&props.compile_flags)); + args.extend(split_maybe_args(&config.target_rustcflags).into_iter()); + args.extend(split_maybe_args(&props.compile_flags).into_iter()); return ProcArgs { prog: config.rustc_path.as_str().unwrap().to_string(), args: args, @@ -321,8 +321,8 @@ actual:\n\ config.build_base.as_str().unwrap().to_string(), "-L".to_string(), aux_dir.as_str().unwrap().to_string()); - args.push_all_move(split_maybe_args(&config.target_rustcflags)); - args.push_all_move(split_maybe_args(&props.compile_flags)); + args.extend(split_maybe_args(&config.target_rustcflags).into_iter()); + args.extend(split_maybe_args(&props.compile_flags).into_iter()); // FIXME (#9639): This needs to handle non-utf8 paths return ProcArgs { prog: config.rustc_path.as_str().unwrap().to_string(), @@ -1095,11 +1095,12 @@ fn compile_test_(config: &Config, props: &TestProps, testfile: &Path, extra_args: &[String]) -> ProcRes { let aux_dir = aux_output_dir_name(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths - let link_args = vec!("-L".to_string(), - aux_dir.as_str().unwrap().to_string()); + let mut link_args = vec!("-L".to_string(), + aux_dir.as_str().unwrap().to_string()); + link_args.extend(extra_args.iter().map(|s| s.clone())); let args = make_compile_args(config, props, - link_args.append(extra_args), + link_args, |a, b| ThisFile(make_exe_name(a, b)), testfile); compose_and_run_compiler(config, props, testfile, args, None) } @@ -1146,16 +1147,16 @@ fn compose_and_run_compiler( for rel_ab in props.aux_builds.iter() { let abs_ab = config.aux_base.join(rel_ab.as_slice()); let aux_props = header::load_props(&abs_ab); - let crate_type = if aux_props.no_prefer_dynamic { + let mut crate_type = if aux_props.no_prefer_dynamic { Vec::new() } else { vec!("--crate-type=dylib".to_string()) }; + crate_type.extend(extra_link_args.clone().into_iter()); let aux_args = make_compile_args(config, &aux_props, - crate_type.append( - extra_link_args.as_slice()), + crate_type, |a,b| { let f = make_lib_name(a, b, testfile); ThisDirectory(f.dir_path()) @@ -1246,11 +1247,11 @@ fn make_compile_args(config: &Config, }; args.push(path.as_str().unwrap().to_string()); if props.force_host { - args.push_all_move(split_maybe_args(&config.host_rustcflags)); + args.extend(split_maybe_args(&config.host_rustcflags).into_iter()); } else { - args.push_all_move(split_maybe_args(&config.target_rustcflags)); + args.extend(split_maybe_args(&config.target_rustcflags).into_iter()); } - args.push_all_move(split_maybe_args(&props.compile_flags)); + args.extend(split_maybe_args(&props.compile_flags).into_iter()); return ProcArgs { prog: config.rustc_path.as_str().unwrap().to_string(), args: args, @@ -1267,10 +1268,9 @@ fn make_lib_name(config: &Config, auxfile: &Path, testfile: &Path) -> Path { fn make_exe_name(config: &Config, testfile: &Path) -> Path { let mut f = output_base_name(config, testfile); if !os::consts::EXE_SUFFIX.is_empty() { - match f.filename().map(|s| Vec::from_slice(s).append(os::consts::EXE_SUFFIX.as_bytes())) { - Some(v) => f.set_filename(v), - None => () - } + let mut fname = f.filename().unwrap().to_vec(); + fname.extend(os::consts::EXE_SUFFIX.bytes()); + f.set_filename(fname); } f } @@ -1286,7 +1286,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) -> args.push(exe_file.as_str().unwrap().to_string()); // Add the arguments in the run_flags directive - args.push_all_move(split_maybe_args(&props.run_flags)); + args.extend(split_maybe_args(&props.run_flags).into_iter()); let prog = args.remove(0).unwrap(); return ProcArgs { @@ -1381,12 +1381,10 @@ fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path { } fn aux_output_dir_name(config: &Config, testfile: &Path) -> Path { - let mut f = output_base_name(config, testfile); - match f.filename().map(|s| Vec::from_slice(s).append(b".libaux")) { - Some(v) => f.set_filename(v), - None => () - } - f + let f = output_base_name(config, testfile); + let mut fname = f.filename().unwrap().to_vec(); + fname.extend("libaux".bytes()); + f.with_filename(fname) } fn output_testname(testfile: &Path) -> Path { @@ -1598,8 +1596,10 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path { if suffix.len() == 0 { (*p).clone() } else { - let stem = p.filestem().unwrap(); - p.with_filename(Vec::from_slice(stem).append(b"-").append(suffix.as_bytes())) + let mut stem = p.filestem().unwrap().to_vec(); + stem.extend("-".bytes()); + stem.extend(suffix.bytes()); + p.with_filename(stem) } } @@ -1607,13 +1607,14 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps, testfile: &Path) -> ProcRes { let aux_dir = aux_output_dir_name(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths - let link_args = vec!("-L".to_string(), - aux_dir.as_str().unwrap().to_string()); + let mut link_args = vec!("-L".to_string(), + aux_dir.as_str().unwrap().to_string()); let llvm_args = vec!("--emit=bc,obj".to_string(), "--crate-type=lib".to_string()); + link_args.extend(llvm_args.into_iter()); let args = make_compile_args(config, props, - link_args.append(llvm_args.as_slice()), + link_args, |a, b| ThisDirectory(output_base_name(a, b).dir_path()), testfile); compose_and_run_compiler(config, props, testfile, args, None) diff --git a/src/doc/rust.md b/src/doc/rust.md index 5028f224475..2ffe22cba75 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -3833,8 +3833,9 @@ fn map(f: |A| -> B, xs: &[A]) -> Vec { return vec![]; } let first: B = f(xs[0].clone()); - let rest: Vec = map(f, xs.slice(1, xs.len())); - return vec![first].append(rest.as_slice()); + let mut rest: Vec = map(f, xs.slice(1, xs.len())); + rest.insert(0, first); + return rest; } ~~~~ diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 11affb9dfd5..60c9dfcff18 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -631,7 +631,7 @@ impl Bitv { let old_size = self.storage.len(); let size = (size + uint::BITS - 1) / uint::BITS; if old_size < size { - self.storage.grow(size - old_size, &0); + self.storage.grow(size - old_size, 0); } } @@ -687,7 +687,7 @@ impl Bitv { // Allocate new words, if needed if new_nwords > self.storage.len() { let to_add = new_nwords - self.storage.len(); - self.storage.grow(to_add, &full_value); + self.storage.grow(to_add, full_value); } // Adjust internal bit count self.nbits = new_nbits; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index f93b5c89127..44fe962fad4 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -283,7 +283,11 @@ pub trait CloneableVector { impl<'a, T: Clone> CloneableVector for &'a [T] { /// Returns a copy of `v`. #[inline] - fn to_vec(&self) -> Vec { Vec::from_slice(*self) } + fn to_vec(&self) -> Vec { + let mut vector = Vec::with_capacity(self.len()); + vector.push_all(*self); + vector + } #[inline(always)] fn into_vec(self) -> Vec { self.to_vec() } @@ -1039,7 +1043,7 @@ mod tests { fn test_grow() { // Test on-stack grow(). let mut v = vec![]; - v.grow(2u, &1i); + v.grow(2u, 1i); { let v = v.as_slice(); assert_eq!(v.len(), 2u); @@ -1048,7 +1052,7 @@ mod tests { } // Test on-heap grow(). - v.grow(3u, &2i); + v.grow(3u, 2i); { let v = v.as_slice(); assert_eq!(v.len(), 5u); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 88c683ef44e..f677b170bb3 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -67,6 +67,7 @@ use core::prelude::{range}; use {Deque, MutableSeq}; use hash; use ringbuf::RingBuf; +use slice::CloneableVector; use string::String; use unicode; use vec::Vec; @@ -754,7 +755,7 @@ pub trait StrAllocating: Str { #[inline] fn to_owned(&self) -> String { unsafe { - mem::transmute(Vec::from_slice(self.as_slice().as_bytes())) + mem::transmute(self.as_slice().as_bytes().to_vec()) } } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index a12d403603f..bb66d271ee4 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -23,6 +23,7 @@ use core::raw::Slice as RawSlice; use {Mutable, MutableSeq}; use hash; +use slice::CloneableVector; use str; use str::{CharRange, StrAllocating, MaybeOwned, Owned}; use str::Slice as MaybeOwnedSlice; // So many `Slice`s... @@ -75,9 +76,7 @@ impl String { /// ``` #[inline] pub fn from_str(string: &str) -> String { - String { - vec: Vec::from_slice(string.as_bytes()) - } + String { vec: string.as_bytes().to_vec() } } /// Deprecated. Replaced by `string::raw::from_parts` diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index dc43dd5e53d..d5ca48e605a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -273,16 +273,7 @@ impl Vec { } impl Vec { - /// Iterates over the `second` vector, copying each element and appending it to - /// the `first`. Afterwards, the `first` is then returned for use again. - /// - /// # Example - /// - /// ``` - /// let vec = vec![1i, 2i]; - /// let vec = vec.append([3i, 4i]); - /// assert_eq!(vec, vec![1, 2, 3, 4]); - /// ``` + /// Deprecated, call `extend` instead. #[inline] #[deprecated = "this function has been deprecated in favor of extend()"] pub fn append(mut self, second: &[T]) -> Vec { @@ -290,21 +281,10 @@ impl Vec { self } - /// Constructs a `Vec` by cloning elements of a slice. - /// - /// # Example - /// - /// ``` - /// let slice = [1i, 2, 3]; - /// let vec = Vec::from_slice(slice); - /// ``` + /// Deprecated, call `to_vec()` instead #[inline] #[deprecated = "this function has been deprecated in favor of to_vec()"] - pub fn from_slice(values: &[T]) -> Vec { - let mut vector = Vec::new(); - vector.push_all(values); - vector - } + pub fn from_slice(values: &[T]) -> Vec { values.to_vec() } /// Constructs a `Vec` with copies of a value. /// @@ -442,9 +422,7 @@ impl Vec { #[unstable] impl Clone for Vec { - fn clone(&self) -> Vec { - Vec::from_slice(self.as_slice()) - } + fn clone(&self) -> Vec { self.as_slice().to_vec() } fn clone_from(&mut self, other: &Vec) { // drop anything in self that will not be overwritten @@ -736,16 +714,7 @@ impl Vec { } } - /// Appends one element to the vector provided. The vector itself is then - /// returned for use again. - /// - /// # Example - /// - /// ``` - /// let vec = vec![1i, 2]; - /// let vec = vec.append_one(3); - /// assert_eq!(vec, vec![1, 2, 3]); - /// ``` + /// Deprecated, call `push` instead #[inline] #[deprecated = "call .push() instead"] pub fn append_one(mut self, x: T) -> Vec { @@ -765,7 +734,7 @@ impl Vec { /// vec.truncate(2); /// assert_eq!(vec, vec![1, 2]); /// ``` - #[stable] + #[unstable = "waiting on failure semantics"] pub fn truncate(&mut self, len: uint) { unsafe { // drop any extra elements @@ -1123,7 +1092,7 @@ impl Vec { /// vec.insert(4, 5); /// assert_eq!(vec, vec![1, 4, 2, 3, 5]); /// ``` - #[stable] + #[unstable = "failure semantics need settling"] pub fn insert(&mut self, index: uint, element: T) { let len = self.len(); assert!(index <= len); @@ -1160,7 +1129,7 @@ impl Vec { /// // v is unchanged: /// assert_eq!(v, vec![1, 3]); /// ``` - #[stable] + #[unstable = "failure semantics need settling"] pub fn remove(&mut self, index: uint) -> Option { let len = self.len(); if index < len { @@ -1192,11 +1161,13 @@ impl Vec { /// # Example /// /// ``` + /// # #![allow(deprecated)] /// let mut vec = vec![box 1i]; /// vec.push_all_move(vec![box 2, box 3, box 4]); /// assert_eq!(vec, vec![box 1, box 2, box 3, box 4]); /// ``` #[inline] + #[deprecated = "use .extend(other.into_iter())"] pub fn push_all_move(&mut self, other: Vec) { self.extend(other.into_iter()); } diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index ab06f327592..94e89dc6043 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -170,7 +170,7 @@ impl<'a,T:Clone> MaybeOwnedVector<'a,T> { pub fn into_vec(self) -> Vec { match self { Growable(v) => v, - Borrowed(v) => Vec::from_slice(v), + Borrowed(v) => v.to_vec(), } } } diff --git a/src/librbml/io.rs b/src/librbml/io.rs index 51115990a31..648aa866814 100644 --- a/src/librbml/io.rs +++ b/src/librbml/io.rs @@ -87,7 +87,7 @@ impl Writer for SeekableMemWriter { // currently are let difference = self.pos as i64 - self.buf.len() as i64; if difference > 0 { - self.buf.grow(difference as uint, &0); + self.buf.grow(difference as uint, 0); } // Figure out what bytes will be used to overwrite what's currently diff --git a/src/libregex/compile.rs b/src/libregex/compile.rs index c4b517c5259..91c3da00162 100644 --- a/src/libregex/compile.rs +++ b/src/libregex/compile.rs @@ -156,7 +156,7 @@ impl<'r> Compiler<'r> { Capture(cap, name, x) => { let len = self.names.len(); if cap >= len { - self.names.grow(10 + cap - len, &None) + self.names.grow(10 + cap - len, None) } *self.names.get_mut(cap) = name; diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index ad60829c088..7f4289b128a 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -986,9 +986,9 @@ fn combine_ranges(unordered: Vec<(char, char)>) -> Vec<(char, char)> { // (or any of their negated forms). Note that this does not handle negation. fn perl_unicode_class(which: char) -> Vec<(char, char)> { match which.to_lowercase() { - 'd' => Vec::from_slice(PERLD), - 's' => Vec::from_slice(PERLS), - 'w' => Vec::from_slice(PERLW), + 'd' => PERLD.to_vec(), + 's' => PERLS.to_vec(), + 'w' => PERLW.to_vec(), _ => unreachable!(), } } @@ -997,7 +997,7 @@ fn perl_unicode_class(which: char) -> Vec<(char, char)> { // `Cat` expression will never be a direct child of another `Cat` expression. fn concat_flatten(x: Ast, y: Ast) -> Ast { match (x, y) { - (Cat(mut xs), Cat(ys)) => { xs.push_all_move(ys); Cat(xs) } + (Cat(mut xs), Cat(ys)) => { xs.extend(ys.into_iter()); Cat(xs) } (Cat(mut xs), ast) => { xs.push(ast); Cat(xs) } (ast, Cat(mut xs)) => { xs.insert(0, ast); Cat(xs) } (ast1, ast2) => Cat(vec!(ast1, ast2)), @@ -1019,7 +1019,7 @@ fn is_valid_cap(c: char) -> bool { fn find_class(classes: NamedClasses, name: &str) -> Option> { match classes.binary_search(|&(s, _)| s.cmp(&name)) { - slice::Found(i) => Some(Vec::from_slice(classes[i].val1())), + slice::Found(i) => Some(classes[i].val1().to_vec()), slice::NotFound(_) => None, } } diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index ae6dd2a4d70..cc6a8e27cda 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -133,7 +133,7 @@ impl<'a> NfaGen<'a> { let init_groups = self.vec_expr(range(0, num_cap_locs), |cx, _| cx.expr_none(self.sp)); - let prefix_lit = Rc::new(Vec::from_slice(self.prog.prefix.as_slice().as_bytes())); + let prefix_lit = Rc::new(self.prog.prefix.as_slice().as_bytes().to_vec()); let prefix_bytes = self.cx.expr_lit(self.sp, ast::LitBinary(prefix_lit)); let check_prefix = self.check_prefix(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b4d44aab239..660b6c7ade2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -505,7 +505,7 @@ fn external_path(cx: &DocContext, name: &str, substs: &subst::Substs) -> Path { .iter() .filter_map(|v| v.clean(cx)) .collect(); - let types = Vec::from_slice(substs.types.get_slice(subst::TypeSpace)); + let types = substs.types.get_slice(subst::TypeSpace).to_vec(); let types = types.clean(cx); Path { global: false, @@ -661,8 +661,8 @@ impl<'a> Clean for (&'a ty::Generics, subst::ParamSpace) { fn clean(&self, cx: &DocContext) -> Generics { let (me, space) = *self; Generics { - type_params: Vec::from_slice(me.types.get_slice(space)).clean(cx), - lifetimes: Vec::from_slice(me.regions.get_slice(space)).clean(cx), + type_params: me.types.get_slice(space).to_vec().clean(cx), + lifetimes: me.regions.get_slice(space).to_vec().clean(cx), } } } @@ -991,7 +991,7 @@ impl Clean for ty::Method { self.fty.sig.clone()), s => { let sig = ty::FnSig { - inputs: Vec::from_slice(self.fty.sig.inputs.slice_from(1)), + inputs: self.fty.sig.inputs.slice_from(1).to_vec(), ..self.fty.sig.clone() }; let s = match s { diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs index f05e8c7cd8b..8b72bd9e102 100644 --- a/src/librustdoc/flock.rs +++ b/src/librustdoc/flock.rs @@ -183,8 +183,8 @@ mod imp { impl Lock { pub fn new(p: &Path) -> Lock { - let p_16: Vec = p.as_str().unwrap().utf16_units().collect(); - let p_16 = p_16.append_one(0); + let mut p_16: Vec = p.as_str().unwrap().utf16_units().collect(); + p_16.push(0); let handle = unsafe { libc::CreateFileW(p_16.as_ptr(), libc::FILE_GENERIC_READ | diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index cf625d4ddfc..c831015e539 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -740,8 +740,9 @@ impl<'a> SourceCollector<'a> { root_path.push_str("../"); }); - cur.push(Vec::from_slice(p.filename().expect("source has no filename")) - .append(b".html")); + let mut fname = p.filename().expect("source has no filename").to_vec(); + fname.extend(".html".bytes()); + cur.push(fname); let mut w = BufferedWriter::new(try!(File::create(&cur))); let title = format!("{} -- source", cur.filename_display()); diff --git a/src/librustrt/args.rs b/src/librustrt/args.rs index 4c444036e1d..c0a17a72014 100644 --- a/src/librustrt/args.rs +++ b/src/librustrt/args.rs @@ -47,6 +47,7 @@ mod imp { use core::prelude::*; use alloc::boxed::Box; + use collections::slice::CloneableVector; use collections::vec::Vec; use core::mem; use core::slice; @@ -106,7 +107,7 @@ mod imp { let mut len = 0; while *base.offset(len) != 0 { len += 1; } slice::raw::buf_as_slice(base, len as uint, |slice| { - Vec::from_slice(slice) + slice.to_vec() }) }) } diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 09d008a9fa9..d572d8ce58a 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -655,7 +655,7 @@ impl rtio::RtioUdpSocket for UdpWatcher { // see comments in StreamWatcher::write for why we may allocate a buffer // here. - let data = if guard.can_timeout {Some(Vec::from_slice(buf))} else {None}; + let data = if guard.can_timeout {Some(buf.to_vec())} else {None}; let uv_buf = if guard.can_timeout { slice_to_uv_buf(data.as_ref().unwrap().as_slice()) } else { diff --git a/src/librustuv/stream.rs b/src/librustuv/stream.rs index 97bd9315a0a..de49fd6cf09 100644 --- a/src/librustuv/stream.rs +++ b/src/librustuv/stream.rs @@ -159,7 +159,7 @@ impl StreamWatcher { // // To do this, the write context has an optionally owned vector of // bytes. - let data = if may_timeout {Some(Vec::from_slice(buf))} else {None}; + let data = if may_timeout {Some(buf.to_vec())} else {None}; let uv_buf = if may_timeout { slice_to_uv_buf(data.as_ref().unwrap().as_slice()) } else { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 32e461b55b1..e8d570f30e6 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -281,6 +281,7 @@ pub mod dl { #[cfg(target_os = "windows")] pub mod dl { use c_str::ToCStr; + use collections::MutableSeq; use iter::Iterator; use libc; use os; @@ -295,8 +296,8 @@ pub mod dl { // Windows expects Unicode data let filename_cstr = filename.to_c_str(); let filename_str = str::from_utf8(filename_cstr.as_bytes_no_nul()).unwrap(); - let filename_str: Vec = filename_str.utf16_units().collect(); - let filename_str = filename_str.append_one(0); + let mut filename_str: Vec = filename_str.utf16_units().collect(); + filename_str.push(0); LoadLibraryW(filename_str.as_ptr() as *const libc::c_void) as *mut u8 } diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index f2ff5c7b5c2..0a969fc37c9 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -15,7 +15,7 @@ use comm::{Sender, Receiver}; use io; use option::{None, Option, Some}; use result::{Ok, Err}; -use slice::{bytes, MutableSlice, ImmutableSlice}; +use slice::{bytes, MutableSlice, ImmutableSlice, CloneableVector}; use str::StrSlice; use super::{Reader, Writer, IoResult}; use vec::Vec; @@ -118,7 +118,7 @@ impl Clone for ChanWriter { impl Writer for ChanWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { - self.tx.send_opt(Vec::from_slice(buf)).map_err(|_| { + self.tx.send_opt(buf.to_vec()).map_err(|_| { io::IoError { kind: io::BrokenPipe, desc: "Pipe closed", diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index f912b3ee38f..b8e18fc44cb 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -61,7 +61,7 @@ use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader}; use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append}; use io::UpdateIoError; use io; -use iter::Iterator; +use iter::{Iterator, Extendable}; use kinds::Send; use libc; use option::{Some, None, Option}; @@ -688,7 +688,7 @@ impl Iterator for Directories { e, path.display())); match result { - Ok(dirs) => { self.stack.push_all_move(dirs); } + Ok(dirs) => { self.stack.extend(dirs.into_iter()); } Err(..) => {} } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 594a1cd131a..81dd114ec7d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -46,15 +46,14 @@ use ptr::RawPtr; use ptr; use result::{Err, Ok, Result}; use slice::{Slice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice}; +use slice::CloneableVector; use str::{Str, StrSlice, StrAllocating}; use string::String; use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; use vec::Vec; -#[cfg(unix)] -use c_str::ToCStr; -#[cfg(unix)] -use libc::c_char; +#[cfg(unix)] use c_str::ToCStr; +#[cfg(unix)] use libc::c_char; /// Get the number of cores available pub fn num_cpus() -> uint { @@ -260,8 +259,11 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { let mut i = 0; while *ch.offset(i) != 0 { let p = &*ch.offset(i); - let len = ptr::position(p, |c| *c == 0); - raw::buf_as_slice(p, len, |s| { + let mut len = 0; + while *(p as *const _).offset(len) != 0 { + len += 1; + } + raw::buf_as_slice(p, len as uint, |s| { result.push(String::from_utf16_lossy(s).into_bytes()); }); i += len as int + 1; @@ -284,7 +286,7 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { let mut result = Vec::new(); while *environ != 0 as *const _ { let env_pair = - Vec::from_slice(CString::new(*environ, false).as_bytes_no_nul()); + CString::new(*environ, false).as_bytes_no_nul().to_vec(); result.push(env_pair); environ = environ.offset(1); } @@ -295,9 +297,9 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { let mut pairs = Vec::new(); for p in input.iter() { let mut it = p.as_slice().splitn(1, |b| *b == b'='); - let key = Vec::from_slice(it.next().unwrap()); + let key = it.next().unwrap().to_vec(); let default: &[u8] = &[]; - let val = Vec::from_slice(it.next().unwrap_or(default)); + let val = it.next().unwrap_or(default).to_vec(); pairs.push((key, val)); } pairs @@ -351,8 +353,7 @@ pub fn getenv_as_bytes(n: &str) -> Option> { if s.is_null() { None } else { - Some(Vec::from_slice(CString::new(s as *const i8, - false).as_bytes_no_nul())) + Some(CString::new(s as *const i8, false).as_bytes_no_nul().to_vec()) } }) } @@ -365,8 +366,8 @@ pub fn getenv(n: &str) -> Option { unsafe { with_env_lock(|| { use os::windows::{fill_utf16_buf_and_decode}; - let n: Vec = n.utf16_units().collect(); - let n = n.append_one(0); + let mut n: Vec = n.utf16_units().collect(); + n.push(0); fill_utf16_buf_and_decode(|buf, sz| { libc::GetEnvironmentVariableW(n.as_ptr(), buf, sz) }) @@ -412,10 +413,10 @@ pub fn setenv(n: &str, v: T) { #[cfg(windows)] fn _setenv(n: &str, v: &[u8]) { - let n: Vec = n.utf16_units().collect(); - let n = n.append_one(0); - let v: Vec = ::str::from_utf8(v).unwrap().utf16_units().collect(); - let v = v.append_one(0); + let mut n: Vec = n.utf16_units().collect(); + n.push(0); + let mut v: Vec = ::str::from_utf8(v).unwrap().utf16_units().collect(); + v.push(0); unsafe { with_env_lock(|| { @@ -442,8 +443,8 @@ pub fn unsetenv(n: &str) { #[cfg(windows)] fn _unsetenv(n: &str) { - let n: Vec = n.utf16_units().collect(); - let n = n.append_one(0); + let mut n: Vec = n.utf16_units().collect(); + n.push(0); unsafe { with_env_lock(|| { libc::SetEnvironmentVariableW(n.as_ptr(), ptr::null()); @@ -883,7 +884,11 @@ pub fn change_dir(p: &Path) -> bool { #[cfg(windows)] fn chdir(p: &Path) -> bool { let p = match p.as_str() { - Some(s) => s.utf16_units().collect::>().append_one(0), + Some(s) => { + let mut p = s.utf16_units().collect::>(); + p.push(0); + p + } None => return false, }; unsafe { @@ -1100,8 +1105,7 @@ unsafe fn load_argc_and_argv(argc: int, use c_str::CString; Vec::from_fn(argc as uint, |i| { - Vec::from_slice(CString::new(*argv.offset(i as int), - false).as_bytes_no_nul()) + CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_vec() }) } @@ -1170,7 +1174,7 @@ fn real_args_as_bytes() -> Vec> { mem::transmute(objc_msgSend(tmp, utf8Sel)); let s = CString::new(utf_c_str, false); if s.is_not_null() { - res.push(Vec::from_slice(s.as_bytes_no_nul())) + res.push(s.as_bytes_no_nul().to_vec()) } } } diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index d84848545bd..16552daae36 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -76,7 +76,7 @@ use option::{Option, None, Some}; use str; use str::{MaybeOwned, Str, StrSlice}; use string::String; -use slice::Slice; +use slice::{Slice, CloneableVector}; use slice::{ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; @@ -480,7 +480,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let extlen = extension.container_as_bytes().len(); match (name.rposition_elem(&dot), extlen) { (None, 0) | (Some(0), 0) => None, - (Some(idx), 0) => Some(Vec::from_slice(name.slice_to(idx))), + (Some(idx), 0) => Some(name.slice_to(idx).to_vec()), (idx, extlen) => { let idx = match idx { None | Some(0) => name.len(), @@ -798,7 +798,7 @@ pub trait BytesContainer { /// Consumes the receiver and converts it into Vec #[inline] fn container_into_owned_bytes(self) -> Vec { - Vec::from_slice(self.container_as_bytes()) + self.container_as_bytes().to_vec() } /// Returns the receiver interpreted as a utf-8 string, if possible #[inline] diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 7d3c7ea71f6..9c4139853c5 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -399,7 +399,7 @@ impl Path { } }; match val { - None => Vec::from_slice(v.as_slice()), + None => v.as_slice().to_vec(), Some(val) => val } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index e703bfae610..3f598e52806 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -371,7 +371,7 @@ impl GenericPath for Path { #[inline] fn into_vec(self) -> Vec { - Vec::from_slice(self.repr.as_bytes()) + self.repr.into_bytes() } #[inline] @@ -815,12 +815,14 @@ impl Path { let mut s = String::with_capacity(n); match prefix { Some(DiskPrefix) => { - s.push_char(prefix_.as_bytes()[0].to_ascii().to_uppercase().to_char()); + s.push_char(prefix_.as_bytes()[0].to_ascii() + .to_uppercase().to_char()); s.push_char(':'); } Some(VerbatimDiskPrefix) => { s.push_str(prefix_.slice_to(4)); - s.push_char(prefix_.as_bytes()[4].to_ascii().to_uppercase().to_char()); + s.push_char(prefix_.as_bytes()[4].to_ascii() + .to_uppercase().to_char()); s.push_str(prefix_.slice_from(5)); } Some(UNCPrefix(a,b)) => { @@ -1619,7 +1621,7 @@ mod tests { t!(s: "a\\b\\c", ["d".to_string(), "e".to_string()], "a\\b\\c\\d\\e"); t!(v: b"a\\b\\c", [b"d", b"e"], b"a\\b\\c\\d\\e"); t!(v: b"a\\b\\c", [b"d", b"\\e", b"f"], b"\\e\\f"); - t!(v: b"a\\b\\c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], + t!(v: b"a\\b\\c", [b"d".to_vec(), b"e".to_vec()], b"a\\b\\c\\d\\e"); } @@ -1759,7 +1761,7 @@ mod tests { t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", ["d".to_string(), "e".to_string()], "a\\b\\c\\d\\e"); t!(v: b"a\\b\\c", [b"d", b"e"], b"a\\b\\c\\d\\e"); - t!(v: b"a\\b\\c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], + t!(v: b"a\\b\\c", [b"d".to_vec(), b"e".to_vec()], b"a\\b\\c\\d\\e"); } diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 93f773f430d..3f626d716f8 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -505,8 +505,8 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { if flags.precision > s.len() { let mut s_ = Vec::with_capacity(flags.precision); let n = flags.precision - s.len(); - s_.grow(n, &b'0'); - s_.push_all_move(s); + s_.grow(n, b'0'); + s_.extend(s.into_iter()); s = s_; } assert!(!s.is_empty(), "string conversion produced empty result"); @@ -524,7 +524,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { FormatHex => { if flags.alternate { let s_ = replace(&mut s, vec!(b'0', b'x')); - s.push_all_move(s_); + s.extend(s_.into_iter()); } } FormatHEX => { @@ -536,7 +536,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { .collect(); if flags.alternate { let s_ = replace(&mut s, vec!(b'0', b'X')); - s.push_all_move(s_); + s.extend(s_.into_iter()); } } FormatString => unreachable!() @@ -546,7 +546,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { Words(s) => { match op { FormatString => { - let mut s = Vec::from_slice(s.as_bytes()); + let mut s = s.as_bytes().to_vec(); if flags.precision > 0 && flags.precision < s.len() { s.truncate(flags.precision); } @@ -562,11 +562,11 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { if flags.width > s.len() { let n = flags.width - s.len(); if flags.left { - s.grow(n, &b' '); + s.grow(n, b' '); } else { let mut s_ = Vec::with_capacity(flags.width); - s_.grow(n, &b' '); - s_.push_all_move(s); + s_.grow(n, b' '); + s_.extend(s.into_iter()); s = s_; } } diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 2826ecc1a12..f59a4465e1d 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -290,9 +290,8 @@ pub fn parse(file: &mut io::Reader, longnames: bool) match nulpos { Some(len) => { string_map.insert(name.to_string(), - Vec::from_slice( - string_table.slice(offset as uint, - offset as uint + len))) + string_table.slice(offset as uint, + offset as uint + len).to_vec()) }, None => { return Err("invalid file: missing NUL in \ @@ -314,10 +313,10 @@ pub fn parse(file: &mut io::Reader, longnames: bool) /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> Box { let mut strings = HashMap::new(); - strings.insert("sgr0".to_string(), Vec::from_slice(b"\x1B[0m")); - strings.insert("bold".to_string(), Vec::from_slice(b"\x1B[1m")); - strings.insert("setaf".to_string(), Vec::from_slice(b"\x1B[3%p1%dm")); - strings.insert("setab".to_string(), Vec::from_slice(b"\x1B[4%p1%dm")); + strings.insert("sgr0".to_string(), b"\x1B[0m".to_vec()); + strings.insert("bold".to_string(), b"\x1B[1m".to_vec()); + strings.insert("setaf".to_string(), b"\x1B[3%p1%dm".to_vec()); + strings.insert("setab".to_string(), b"\x1B[4%p1%dm".to_vec()); box TermInfo { names: vec!("cygwin".to_string()), // msys is a fork of an older cygwin version bools: HashMap::new(), diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 7087d4c4238..ae70bb4b792 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -261,13 +261,13 @@ impl<'a, T: FloatMath + FromPrimitive> Stats for &'a [T] { } fn percentile(self, pct: T) -> T { - let mut tmp = Vec::from_slice(self); + let mut tmp = self.to_vec(); local_sort(tmp.as_mut_slice()); percentile_of_sorted(tmp.as_slice(), pct) } fn quartiles(self) -> (T,T,T) { - let mut tmp = Vec::from_slice(self); + let mut tmp = self.to_vec(); local_sort(tmp.as_mut_slice()); let first = FromPrimitive::from_uint(25).unwrap(); let a = percentile_of_sorted(tmp.as_slice(), first); @@ -318,7 +318,7 @@ fn percentile_of_sorted(sorted_samples: &[T], /// /// See: http://en.wikipedia.org/wiki/Winsorising pub fn winsorize(samples: &mut [T], pct: T) { - let mut tmp = Vec::from_slice(samples); + let mut tmp = samples.to_vec(); local_sort(tmp.as_mut_slice()); let lo = percentile_of_sorted(tmp.as_slice(), pct); let hundred: T = FromPrimitive::from_uint(100).unwrap(); diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs index 600c0ac801b..cdfb384d47c 100644 --- a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs +++ b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs @@ -12,7 +12,7 @@ fn main() { let mut vector = vec![1u, 2]; for &x in vector.iter() { let cap = vector.capacity(); - vector.grow(cap, &0u); //~ ERROR cannot borrow + vector.grow(cap, 0u); //~ ERROR cannot borrow *vector.get_mut(1u) = 5u; //~ ERROR cannot borrow } }