@@ -52,21 +52,22 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
5252 }
5353 }
5454
55- // Only returns pointers to the slices, as that's
56- // all we need to drop them. May only be called if `self.remaining != 0`.
55+ // Only returns pointers to the slices, as that's all we need
56+ // to drop them. May only be called if `self.remaining != 0`.
5757 unsafe fn as_slices ( & self ) -> ( * mut [ T ] , * mut [ T ] ) {
5858 unsafe {
5959 let deque = self . deque . as_ref ( ) ;
6060
61- let start = self . idx ;
6261 // We know that `self.idx + self.remaining <= deque.len <= usize::MAX`, so this won't overflow.
63- let end = start + self . remaining ;
62+ let logical_remaining_range = self . idx .. self . idx + self . remaining ;
6463
65- // SAFETY: `start..end` represents the range of elements that
64+ // SAFETY: `logical_remaining_range` represents the
65+ // range into the logical buffer of elements that
6666 // haven't been drained yet, so they're all initialized,
6767 // and `slice::range(start..end, end) == start..end`,
6868 // so the preconditions for `slice_ranges` are met.
69- let ( a_range, b_range) = deque. slice_ranges ( start..end, end) ;
69+ let ( a_range, b_range) =
70+ deque. slice_ranges ( logical_remaining_range. clone ( ) , logical_remaining_range. end ) ;
7071 ( deque. buffer_range ( a_range) , deque. buffer_range ( b_range) )
7172 }
7273 }
0 commit comments