@@ -52,21 +52,22 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
52
52
}
53
53
}
54
54
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`.
57
57
unsafe fn as_slices ( & self ) -> ( * mut [ T ] , * mut [ T ] ) {
58
58
unsafe {
59
59
let deque = self . deque . as_ref ( ) ;
60
60
61
- let start = self . idx ;
62
61
// 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 ;
64
63
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
66
66
// haven't been drained yet, so they're all initialized,
67
67
// and `slice::range(start..end, end) == start..end`,
68
68
// 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 ) ;
70
71
( deque. buffer_range ( a_range) , deque. buffer_range ( b_range) )
71
72
}
72
73
}
0 commit comments