Skip to content

Commit 16b219a

Browse files
committed
cleanup slice iter 2
1 parent 0bd13c3 commit 16b219a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

library/core/src/slice/iter.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,19 +2495,13 @@ impl<'a, T> Iterator for RChunksMut<'a, T> {
24952495
&& end < self.v.len()
24962496
{
24972497
let end = self.v.len() - end;
2498-
let start = match end.checked_sub(self.chunk_size) {
2499-
Some(sum) => sum,
2500-
None => 0,
2501-
};
2502-
// SAFETY: This type ensures that self.v is a valid pointer with a correct len.
2503-
// Therefore the bounds check in split_at_mut guarantees the split point is inbounds.
2504-
let (head, tail) = unsafe { self.v.split_at_mut(start) };
2505-
// SAFETY: This type ensures that self.v is a valid pointer with a correct len.
2506-
// Therefore the bounds check in split_at_mut guarantees the split point is inbounds.
2507-
let (nth, _) = unsafe { tail.split_at_mut(end - start) };
2508-
self.v = head;
2498+
// SAFETY: The self.v contract ensures that any split_at_mut is valid.
2499+
let (rest, _) = unsafe { self.v.split_at_mut(end) };
2500+
// SAFETY: The self.v contract ensures that any split_at_mut is valid.
2501+
let (rest, chunk) = unsafe { rest.split_at_mut(end.saturating_sub(self.chunk_size)) };
2502+
self.v = rest;
25092503
// SAFETY: Nothing else points to or will point to the contents of this slice.
2510-
Some(unsafe { &mut *nth })
2504+
Some(unsafe { &mut *chunk })
25112505
} else {
25122506
self.v = &mut [];
25132507
None

0 commit comments

Comments
 (0)