From 81d1feb9804f66034df4f218cc8fb0209c7450a7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Sep 2014 10:47:05 -0700 Subject: [PATCH 1/3] Remove #[allow(deprecated)] from libstd --- src/libstd/ascii.rs | 19 +++++++++---------- src/libstd/collections/hashmap/map.rs | 3 ++- src/libstd/collections/hashmap/table.rs | 4 ++-- src/libstd/failure.rs | 4 ++-- src/libstd/io/buffered.rs | 10 +++++----- src/libstd/io/extensions.rs | 24 +++++++++++------------- src/libstd/io/net/ip.rs | 16 ++++++++++++---- src/libstd/io/tempfile.rs | 2 +- src/libstd/lib.rs | 1 - src/libstd/os.rs | 9 +++++---- src/libstd/path/posix.rs | 4 ++-- src/libstd/path/windows.rs | 14 +++++++------- src/libstd/sync/task_pool.rs | 2 +- 13 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index fd8432ded8b50..fe2b8a15c7375 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -21,8 +21,7 @@ use mem; use option::{Option, Some, None}; use slice::{ImmutableSlice, MutableSlice, Slice}; use str::{Str, StrSlice}; -use str; -use string::String; +use string::{mod, String}; use to_string::IntoStr; use vec::Vec; @@ -113,7 +112,7 @@ impl Ascii { /// Check if the character is a letter or number #[inline] pub fn is_alphanumeric(&self) -> bool { - self.is_alpha() || self.is_digit() + self.is_alphabetic() || self.is_digit() } /// Check if the character is a space or horizontal tab @@ -169,7 +168,7 @@ impl Ascii { /// Checks if the character is punctuation #[inline] pub fn is_punctuation(&self) -> bool { - self.is_graph() && !self.is_alnum() + self.is_graph() && !self.is_alphanumeric() } /// Checks if the character is a valid hex digit @@ -338,12 +337,12 @@ impl<'a> AsciiStr for &'a [Ascii] { #[inline] fn to_lower(&self) -> Vec { - self.iter().map(|a| a.to_lower()).collect() + self.iter().map(|a| a.to_lowercase()).collect() } #[inline] fn to_upper(&self) -> Vec { - self.iter().map(|a| a.to_upper()).collect() + self.iter().map(|a| a.to_uppercase()).collect() } #[inline] @@ -410,13 +409,13 @@ impl<'a> AsciiExt for &'a str { #[inline] fn to_ascii_upper(&self) -> String { // Vec::to_ascii_upper() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.as_bytes().to_ascii_upper()) } + unsafe { string::raw::from_utf8(self.as_bytes().to_ascii_upper()) } } #[inline] fn to_ascii_lower(&self) -> String { // Vec::to_ascii_lower() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.as_bytes().to_ascii_lower()) } + unsafe { string::raw::from_utf8(self.as_bytes().to_ascii_lower()) } } #[inline] @@ -429,13 +428,13 @@ impl OwnedAsciiExt for String { #[inline] fn into_ascii_upper(self) -> String { // Vec::into_ascii_upper() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.into_bytes().into_ascii_upper()) } + unsafe { string::raw::from_utf8(self.into_bytes().into_ascii_upper()) } } #[inline] fn into_ascii_lower(self) -> String { // Vec::into_ascii_lower() preserves the UTF-8 invariant. - unsafe { str::raw::from_utf8_owned(self.into_bytes().into_ascii_lower()) } + unsafe { string::raw::from_utf8(self.into_bytes().into_ascii_lower()) } } } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index e8c5eecc6f2e7..b0604e1316304 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -1288,7 +1288,7 @@ impl, V: Clone, S, H: Hasher> HashMap { /// let s: String = map.get_copy(&1); /// ``` pub fn get_copy(&self, k: &K) -> V { - (*self.get(k)).clone() + self[*k].clone() } } @@ -1325,6 +1325,7 @@ impl, V, S, H: Hasher + Default> Default for HashMap impl, V, S, H: Hasher> Index for HashMap { #[inline] + #[allow(deprecated)] fn index<'a>(&'a self, index: &K) -> &'a V { self.get(index) } diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index 87a5cc1484a24..45ca633b41f9a 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -846,8 +846,8 @@ impl Clone for RawTable { (full.hash(), k.clone(), v.clone()) }; *new_buckets.raw.hash = h.inspect(); - mem::overwrite(new_buckets.raw.key, k); - mem::overwrite(new_buckets.raw.val, v); + ptr::write(new_buckets.raw.key, k); + ptr::write(new_buckets.raw.val, v); } Empty(..) => { *new_buckets.raw.hash = EMPTY_BUCKET; diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index 8d715de16e65a..a7de84184ff5d 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -38,9 +38,9 @@ impl Writer for Stdio { } pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { - let msg = match obj.as_ref::<&'static str>() { + let msg = match obj.downcast_ref::<&'static str>() { Some(s) => *s, - None => match obj.as_ref::() { + None => match obj.downcast_ref::() { Some(s) => s.as_slice(), None => "Box", } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a777a372ad14f..d9543a06b350c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -162,7 +162,7 @@ impl BufferedWriter { fn flush_buf(&mut self) -> IoResult<()> { if self.pos != 0 { - let ret = self.inner.get_mut_ref().write(self.buf.slice_to(self.pos)); + let ret = self.inner.as_mut().unwrap().write(self.buf.slice_to(self.pos)); self.pos = 0; ret } else { @@ -174,7 +174,7 @@ impl BufferedWriter { /// /// This type does not expose the ability to get a mutable reference to the /// underlying reader because that could possibly corrupt the buffer. - pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() } + pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.as_ref().unwrap() } /// Unwraps this `BufferedWriter`, returning the underlying writer. /// @@ -193,7 +193,7 @@ impl Writer for BufferedWriter { } if buf.len() > self.buf.len() { - self.inner.get_mut_ref().write(buf) + self.inner.as_mut().unwrap().write(buf) } else { let dst = self.buf.slice_from_mut(self.pos); slice::bytes::copy_memory(dst, buf); @@ -203,7 +203,7 @@ impl Writer for BufferedWriter { } fn flush(&mut self) -> IoResult<()> { - self.flush_buf().and_then(|()| self.inner.get_mut_ref().flush()) + self.flush_buf().and_then(|()| self.inner.as_mut().unwrap().flush()) } } @@ -273,7 +273,7 @@ impl InternalBufferedWriter { impl Reader for InternalBufferedWriter { fn read(&mut self, buf: &mut [u8]) -> IoResult { - self.get_mut().inner.get_mut_ref().read(buf) + self.get_mut().inner.as_mut().unwrap().read(buf) } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index b61e7c6b44191..a93f9826fa56b 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -16,13 +16,14 @@ // FIXME: Iteration should probably be considered separately use collections::{Collection, MutableSeq}; +use io::{IoError, IoResult, Reader}; +use io; use iter::Iterator; +use num::Int; use option::{Option, Some, None}; +use ptr::RawPtr; use result::{Ok, Err}; -use io; -use io::{IoError, IoResult, Reader}; use slice::{ImmutableSlice, Slice}; -use ptr::RawPtr; /// An iterator that reads a single byte on each iteration, /// until `.read_byte()` returns `EndOfFile`. @@ -76,16 +77,15 @@ impl<'r, R: Reader> Iterator> for Bytes<'r, R> { /// /// This function returns the value returned by the callback, for convenience. pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { - use mem::{to_le16, to_le32, to_le64}; use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_le* intrinsics assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_le16(n as u16)) }), - 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_le32(n as u32)) }), - 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_le64(n)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_le()) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_le()) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_le()) }), _ => { let mut bytes = vec!(); @@ -116,16 +116,15 @@ pub fn u64_to_le_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// /// This function returns the value returned by the callback, for convenience. pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { - use mem::{to_be16, to_be32, to_be64}; use mem::transmute; // LLVM fails to properly optimize this when using shifts instead of the to_be* intrinsics assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_be16(n as u16)) }), - 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_be32(n as u32)) }), - 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_be64(n)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_be()) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_be()) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_be()) }), _ => { let mut bytes = vec!(); let mut i = size; @@ -152,7 +151,6 @@ pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// 32-bit value is parsed. pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { use ptr::{copy_nonoverlapping_memory}; - use mem::from_be64; use slice::MutableSlice; assert!(size <= 8u); @@ -166,7 +164,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); - from_be64(*(out as *const u64)) + (*(out as *const u64)).to_be() } } diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 1141cd22eebb6..6eb7d1c02fbc7 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -103,7 +103,12 @@ impl<'a> Parser<'a> { // Commit only if parser read till EOF fn read_till_eof(&mut self, cb: |&mut Parser| -> Option) -> Option { - self.read_atomically(|p| cb(p).filtered(|_| p.is_eof())) + self.read_atomically(|p| { + match cb(p) { + Some(x) => if p.is_eof() {Some(x)} else {None}, + None => None, + } + }) } // Return result of first successful parser @@ -152,7 +157,10 @@ impl<'a> Parser<'a> { // Return char and advance iff next char is equal to requested fn read_given_char(&mut self, c: char) -> Option { self.read_atomically(|p| { - p.read_char().filtered(|&next| next == c) + match p.read_char() { + Some(next) if next == c => Some(next), + _ => None, + } }) } @@ -232,8 +240,8 @@ impl<'a> Parser<'a> { fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> IpAddr { assert!(head.len() + tail.len() <= 8); let mut gs = [0u16, ..8]; - gs.copy_from(head); - gs.slice_mut(8 - tail.len(), 8).copy_from(tail); + gs.clone_from_slice(head); + gs.slice_mut(8 - tail.len(), 8).clone_from_slice(tail); Ipv6Addr(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7]) } diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs index 6c9f10e19ae97..9d6713b25b724 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/io/tempfile.rs @@ -79,7 +79,7 @@ impl TempDir { /// Access the wrapped `std::path::Path` to the temporary directory. pub fn path<'a>(&'a self) -> &'a Path { - self.path.get_ref() + self.path.as_ref().unwrap() } /// Close and remove the temporary directory diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 23643542c4f01..299e41f72191d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -112,7 +112,6 @@ // Don't link to std. We are std. #![no_std] -#![allow(deprecated)] #![deny(missing_doc)] #![reexport_test_harness_main = "test_main"] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index f1480eb7d455a..594a1cd131aaa 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -276,17 +276,18 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { extern { fn rust_env_pairs() -> *const *const c_char; } - let environ = rust_env_pairs(); + let mut environ = rust_env_pairs(); if environ as uint == 0 { fail!("os::env() failure getting env string from OS: {}", os::last_os_error()); } let mut result = Vec::new(); - ptr::array_each(environ, |e| { + while *environ != 0 as *const _ { let env_pair = - Vec::from_slice(CString::new(e, false).as_bytes_no_nul()); + Vec::from_slice(CString::new(*environ, false).as_bytes_no_nul()); result.push(env_pair); - }); + environ = environ.offset(1); + } result } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index c654d3a668a7c..7d3c7ea71f676 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -264,7 +264,7 @@ impl GenericPath for Path { #[inline] fn is_absolute(&self) -> bool { - *self.repr.get(0) == SEP_BYTE + self.repr[0] == SEP_BYTE } fn is_ancestor_of(&self, other: &Path) -> bool { @@ -409,7 +409,7 @@ impl Path { /// /a/b/c and a/b/c yield the same set of components. /// A path of "/" yields no components. A path of "." yields one component. pub fn components<'a>(&'a self) -> Components<'a> { - let v = if *self.repr.get(0) == SEP_BYTE { + let v = if self.repr[0] == SEP_BYTE { self.repr.slice_from(1) } else { self.repr.as_slice() }; let mut ret = v.split(is_sep_byte); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index e68c8bdb07d20..e703bfae61089 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -264,10 +264,10 @@ impl GenericPathUnsafe for Path { let repr = me.repr.as_slice(); match me.prefix { Some(DiskPrefix) => { - repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_uppercase().to_byte() } Some(VerbatimDiskPrefix) => { - repr.as_bytes()[4] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + repr.as_bytes()[4] == path.as_bytes()[0].to_ascii().to_uppercase().to_byte() } _ => false } @@ -776,9 +776,9 @@ impl Path { let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); - *v.get_mut(0) = v.get(0) + *v.get_mut(0) = (*v)[0] .to_ascii() - .to_upper() + .to_uppercase() .to_byte(); } if is_abs { @@ -794,7 +794,7 @@ impl Path { let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); - *v.get_mut(4) = v.get(4).to_ascii().to_upper().to_byte(); + *v.get_mut(4) = (*v)[4].to_ascii().to_uppercase().to_byte(); } Some(s) } @@ -815,12 +815,12 @@ impl Path { let mut s = String::with_capacity(n); match prefix { Some(DiskPrefix) => { - s.push_char(prefix_.as_bytes()[0].to_ascii().to_upper().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_upper().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)) => { diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 23ba582ec0aa7..a00eeb1f93838 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -79,7 +79,7 @@ impl TaskPool { /// Executes the function `f` on a task in the pool. The function /// receives a reference to the local data returned by the `init_fn`. pub fn execute(&mut self, f: proc(&T):Send) { - self.channels.get(self.next_index).send(Execute(f)); + self.channels[self.next_index].send(Execute(f)); self.next_index += 1; if self.next_index == self.channels.len() { self.next_index = 0; } } From 087b9283a0ed8df68f47ab07a25e60bc6a3ca050 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 29 Aug 2014 13:20:58 -0700 Subject: [PATCH 2/3] collections: Stabilize Vec The following methods, types, and names have become stable: * Vec * Vec::as_mut_slice * Vec::as_slice * Vec::capacity * Vec::clear * Vec::default * Vec::grow * Vec::insert * Vec::len * Vec::new * Vec::pop * Vec::push * Vec::remove * Vec::set_len * Vec::shrink_to_fit * Vec::truncate * Vec::with_capacity The following have become unstable: * Vec::dedup // naming * Vec::from_fn // naming and unboxed closures * Vec::get_mut // will be removed for IndexMut * Vec::grow_fn // unboxed closures and naming * Vec::retain // unboxed closures * Vec::swap_remove // uncertain naming * Vec::from_elem // uncertain semantics * vec::unzip // should be generic for all collections The following have been deprecated * Vec::append - call .extend() * Vec::append_one - call .push() * Vec::from_slice - call .to_vec() * Vec::grow_set - call .grow() and then .push() * Vec::into_vec - move the vector instead * Vec::move_iter - renamed to iter_move() * Vec::to_vec - call .clone() The following methods remain experimental pending conventions * vec::raw * vec::raw::from_buf * Vec:from_raw_parts * Vec::push_all This is a breaking change in terms of the signature of the `Vec::grow` function. The argument used to be taken by reference, but it is now taken by value. Code must update by removing a leading `&` sigil or by calling `.clone()` to create a value. [breaking-change] --- src/libcollections/vec.rs | 61 +++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 4051f68213436..dc43dd5e53d6c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -99,6 +99,7 @@ use slice::{Items, MutItems}; /// to use `Vec::with_capacity` whenever possible to specify how big the vector /// is expected to get. #[unsafe_no_drop_flag] +#[stable] pub struct Vec { len: uint, cap: uint, @@ -116,6 +117,7 @@ impl Vec { /// let mut vec: Vec = Vec::new(); /// ``` #[inline] + #[stable] pub fn new() -> Vec { // We want ptr to never be NULL so instead we set it to some arbitrary // non-null value which is fine since we never call deallocate on the ptr @@ -152,6 +154,7 @@ impl Vec { /// vec.push(11); /// ``` #[inline] + #[stable] pub fn with_capacity(capacity: uint) -> Vec { if mem::size_of::() == 0 { Vec { len: 0, cap: uint::MAX, ptr: EMPTY as *mut T } @@ -177,6 +180,8 @@ impl Vec { /// assert_eq!(vec, vec![0, 2, 4]); /// ``` #[inline] + #[unstable = "the naming is uncertain as well as this migrating to unboxed \ + closures in the future"] pub fn from_fn(length: uint, op: |uint| -> T) -> Vec { unsafe { let mut xs = Vec::with_capacity(length); @@ -229,6 +234,7 @@ impl Vec { /// } /// } /// ``` + #[experimental] pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut T) -> Vec { Vec { len: length, cap: capacity, ptr: ptr } @@ -249,6 +255,7 @@ impl Vec { /// assert_eq!(odd, vec![1, 3]); /// ``` #[inline] + #[experimental] pub fn partition(self, f: |&T| -> bool) -> (Vec, Vec) { let mut lefts = Vec::new(); let mut rights = Vec::new(); @@ -277,6 +284,7 @@ impl Vec { /// assert_eq!(vec, vec![1, 2, 3, 4]); /// ``` #[inline] + #[deprecated = "this function has been deprecated in favor of extend()"] pub fn append(mut self, second: &[T]) -> Vec { self.push_all(second); self @@ -291,6 +299,7 @@ impl Vec { /// let vec = Vec::from_slice(slice); /// ``` #[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); @@ -307,6 +316,7 @@ impl Vec { /// println!("{}", vec); // prints [hi, hi, hi] /// ``` #[inline] + #[unstable = "this functionality may become more generic over all collections"] pub fn from_elem(length: uint, value: T) -> Vec { unsafe { let mut xs = Vec::with_capacity(length); @@ -333,6 +343,7 @@ impl Vec { /// assert_eq!(vec, vec![1, 2, 3, 4]); /// ``` #[inline] + #[experimental] pub fn push_all(&mut self, other: &[T]) { self.reserve_additional(other.len()); @@ -359,15 +370,16 @@ impl Vec { /// /// ``` /// let mut vec = vec!["hello"]; - /// vec.grow(2, &("world")); + /// vec.grow(2, "world"); /// assert_eq!(vec, vec!["hello", "world", "world"]); /// ``` - pub fn grow(&mut self, n: uint, value: &T) { + #[stable] + pub fn grow(&mut self, n: uint, value: T) { self.reserve_additional(n); let mut i: uint = 0u; while i < n { - self.push((*value).clone()); + self.push(value.clone()); i += 1u; } } @@ -382,15 +394,17 @@ impl Vec { /// # Example /// /// ``` + /// # #![allow(deprecated)] /// let mut vec = vec!["a", "b", "c"]; /// vec.grow_set(1, &("fill"), "d"); /// vec.grow_set(4, &("fill"), "e"); /// assert_eq!(vec, vec!["a", "d", "c", "fill", "e"]); /// ``` + #[deprecated = "call .grow() and .push() manually instead"] pub fn grow_set(&mut self, index: uint, initval: &T, value: T) { let l = self.len(); if index >= l { - self.grow(index - l + 1u, initval); + self.grow(index - l + 1u, initval.clone()); } *self.get_mut(index) = value; } @@ -409,6 +423,7 @@ impl Vec { /// assert_eq!(even, vec![2i, 4]); /// assert_eq!(odd, vec![1i, 3]); /// ``` + #[experimental] pub fn partitioned(&self, f: |&T| -> bool) -> (Vec, Vec) { let mut lefts = Vec::new(); let mut rights = Vec::new(); @@ -449,6 +464,7 @@ impl Clone for Vec { } } +#[experimental = "waiting on Index stability"] impl Index for Vec { #[inline] #[allow(deprecated)] // allow use of get @@ -506,6 +522,8 @@ impl ops::SliceMut for Vec { self.as_mut_slice().slice_mut_(start, end) } } + +#[experimental = "waiting on FromIterator stability"] impl FromIterator for Vec { #[inline] fn from_iter>(mut iterator: I) -> Vec { @@ -518,6 +536,7 @@ impl FromIterator for Vec { } } +#[experimental = "waiting on Extendable stability"] impl Extendable for Vec { #[inline] fn extend>(&mut self, mut iterator: I) { @@ -529,6 +548,7 @@ impl Extendable for Vec { } } +#[unstable = "waiting on PartialEq stability"] impl PartialEq for Vec { #[inline] fn eq(&self, other: &Vec) -> bool { @@ -536,6 +556,7 @@ impl PartialEq for Vec { } } +#[unstable = "waiting on PartialOrd stability"] impl PartialOrd for Vec { #[inline] fn partial_cmp(&self, other: &Vec) -> Option { @@ -543,13 +564,16 @@ impl PartialOrd for Vec { } } +#[unstable = "waiting on Eq stability"] impl Eq for Vec {} +#[experimental] impl> Equiv for Vec { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } +#[unstable = "waiting on Ord stability"] impl Ord for Vec { #[inline] fn cmp(&self, other: &Vec) -> Ordering { @@ -557,15 +581,19 @@ impl Ord for Vec { } } +#[experimental = "waiting on Collection stability"] impl Collection for Vec { #[inline] + #[stable] fn len(&self) -> uint { self.len } } impl CloneableVector for Vec { + #[deprecated = "call .clone() instead"] fn to_vec(&self) -> Vec { self.clone() } + #[deprecated = "move the vector instead"] fn into_vec(self) -> Vec { self } } @@ -600,6 +628,7 @@ impl Vec { /// assert_eq!(vec.capacity(), 10); /// ``` #[inline] + #[stable] pub fn capacity(&self) -> uint { self.cap } @@ -683,6 +712,7 @@ impl Vec { /// let mut vec = vec![1i, 2, 3]; /// vec.shrink_to_fit(); /// ``` + #[stable] pub fn shrink_to_fit(&mut self) { if mem::size_of::() == 0 { return } @@ -717,6 +747,7 @@ impl Vec { /// assert_eq!(vec, vec![1, 2, 3]); /// ``` #[inline] + #[deprecated = "call .push() instead"] pub fn append_one(mut self, x: T) -> Vec { self.push(x); self @@ -734,6 +765,7 @@ impl Vec { /// vec.truncate(2); /// assert_eq!(vec, vec![1, 2]); /// ``` + #[stable] pub fn truncate(&mut self, len: uint) { unsafe { // drop any extra elements @@ -757,6 +789,7 @@ impl Vec { /// foo(vec.as_mut_slice()); /// ``` #[inline] + #[stable] pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { mem::transmute(RawSlice { @@ -796,7 +829,6 @@ impl Vec { } } - /// Sets the length of a vector. /// /// This will explicitly set the size of the vector, without actually @@ -812,6 +844,7 @@ impl Vec { /// } /// ``` #[inline] + #[stable] pub unsafe fn set_len(&mut self, len: uint) { self.len = len; } @@ -850,6 +883,7 @@ impl Vec { /// assert_eq!(vec, vec![1i, 4, 3]); /// ``` #[inline] + #[unstable = "this is likely to be moved to actual indexing"] pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut T { &mut self.as_mut_slice()[index] } @@ -1020,6 +1054,7 @@ impl Vec { /// assert_eq!(v.swap_remove(2), None); /// ``` #[inline] + #[unstable = "the naming of this function may be altered"] pub fn swap_remove(&mut self, index: uint) -> Option { let length = self.len(); if length > 0 && index < length - 1 { @@ -1088,6 +1123,7 @@ impl Vec { /// vec.insert(4, 5); /// assert_eq!(vec, vec![1, 4, 2, 3, 5]); /// ``` + #[stable] pub fn insert(&mut self, index: uint, element: T) { let len = self.len(); assert!(index <= len); @@ -1124,6 +1160,7 @@ impl Vec { /// // v is unchanged: /// assert_eq!(v, vec![1, 3]); /// ``` + #[stable] pub fn remove(&mut self, index: uint) -> Option { let len = self.len(); if index < len { @@ -1410,6 +1447,7 @@ impl Vec { /// vec.retain(|x| x%2 == 0); /// assert_eq!(vec, vec![2, 4]); /// ``` + #[unstable = "the closure argument may become an unboxed closure"] pub fn retain(&mut self, f: |&T| -> bool) { let len = self.len(); let mut del = 0u; @@ -1441,6 +1479,7 @@ impl Vec { /// vec.grow_fn(3, |i| i); /// assert_eq!(vec, vec![0, 1, 0, 1, 2]); /// ``` + #[unstable = "this function may be renamed or change to unboxed closures"] pub fn grow_fn(&mut self, n: uint, f: |uint| -> T) { self.reserve_additional(n); for i in range(0u, n) { @@ -1467,8 +1506,10 @@ impl Vec { } } +#[experimental = "waiting on Mutable stability"] impl Mutable for Vec { #[inline] + #[stable] fn clear(&mut self) { self.truncate(0) } @@ -1499,6 +1540,7 @@ impl Vec { /// vec.dedup(); /// assert_eq!(vec, vec![1i, 2, 3, 2]); /// ``` + #[unstable = "this function may be renamed"] pub fn dedup(&mut self) { unsafe { // Although we have a mutable reference to `self`, we cannot make @@ -1596,6 +1638,7 @@ impl Slice for Vec { /// foo(vec.as_slice()); /// ``` #[inline] + #[stable] fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { mem::transmute(RawSlice { data: self.as_ptr(), len: self.len }) } } @@ -1627,18 +1670,21 @@ impl Drop for Vec { } } +#[stable] impl Default for Vec { fn default() -> Vec { Vec::new() } } +#[experimental = "waiting on Show stability"] impl fmt::Show for Vec { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_slice().fmt(f) } } +#[experimental = "waiting on MutableSeq stability"] impl MutableSeq for Vec { /// Appends an element to the back of a collection. /// @@ -1654,6 +1700,7 @@ impl MutableSeq for Vec { /// assert_eq!(vec, vec!(1, 2, 3)); /// ``` #[inline] + #[stable] fn push(&mut self, value: T) { if mem::size_of::() == 0 { // zero-size types consume no memory, so we can't rely on the address space running out @@ -1680,6 +1727,7 @@ impl MutableSeq for Vec { } #[inline] + #[stable] fn pop(&mut self) -> Option { if self.len == 0 { None @@ -1765,6 +1813,7 @@ impl Drop for MoveItems { /// vector contains the first element of the i-th tuple of the input iterator, /// and the i-th element of the second vector contains the second element /// of the i-th tuple of the input iterator. +#[unstable = "this functionality may become more generic over time"] pub fn unzip>(mut iter: V) -> (Vec, Vec) { let (lo, _) = iter.size_hint(); let mut ts = Vec::with_capacity(lo); @@ -1777,6 +1826,7 @@ pub fn unzip>(mut iter: V) -> (Vec, Vec) { } /// Unsafe vector operations. +#[unstable] pub mod raw { use super::Vec; use core::ptr; @@ -1786,6 +1836,7 @@ pub mod raw { /// The elements of the buffer are copied into the vector without cloning, /// as if `ptr::read()` were called on them. #[inline] + #[unstable] pub unsafe fn from_buf(ptr: *const T, elts: uint) -> Vec { let mut dst = Vec::with_capacity(elts); dst.set_len(elts); From 0169218047dc989acf9ea25e3122b9c659acb6b3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Sep 2014 12:56:31 -0700 Subject: [PATCH 3/3] 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 d64d3317e2e5b..f3e9177fc6e11 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 5028f224475a9..2ffe22cba7553 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 11affb9dfd576..60c9dfcff187c 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 f93b5c89127e5..44fe962fad4a0 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 88c683ef44e93..f677b170bb367 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 a12d403603fe8..bb66d271ee4d4 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 dc43dd5e53d6c..d5ca48e605a64 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 ab06f327592d4..94e89dc6043ce 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 51115990a3113..648aa8668144b 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 c4b517c525963..91c3da001628e 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 ad60829c08800..7f4289b128afe 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 ae6dd2a4d70a7..cc6a8e27cda4a 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 b4d44aab23921..660b6c7ade2b2 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 f05e8c7cd8bd2..8b72bd9e10283 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 cf625d4ddfc79..c831015e53936 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 4c444036e1db9..c0a17a7201473 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 09d008a9fa904..d572d8ce58a53 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 97bd9315a0a5c..de49fd6cf0986 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 32e461b55b170..e8d570f30e614 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 f2ff5c7b5c2b4..0a969fc37c924 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 f912b3ee38f10..b8e18fc44cbc6 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 594a1cd131aaa..81dd114ec7d06 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 d84848545bda8..16552daae36b7 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 7d3c7ea71f676..9c4139853c540 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 e703bfae61089..3f598e5280624 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 93f773f430d40..3f626d716f88b 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 2826ecc1a1222..f59a4465e1da4 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 7087d4c423838..ae70bb4b7925a 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 600c0ac801b7e..cdfb384d47ca2 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 } }