File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2985,8 +2985,14 @@ impl<T> Iterator for IntoIter<T> {
2985
2985
where
2986
2986
Self : TrustedRandomAccess ,
2987
2987
{
2988
- // SAFETY: the caller must uphold the contract for
2989
- // `Iterator::get_unchecked`.
2988
+ // SAFETY: the caller must guarantee that `i` is in bounds of the
2989
+ // `Vec<T>`, so `i` cannot overflow an `isize`, and the `self.ptr.add(i)`
2990
+ // is guaranteed to pointer to an element of the `Vec<T>` and
2991
+ // thus guaranteed to be valid to dereference.
2992
+ //
2993
+ // Also note the implementation of `Self: TrustedRandomAccess` requires
2994
+ // that `T: Copy` so reading elements from the buffer doesn't invalidate
2995
+ // them for `Drop`.
2990
2996
unsafe {
2991
2997
if mem:: size_of :: < T > ( ) == 0 { mem:: zeroed ( ) } else { ptr:: read ( self . ptr . add ( i) ) }
2992
2998
}
You can’t perform that action at this time.
0 commit comments