File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 66
66
fn next ( & mut self ) -> Option < T > {
67
67
while self . idx < self . end {
68
68
let i = self . idx ;
69
- // SAFETY: Unchecked element must be valid.
69
+ // SAFETY:
70
+ // We know that `i < self.end` from the if guard and that `self.end <= self.old_len` from
71
+ // the validity of `Self`. Therefore `i` points to an element within `vec`.
72
+ //
73
+ // Additionally, the i-th element is valid because each element is visited at most once
74
+ // and it is the first time we access vec[i].
75
+ //
76
+ // Note: we can't use `vec.get_unchecked_mut(i)` here since the precondition for that
77
+ // function is that i < vec.len(), but we've set vec's length to zero.
70
78
let cur = unsafe { & mut * self . vec . as_mut_ptr ( ) . add ( i) } ;
71
79
let drained = ( self . pred ) ( cur) ;
72
80
// Update the index *after* the predicate is called. If the index
You can’t perform that action at this time.
0 commit comments