8383 //
8484 // Note: we can't use `vec.get_mut(i).unwrap()` here since the precondition for that
8585 // function is that i < vec.len, but we've set vec's length to zero.
86- let idx = self . vec . to_physical_idx ( i) ;
87- let cur = unsafe { & mut * self . vec . ptr ( ) . add ( idx) } ;
86+ let idx = self . vec . to_wrapped_index ( i) ;
87+ let cur = unsafe { & mut * self . vec . ptr ( ) . add ( idx. as_index ( ) ) } ;
8888 let drained = ( self . pred ) ( cur) ;
8989 // Update the index *after* the predicate is called. If the index
9090 // is updated prior and the predicate panics, the element at this
9595 // SAFETY: We never touch this element again after returning it.
9696 return Some ( unsafe { ptr:: read ( cur) } ) ;
9797 } else if self . del > 0 {
98- let hole_slot = self . vec . to_physical_idx ( i - self . del ) ;
98+ let hole_slot = self . vec . to_wrapped_index ( i - self . del ) ;
9999 // SAFETY: `self.del` > 0, so the hole slot must not overlap with current element.
100100 // We use copy for move, and never touch this element again.
101101 unsafe { self . vec . wrap_copy ( idx, hole_slot, 1 ) } ;
@@ -113,8 +113,8 @@ where
113113impl < T , F , A : Allocator > Drop for ExtractIf < ' _ , T , F , A > {
114114 fn drop ( & mut self ) {
115115 if self . del > 0 {
116- let src = self . vec . to_physical_idx ( self . idx ) ;
117- let dst = self . vec . to_physical_idx ( self . idx - self . del ) ;
116+ let src = self . vec . to_wrapped_index ( self . idx ) ;
117+ let dst = self . vec . to_wrapped_index ( self . idx - self . del ) ;
118118 let len = self . old_len - self . idx ;
119119 // SAFETY: Trailing unchecked items must be valid since we never touch them.
120120 unsafe { self . vec . wrap_copy ( src, dst, len) } ;
@@ -131,7 +131,7 @@ where
131131{
132132 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
133133 let peek = if self . idx < self . end {
134- let idx = self . vec . to_physical_idx ( self . idx ) ;
134+ let idx = self . vec . to_wrapped_index ( self . idx ) ;
135135 // This has to use pointer arithmetic as `self.vec[self.idx]` or
136136 // `self.vec.get_unchecked(self.idx)` wouldn't work since we
137137 // temporarily set the length of `self.vec` to zero.
@@ -141,7 +141,7 @@ where
141141 // smaller than `self.old_len`, `idx` is valid for indexing the
142142 // buffer. Also, per the invariant of `self.idx`, this element
143143 // has not been inspected/moved out yet.
144- Some ( unsafe { & * self . vec . ptr ( ) . add ( idx) } )
144+ Some ( unsafe { & * self . vec . ptr ( ) . add ( idx. as_index ( ) ) } )
145145 } else {
146146 None
147147 } ;
0 commit comments