Skip to content

Commit acc876e

Browse files
committed
Changes according to review
1 parent 1e114a8 commit acc876e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

library/alloc/src/collections/vec_deque/drain.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -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
}

library/alloc/src/collections/vec_deque/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
12301230
/// # Safety
12311231
///
12321232
/// This function is always safe to call. For the resulting ranges to be valid
1233-
/// ranges into the physical buffer, the caller must ensure that for all possible
1234-
/// values of `range` and `len`, the result of calling `slice::range(range, ..len)`
1235-
/// represents a valid range into the logical buffer, and that all elements
1236-
/// in that range are initialized.
1233+
/// ranges into the physical buffer, the caller must ensure that the result of
1234+
/// calling `slice::range(range, ..len)` represents a valid range into the
1235+
/// logical buffer, and that all elements in that range are initialized.
12371236
fn slice_ranges<R>(&self, range: R, len: usize) -> (Range<usize>, Range<usize>)
12381237
where
12391238
R: RangeBounds<usize>,
@@ -1244,7 +1243,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
12441243
if len == 0 {
12451244
(0..0, 0..0)
12461245
} else {
1247-
// `slice::range` guarantees that `start <= end <= self.len`.
1246+
// `slice::range` guarantees that `start <= end <= len`.
12481247
// because `len != 0`, we know that `start < end`, so `start < len`
12491248
// and the indexing is valid.
12501249
let wrapped_start = self.to_physical_idx(start);

0 commit comments

Comments
 (0)