about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorMarkus Everling <markuseverling@gmail.com>2023-02-20 23:25:26 +0100
committerMarkus Everling <markuseverling@gmail.com>2023-02-20 23:25:26 +0100
commitacc876e42fce0dc3d6596f754dcfbc0ce07cabd6 (patch)
tree3614012db83ebf4333be412aa95af93feb1a0c24 /library/alloc/src
parent1e114a88bde098d1c057161aa252fa75d5739592 (diff)
downloadrust-acc876e42fce0dc3d6596f754dcfbc0ce07cabd6.tar.gz
rust-acc876e42fce0dc3d6596f754dcfbc0ce07cabd6.zip
Changes according to review
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/collections/vec_deque/drain.rs13
-rw-r--r--library/alloc/src/collections/vec_deque/mod.rs9
2 files changed, 11 insertions, 11 deletions
diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs
index 99bd7902e69..0be274a3822 100644
--- a/library/alloc/src/collections/vec_deque/drain.rs
+++ b/library/alloc/src/collections/vec_deque/drain.rs
@@ -52,21 +52,22 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
         }
     }
 
-    // Only returns pointers to the slices, as that's
-    // all we need to drop them. May only be called if `self.remaining != 0`.
+    // Only returns pointers to the slices, as that's all we need
+    // to drop them. May only be called if `self.remaining != 0`.
     unsafe fn as_slices(&self) -> (*mut [T], *mut [T]) {
         unsafe {
             let deque = self.deque.as_ref();
 
-            let start = self.idx;
             // We know that `self.idx + self.remaining <= deque.len <= usize::MAX`, so this won't overflow.
-            let end = start + self.remaining;
+            let logical_remaining_range = self.idx..self.idx + self.remaining;
 
-            // SAFETY: `start..end` represents the range of elements that
+            // SAFETY: `logical_remaining_range` represents the
+            // range into the logical buffer of elements that
             // haven't been drained yet, so they're all initialized,
             // and `slice::range(start..end, end) == start..end`,
             // so the preconditions for `slice_ranges` are met.
-            let (a_range, b_range) = deque.slice_ranges(start..end, end);
+            let (a_range, b_range) =
+                deque.slice_ranges(logical_remaining_range.clone(), logical_remaining_range.end);
             (deque.buffer_range(a_range), deque.buffer_range(b_range))
         }
     }
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs
index 813430ae615..40f31f1a194 100644
--- a/library/alloc/src/collections/vec_deque/mod.rs
+++ b/library/alloc/src/collections/vec_deque/mod.rs
@@ -1230,10 +1230,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
     /// # Safety
     ///
     /// This function is always safe to call. For the resulting ranges to be valid
-    /// ranges into the physical buffer, the caller must ensure that for all possible
-    /// values of `range` and `len`, the result of calling `slice::range(range, ..len)`
-    /// represents a valid range into the logical buffer, and that all elements
-    /// in that range are initialized.
+    /// ranges into the physical buffer, the caller must ensure that the result of
+    /// calling `slice::range(range, ..len)` represents a valid range into the
+    /// logical buffer, and that all elements in that range are initialized.
     fn slice_ranges<R>(&self, range: R, len: usize) -> (Range<usize>, Range<usize>)
     where
         R: RangeBounds<usize>,
@@ -1244,7 +1243,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
         if len == 0 {
             (0..0, 0..0)
         } else {
-            // `slice::range` guarantees that `start <= end <= self.len`.
+            // `slice::range` guarantees that `start <= end <= len`.
             // because `len != 0`, we know that `start < end`, so `start < len`
             // and the indexing is valid.
             let wrapped_start = self.to_physical_idx(start);