Skip to content

Commit c5b8763

Browse files
committed
Deprecate as_mut_slice methods
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]
1 parent 1501f33 commit c5b8763

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

src/libcollections/slice.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,11 @@ impl<T> [T] {
611611
core_slice::SliceExt::get_mut(self, index)
612612
}
613613

614-
/// Work with `self` as a mut slice.
615-
/// Primarily intended for getting a &mut [T] from a [T; N].
616-
#[stable(feature = "rust1", since = "1.0.0")]
614+
/// Deprecated: use `&mut s[..]` instead.
615+
#[unstable(feature = "collections",
616+
reason = "will be replaced by slice syntax")]
617+
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
618+
#[allow(deprecated)]
617619
pub fn as_mut_slice(&mut self) -> &mut [T] {
618620
core_slice::SliceExt::as_mut_slice(self)
619621
}

src/libcollections/vec.rs

+18-31
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,13 @@ impl<T> Vec<T> {
423423
}
424424
}
425425

426-
/// Returns a mutable slice of the elements of `self`.
427-
///
428-
/// # Examples
429-
///
430-
/// ```
431-
/// fn foo(slice: &mut [i32]) {}
432-
///
433-
/// let mut vec = vec![1, 2];
434-
/// foo(vec.as_mut_slice());
435-
/// ```
426+
/// Deprecated: use `&mut s[..]` instead.
436427
#[inline]
437-
#[stable(feature = "rust1", since = "1.0.0")]
428+
#[unstable(feature = "collections",
429+
reason = "will be replaced by slice syntax")]
430+
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
438431
pub fn as_mut_slice(&mut self) -> &mut [T] {
439-
unsafe {
440-
let ptr = *self.ptr;
441-
assume(!ptr.is_null());
442-
slice::from_raw_parts_mut(ptr, self.len)
443-
}
432+
&mut self[..]
444433
}
445434

446435
/// 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> {
14941483
#[cfg(stage0)]
14951484
#[inline]
14961485
fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] {
1497-
self.as_mut_slice()
1486+
self
14981487
}
14991488

15001489
#[cfg(not(stage0))]
15011490
#[inline]
15021491
fn index_mut(&mut self, _index: ops::RangeFull) -> &mut [T] {
1503-
self.as_mut_slice()
1492+
self
15041493
}
15051494
}
15061495

@@ -1519,7 +1508,13 @@ impl<T> ops::Deref for Vec<T> {
15191508

15201509
#[stable(feature = "rust1", since = "1.0.0")]
15211510
impl<T> ops::DerefMut for Vec<T> {
1522-
fn deref_mut(&mut self) -> &mut [T] { self.as_mut_slice() }
1511+
fn deref_mut(&mut self) -> &mut [T] {
1512+
unsafe {
1513+
let ptr = *self.ptr;
1514+
assume(!ptr.is_null());
1515+
slice::from_raw_parts_mut(ptr, self.len)
1516+
}
1517+
}
15231518
}
15241519

15251520
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1656,21 +1651,13 @@ impl<T: Ord> Ord for Vec<T> {
16561651
}
16571652
}
16581653

1654+
#[unstable(feature = "collections",
1655+
reason = "will be replaced by slice syntax")]
1656+
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
16591657
#[allow(deprecated)]
16601658
impl<T> AsSlice<T> for Vec<T> {
1661-
/// Returns a slice into `self`.
1662-
///
1663-
/// # Examples
1664-
///
1665-
/// ```
1666-
/// # #![feature(core)]
1667-
/// fn foo(slice: &[i32]) {}
1668-
///
1669-
/// let vec = vec![1, 2];
1670-
/// foo(vec.as_slice());
1671-
/// ```
1659+
/// Deprecated: use `&mut s[..]` instead.
16721660
#[inline]
1673-
#[stable(feature = "rust1", since = "1.0.0")]
16741661
fn as_slice(&self) -> &[T] {
16751662
self
16761663
}

src/libcore/slice.rs

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pub trait SliceExt {
8888
fn len(&self) -> usize;
8989
fn is_empty(&self) -> bool { self.len() == 0 }
9090
fn get_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut Self::Item>;
91+
#[unstable(feature = "core",
92+
reason = "will be replaced by slice syntax")]
93+
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
9194
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item];
9295
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>;
9396
fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>;
@@ -261,6 +264,9 @@ impl<T> SliceExt for [T] {
261264
}
262265

263266
#[inline]
267+
#[unstable(feature = "core",
268+
reason = "will be replaced by slice syntax")]
269+
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
264270
fn as_mut_slice(&mut self) -> &mut [T] { self }
265271

266272
#[cfg(stage0)]

src/librand/distributions/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct Weighted<T> {
101101
/// let mut items = vec!(Weighted { weight: 2, item: 'a' },
102102
/// Weighted { weight: 4, item: 'b' },
103103
/// Weighted { weight: 1, item: 'c' });
104-
/// let wc = WeightedChoice::new(items.as_mut_slice());
104+
/// let wc = WeightedChoice::new(&mut items[..]);
105105
/// let mut rng = rand::thread_rng();
106106
/// for _ in 0..16 {
107107
/// // on average prints 'a' 4 times, 'b' 8 and 'c' twice.

0 commit comments

Comments
 (0)