diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 688d730e25287..83e632e6c9676 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -611,9 +611,11 @@ impl [T] { core_slice::SliceExt::get_mut(self, index) } - /// Work with `self` as a mut slice. - /// Primarily intended for getting a &mut [T] from a [T; N]. - #[stable(feature = "rust1", since = "1.0.0")] + /// Deprecated: use `&mut s[..]` instead. + #[unstable(feature = "collections", + reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] + #[allow(deprecated)] pub fn as_mut_slice(&mut self) -> &mut [T] { core_slice::SliceExt::as_mut_slice(self) } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e71077c96c774..19b0d5b166786 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -423,24 +423,13 @@ impl Vec { } } - /// Returns a mutable slice of the elements of `self`. - /// - /// # Examples - /// - /// ``` - /// fn foo(slice: &mut [i32]) {} - /// - /// let mut vec = vec![1, 2]; - /// foo(vec.as_mut_slice()); - /// ``` + /// Deprecated: use `&mut s[..]` instead. #[inline] - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "collections", + reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] pub fn as_mut_slice(&mut self) -> &mut [T] { - unsafe { - let ptr = *self.ptr; - assume(!ptr.is_null()); - slice::from_raw_parts_mut(ptr, self.len) - } + &mut self[..] } /// Creates a consuming iterator, that is, one that moves each value out of @@ -1494,13 +1483,13 @@ impl ops::IndexMut for Vec { #[cfg(stage0)] #[inline] fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] { - self.as_mut_slice() + self } #[cfg(not(stage0))] #[inline] fn index_mut(&mut self, _index: ops::RangeFull) -> &mut [T] { - self.as_mut_slice() + self } } @@ -1519,7 +1508,13 @@ impl ops::Deref for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl ops::DerefMut for Vec { - fn deref_mut(&mut self) -> &mut [T] { self.as_mut_slice() } + fn deref_mut(&mut self) -> &mut [T] { + unsafe { + let ptr = *self.ptr; + assume(!ptr.is_null()); + slice::from_raw_parts_mut(ptr, self.len) + } + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1656,21 +1651,13 @@ impl Ord for Vec { } } +#[unstable(feature = "collections", + reason = "will be replaced by slice syntax")] +#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] #[allow(deprecated)] impl AsSlice for Vec { - /// Returns a slice into `self`. - /// - /// # Examples - /// - /// ``` - /// # #![feature(core)] - /// fn foo(slice: &[i32]) {} - /// - /// let vec = vec![1, 2]; - /// foo(vec.as_slice()); - /// ``` + /// Deprecated: use `&mut s[..]` instead. #[inline] - #[stable(feature = "rust1", since = "1.0.0")] fn as_slice(&self) -> &[T] { self } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index fce29abed7300..892660b98bc95 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -88,6 +88,9 @@ pub trait SliceExt { fn len(&self) -> usize; fn is_empty(&self) -> bool { self.len() == 0 } fn get_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut Self::Item>; + #[unstable(feature = "core", + reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item]; fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>; fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>; @@ -261,6 +264,9 @@ impl SliceExt for [T] { } #[inline] + #[unstable(feature = "core", + reason = "will be replaced by slice syntax")] + #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] fn as_mut_slice(&mut self) -> &mut [T] { self } #[cfg(stage0)]