From 094d61f079e5f06930e002da18f92dde5827154f Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 21 May 2017 03:05:19 -0700 Subject: [PATCH] Stop returning k from [T]::rotate --- src/libcollections/slice.rs | 14 +++++++------- src/libcollections/tests/slice.rs | 3 +-- src/libcore/slice/mod.rs | 6 ++---- src/libcore/tests/slice.rs | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 668f8cf80cf..702f19976cd 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1342,14 +1342,12 @@ pub fn sort_unstable_by_key(&mut self, f: F) /// slice. Equivalently, rotates the slice `mid` places to the left /// or `k = self.len() - mid` places to the right. /// - /// Rotation by `mid` and rotation by `k` are inverse operations. - /// The method returns `k`, which is also the new location of - /// the formerly-first element. - /// /// This is a "k-rotation", a permutation in which item `i` moves to /// position `i + k`, modulo the length of the slice. See _Elements /// of Programming_ [§10.4][eop]. /// + /// Rotation by `mid` and rotation by `k` are inverse operations. + /// /// [eop]: https://books.google.com/books?id=CO9ULZGINlsC&pg=PA178&q=k-rotation /// /// # Panics @@ -1368,8 +1366,10 @@ pub fn sort_unstable_by_key(&mut self, f: F) /// #![feature(slice_rotate)] /// /// let mut a = [1, 2, 3, 4, 5, 6, 7]; - /// let k = a.rotate(2); + /// let mid = 2; + /// a.rotate(mid); /// assert_eq!(&a, &[3, 4, 5, 6, 7, 1, 2]); + /// let k = a.len() - mid; /// a.rotate(k); /// assert_eq!(&a, &[1, 2, 3, 4, 5, 6, 7]); /// @@ -1388,8 +1388,8 @@ pub fn sort_unstable_by_key(&mut self, f: F) /// assert_eq!(&v, &[0, 3, 7, 4, 5, 6, 1, 2, 8, 9]); /// ``` #[unstable(feature = "slice_rotate", issue = "41891")] - pub fn rotate(&mut self, mid: usize) -> usize { - core_slice::SliceExt::rotate(self, mid) + pub fn rotate(&mut self, mid: usize) { + core_slice::SliceExt::rotate(self, mid); } /// Copies the elements from `src` into `self`. diff --git a/src/libcollections/tests/slice.rs b/src/libcollections/tests/slice.rs index 6feaf91d6da..7fa65a2144e 100644 --- a/src/libcollections/tests/slice.rs +++ b/src/libcollections/tests/slice.rs @@ -482,9 +482,8 @@ fn test_rotate() { // happy path v = (5..13).chain(0..5).collect(); - let k = v.rotate(8); + v.rotate(8); assert_eq!(v, expected); - assert_eq!(k, 5); let expected: Vec<_> = (0..1000).collect(); diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8cdfcf23254..0c28f1f69dd 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -204,7 +204,7 @@ unsafe fn get_unchecked_mut(&mut self, index: I) -> &mut I::Output fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq; #[unstable(feature = "slice_rotate", issue = "41891")] - fn rotate(&mut self, mid: usize) -> usize; + fn rotate(&mut self, mid: usize); #[stable(feature = "clone_from_slice", since = "1.7.0")] fn clone_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Clone; @@ -639,7 +639,7 @@ fn binary_search(&self, x: &Q) -> Result self.binary_search_by(|p| p.borrow().cmp(x)) } - fn rotate(&mut self, mid: usize) -> usize { + fn rotate(&mut self, mid: usize) { assert!(mid <= self.len()); let k = self.len() - mid; @@ -647,8 +647,6 @@ fn rotate(&mut self, mid: usize) -> usize { let p = self.as_mut_ptr(); rotate::ptr_rotate(mid, p.offset(mid as isize), k); } - - k } #[inline] diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index f34f9497500..e5d6b53b570 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -246,9 +246,9 @@ fn test_rotate() { a[i] = i; } - let k = a.rotate(42); + a.rotate(42); + let k = N - 42; - assert_eq!(k, N - 42); for i in 0..N { assert_eq!(a[(i+k)%N], i); } -- 2.44.0