]> git.lizzy.rs Git - rust.git/commitdiff
Deprecate as_mut_slice methods
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Thu, 26 Mar 2015 14:29:06 +0000 (07:29 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Thu, 26 Mar 2015 14:29:06 +0000 (07:29 -0700)
This is technically a breaking change as it deprecates and unstables
some previously stable apis that were missed in the last round of
deprecations.

[breaking change]

src/libcollections/slice.rs
src/libcollections/vec.rs
src/libcore/slice.rs
src/librand/distributions/mod.rs

index 688d730e2528744c03f49903d7928a0610384a29..83e632e6c9676fef00036319fc5cd7c652c16e0a 100644 (file)
@@ -611,9 +611,11 @@ pub fn get_mut(&mut self, index: usize) -> Option<&mut 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)
     }
index e71077c96c774a4acbfb7bdf5174138ae39dd08e..19b0d5b166786f54be677f123b9cc0f7f240ec94 100644 (file)
@@ -423,24 +423,13 @@ pub fn truncate(&mut self, len: usize) {
         }
     }
 
-    /// 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<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
     #[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 @@ fn deref(&self) -> &[T] {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::DerefMut for Vec<T> {
-    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 @@ fn cmp(&self, other: &Vec<T>) -> Ordering {
     }
 }
 
+#[unstable(feature = "collections",
+           reason = "will be replaced by slice syntax")]
+#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
 #[allow(deprecated)]
 impl<T> AsSlice<T> for Vec<T> {
-    /// 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
     }
index fce29abed7300c161c416be5f78b8f379cb92594..892660b98bc95ac4279fa7c3c147cf54339f4023 100644 (file)
@@ -88,6 +88,9 @@ fn binary_search_by<F>(&self, f: F) -> Result<usize, usize> where
     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 @@ fn get_mut(&mut self, index: usize) -> Option<&mut 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)]
index 5cafb8d2e5eae2ab6f61339c9f4f2c42536d75d8..83cb5c567c794adff525ce74b835b385f5e551d0 100644 (file)
@@ -101,7 +101,7 @@ pub struct Weighted<T> {
 /// let mut items = vec!(Weighted { weight: 2, item: 'a' },
 ///                      Weighted { weight: 4, item: 'b' },
 ///                      Weighted { weight: 1, item: 'c' });
-/// let wc = WeightedChoice::new(items.as_mut_slice());
+/// let wc = WeightedChoice::new(&mut items[..]);
 /// let mut rng = rand::thread_rng();
 /// for _ in 0..16 {
 ///      // on average prints 'a' 4 times, 'b' 8 and 'c' twice.