Skip to content

Commit

Permalink
Move ArrayChunksMut::get_unchecked per rust-lang#73565
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Sep 5, 2020
1 parent 2190353 commit 86b9f71
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 86b9f71

Please sign in to comment.