]> git.lizzy.rs Git - rust.git/commitdiff
Stop returning k from [T]::rotate
authorScott McMurray <scottmcm@users.noreply.github.com>
Sun, 21 May 2017 10:05:19 +0000 (03:05 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Sun, 21 May 2017 10:05:19 +0000 (03:05 -0700)
src/libcollections/slice.rs
src/libcollections/tests/slice.rs
src/libcore/slice/mod.rs
src/libcore/tests/slice.rs

index 668f8cf80cfb3d459d260a8f52bb477574642de4..702f19976cd5e670d56297fc60db84c213bc8ff8 100644 (file)
@@ -1342,14 +1342,12 @@ pub fn sort_unstable_by_key<B, F>(&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<B, F>(&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<B, F>(&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`.
index 6feaf91d6da064fa1d0103875e2d82936f394eee..7fa65a2144e9b47d1f3f093c04fa980bc6bf5596 100644 (file)
@@ -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();
 
index 8cdfcf23254e77b027dd448d803a5644ce17ca92..0c28f1f69dda00efb9596fb13e98a9ec5acdf59c 100644 (file)
@@ -204,7 +204,7 @@ unsafe fn get_unchecked_mut<I>(&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<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
         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]
index f34f94975009efe36ead17ed9afa828b33a6ebfb..e5d6b53b570628b688e8e623a0b6052f5dab1f0d 100644 (file)
@@ -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);
     }