Skip to content

Commit 094d61f

Browse files
committed
Stop returning k from [T]::rotate
1 parent 95db271 commit 094d61f

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/libcollections/slice.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1342,14 +1342,12 @@ impl<T> [T] {
13421342
/// slice. Equivalently, rotates the slice `mid` places to the left
13431343
/// or `k = self.len() - mid` places to the right.
13441344
///
1345-
/// Rotation by `mid` and rotation by `k` are inverse operations.
1346-
/// The method returns `k`, which is also the new location of
1347-
/// the formerly-first element.
1348-
///
13491345
/// This is a "k-rotation", a permutation in which item `i` moves to
13501346
/// position `i + k`, modulo the length of the slice. See _Elements
13511347
/// of Programming_ [§10.4][eop].
13521348
///
1349+
/// Rotation by `mid` and rotation by `k` are inverse operations.
1350+
///
13531351
/// [eop]: https://books.google.com/books?id=CO9ULZGINlsC&pg=PA178&q=k-rotation
13541352
///
13551353
/// # Panics
@@ -1368,8 +1366,10 @@ impl<T> [T] {
13681366
/// #![feature(slice_rotate)]
13691367
///
13701368
/// let mut a = [1, 2, 3, 4, 5, 6, 7];
1371-
/// let k = a.rotate(2);
1369+
/// let mid = 2;
1370+
/// a.rotate(mid);
13721371
/// assert_eq!(&a, &[3, 4, 5, 6, 7, 1, 2]);
1372+
/// let k = a.len() - mid;
13731373
/// a.rotate(k);
13741374
/// assert_eq!(&a, &[1, 2, 3, 4, 5, 6, 7]);
13751375
///
@@ -1388,8 +1388,8 @@ impl<T> [T] {
13881388
/// assert_eq!(&v, &[0, 3, 7, 4, 5, 6, 1, 2, 8, 9]);
13891389
/// ```
13901390
#[unstable(feature = "slice_rotate", issue = "41891")]
1391-
pub fn rotate(&mut self, mid: usize) -> usize {
1392-
core_slice::SliceExt::rotate(self, mid)
1391+
pub fn rotate(&mut self, mid: usize) {
1392+
core_slice::SliceExt::rotate(self, mid);
13931393
}
13941394

13951395
/// Copies the elements from `src` into `self`.

src/libcollections/tests/slice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,8 @@ fn test_rotate() {
482482

483483
// happy path
484484
v = (5..13).chain(0..5).collect();
485-
let k = v.rotate(8);
485+
v.rotate(8);
486486
assert_eq!(v, expected);
487-
assert_eq!(k, 5);
488487

489488
let expected: Vec<_> = (0..1000).collect();
490489

src/libcore/slice/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub trait SliceExt {
204204
fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
205205

206206
#[unstable(feature = "slice_rotate", issue = "41891")]
207-
fn rotate(&mut self, mid: usize) -> usize;
207+
fn rotate(&mut self, mid: usize);
208208

209209
#[stable(feature = "clone_from_slice", since = "1.7.0")]
210210
fn clone_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Clone;
@@ -639,16 +639,14 @@ impl<T> SliceExt for [T] {
639639
self.binary_search_by(|p| p.borrow().cmp(x))
640640
}
641641

642-
fn rotate(&mut self, mid: usize) -> usize {
642+
fn rotate(&mut self, mid: usize) {
643643
assert!(mid <= self.len());
644644
let k = self.len() - mid;
645645

646646
unsafe {
647647
let p = self.as_mut_ptr();
648648
rotate::ptr_rotate(mid, p.offset(mid as isize), k);
649649
}
650-
651-
k
652650
}
653651

654652
#[inline]

src/libcore/tests/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ fn test_rotate() {
246246
a[i] = i;
247247
}
248248

249-
let k = a.rotate(42);
249+
a.rotate(42);
250+
let k = N - 42;
250251

251-
assert_eq!(k, N - 42);
252252
for i in 0..N {
253253
assert_eq!(a[(i+k)%N], i);
254254
}

0 commit comments

Comments
 (0)