Skip to content

Commit 7662528

Browse files
committed
Clarify unused_as_mut_slices
1 parent ae0f254 commit 7662528

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/liballoc/collections/vec_deque.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,14 @@ impl<T> VecDeque<T> {
208208
let head = self.head;
209209
let tail = self.tail;
210210
let buf = self.buffer_as_mut_slice();
211-
if head == tail {
211+
if head != tail {
212+
// In buf, head..tail contains the VecDeque and tail..head is unused.
213+
// So calling `ring_slices` with tail and head swapped returns unused slices.
214+
RingSlices::ring_slices(buf, tail, head)
215+
} else {
216+
// Swapping doesn't help when head == tail.
212217
let (before, after) = buf.split_at_mut(head);
213218
(after, before)
214-
} else {
215-
RingSlices::ring_slices(buf, tail, head)
216219
}
217220
}
218221

0 commit comments

Comments
 (0)