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 6666 fn next ( & mut self ) -> Option < T > {
6767 while self . idx < self . end {
6868 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.
7078 let cur = unsafe { & mut * self . vec . as_mut_ptr ( ) . add ( i) } ;
7179 let drained = ( self . pred ) ( cur) ;
7280 // Update the index *after* the predicate is called. If the index
You can’t perform that action at this time.
0 commit comments