about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-08-02 10:35:57 -0700
committerJosh Stone <jistone@redhat.com>2020-09-04 19:51:29 -0700
commit21903532eee96a5311d08b8a9e9cc9f9231bc478 (patch)
tree14818906c4dd599dc918e2adce485b185124e206
parent864a28e01d70cd73ef7f0b64f6793697f638b8b0 (diff)
downloadrust-21903532eee96a5311d08b8a9e9cc9f9231bc478.tar.gz
rust-21903532eee96a5311d08b8a9e9cc9f9231bc478.zip
Build the slice directly in array_chunks_mut
Review discussion found that the concern about aliasing was overblown,
so we can simplify this to cast from one slice to another directly.
-rw-r--r--library/core/src/slice/mod.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index 18ff50b8dbd..a32ea062de4 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -1067,14 +1067,11 @@ impl<T> [T] {
     pub fn array_chunks_mut<const N: usize>(&mut self) -> ArrayChunksMut<'_, T, N> {
         assert_ne!(N, 0);
         let len = self.len() / N;
-        let (fst_ptr, snd) = {
-            // Scope the first slice into a pointer to avoid aliasing the new slice below.
-            let (fst, snd) = self.split_at_mut(len * N);
-            (fst.as_mut_ptr(), snd)
-        };
+        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_ptr.cast(), len) };
+        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 }
     }