about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-09-04 20:08:12 -0700
committerJosh Stone <jistone@redhat.com>2020-09-04 20:08:12 -0700
commit86b9f710d0c90068866e736bbbb7b89ac93ff2e6 (patch)
tree507fd489a7d0aafde1c2bd8d771b93caeab8c02a
parent21903532eee96a5311d08b8a9e9cc9f9231bc478 (diff)
downloadrust-86b9f710d0c90068866e736bbbb7b89ac93ff2e6.tar.gz
rust-86b9f710d0c90068866e736bbbb7b89ac93ff2e6.zip
Move ArrayChunksMut::get_unchecked per #73565
-rw-r--r--library/core/src/slice/mod.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index a32ea062de4..609fdbd5992 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -1070,9 +1070,10 @@ impl<T> [T] {
         let (fst, snd) = self.split_at_mut(len * N);
         // SAFETY: We cast a slice of `len * N` elements into
         // a slice of `len` many `N` elements chunks.
-        let array_slice: &mut [[T; N]] =
-            unsafe { from_raw_parts_mut(fst.as_mut_ptr().cast(), len) };
-        ArrayChunksMut { iter: array_slice.iter_mut(), rem: snd }
+        unsafe {
+            let array_slice: &mut [[T; N]] = from_raw_parts_mut(fst.as_mut_ptr().cast(), len);
+            ArrayChunksMut { iter: array_slice.iter_mut(), rem: snd }
+        }
     }
 
     /// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end
@@ -6028,6 +6029,12 @@ impl<'a, T, const N: usize> Iterator for ArrayChunksMut<'a, T, N> {
     fn last(self) -> Option<Self::Item> {
         self.iter.last()
     }
+
+    unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut [T; N] {
+        // SAFETY: The safety guarantees of `get_unchecked` are transferred to
+        // the caller.
+        unsafe { self.iter.get_unchecked(i) }
+    }
 }
 
 #[unstable(feature = "array_chunks", issue = "74985")]
@@ -6059,9 +6066,6 @@ impl<T, const N: usize> FusedIterator for ArrayChunksMut<'_, T, N> {}
 #[doc(hidden)]
 #[unstable(feature = "array_chunks", issue = "74985")]
 unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunksMut<'a, T, N> {
-    unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut [T; N] {
-        unsafe { self.iter.get_unchecked(i) }
-    }
     fn may_have_side_effect() -> bool {
         false
     }