about summary refs log tree commit diff
path: root/library/alloc/src/vec.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-25 21:44:26 +0000
committerbors <bors@rust-lang.org>2020-09-25 21:44:26 +0000
commit043f6d747c15068f0053a0542e9b0f17ae7f4de4 (patch)
treeab199af58050afe1cfe5ffe44b77818faaa3ef5d /library/alloc/src/vec.rs
parentc6e4db620a7d2f569f11dcab627430921ea8aacf (diff)
parent04a0b1d0879f7872b09cd8058a15479589ccd352 (diff)
downloadrust-043f6d747c15068f0053a0542e9b0f17ae7f4de4.tar.gz
rust-043f6d747c15068f0053a0542e9b0f17ae7f4de4.zip
Auto merge of #77201 - matthewjasper:rename-get-unchecked, r=spastorino
Rename Iterator::get_unchecked

Closes #76479

r? `@pnkfelix`
Diffstat (limited to 'library/alloc/src/vec.rs')
-rw-r--r--library/alloc/src/vec.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs
index cfa89937794..fec4c1e0e50 100644
--- a/library/alloc/src/vec.rs
+++ b/library/alloc/src/vec.rs
@@ -2980,12 +2980,18 @@ impl<T> Iterator for IntoIter<T> {
         self.len()
     }
 
-    unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item
+    unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
     where
         Self: TrustedRandomAccess,
     {
-        // SAFETY: the caller must uphold the contract for
-        // `Iterator::get_unchecked`.
+        // SAFETY: the caller must guarantee that `i` is in bounds of the
+        // `Vec<T>`, so `i` cannot overflow an `isize`, and the `self.ptr.add(i)`
+        // is guaranteed to pointer to an element of the `Vec<T>` and
+        // thus guaranteed to be valid to dereference.
+        //
+        // Also note the implementation of `Self: TrustedRandomAccess` requires
+        // that `T: Copy` so reading elements from the buffer doesn't invalidate
+        // them for `Drop`.
         unsafe {
             if mem::size_of::<T>() == 0 { mem::zeroed() } else { ptr::read(self.ptr.add(i)) }
         }