Skip to content

Commit

Permalink
Rollup merge of #23721 - erickt:deprecate, r=alexcrichton
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Manishearth committed Mar 26, 2015
2 parents 7bf66b3 + 5ed703b commit 2bf4846
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
8 changes: 5 additions & 3 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,11 @@ impl<T> [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)
}
Expand Down
49 changes: 18 additions & 31 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,24 +423,13 @@ impl<T> Vec<T> {
}
}

/// 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
Expand Down Expand Up @@ -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
}
}

Expand All @@ -1519,7 +1508,13 @@ impl<T> ops::Deref for Vec<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")]
Expand Down Expand Up @@ -1656,21 +1651,13 @@ impl<T: Ord> Ord for Vec<T> {
}
}

#[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
}
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -261,6 +264,9 @@ impl<T> 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)]
Expand Down

0 comments on commit 2bf4846

Please sign in to comment.