@@ -4,7 +4,6 @@ use crate::alloc::{Allocator, Global};
44use crate::raw_vec::RawVec;
55use core::array;
66use core::fmt;
7- use core::intrinsics::arith_offset;
87use core::iter::{
98 FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce,
109};
@@ -154,7 +153,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
154153 // purposefully don't use 'ptr.offset' because for
155154 // vectors with 0-size elements this would return the
156155 // same pointer.
157- self.ptr = unsafe { arith_offset( self.ptr as *const i8, 1) as *mut T } ;
156+ self.ptr = self.ptr.wrapping_byte_add(1) ;
158157
159158 // Make up a value of this ZST.
160159 Some(unsafe { mem::zeroed() })
@@ -184,7 +183,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
184183 // SAFETY: due to unchecked casts of unsigned amounts to signed offsets the wraparound
185184 // effectively results in unsigned pointers representing positions 0..usize::MAX,
186185 // which is valid for ZSTs.
187- self.ptr = unsafe { arith_offset( self.ptr as *const i8, step_size as isize) as *mut T }
186+ self.ptr = self.ptr.wrapping_byte_add( step_size);
188187 } else {
189188 // SAFETY: the min() above ensures that step_size is in bounds
190189 self.ptr = unsafe { self.ptr.add(step_size) };
@@ -217,7 +216,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
217216 return Err(unsafe { array::IntoIter::new_unchecked(raw_ary, 0..len) });
218217 }
219218
220- self.ptr = unsafe { arith_offset( self.ptr as *const i8, N as isize) as *mut T } ;
219+ self.ptr = self.ptr.wrapping_byte_add(N) ;
221220 // Safety: ditto
222221 return Ok(unsafe { MaybeUninit::array_assume_init(raw_ary) });
223222 }
@@ -267,7 +266,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
267266 None
268267 } else if mem::size_of::<T>() == 0 {
269268 // See above for why 'ptr.offset' isn't used
270- self.end = unsafe { arith_offset( self.end as *const i8, -1) as *mut T } ;
269+ self.end = self.ptr.wrapping_byte_sub(1) ;
271270
272271 // Make up a value of this ZST.
273272 Some(unsafe { mem::zeroed() })
@@ -283,9 +282,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
283282 let step_size = self.len().min(n);
284283 if mem::size_of::<T>() == 0 {
285284 // SAFETY: same as for advance_by()
286- self.end = unsafe {
287- arith_offset(self.end as *const i8, step_size.wrapping_neg() as isize) as *mut T
288- }
285+ self.end = self.end.wrapping_byte_sub(step_size);
289286 } else {
290287 // SAFETY: same as for advance_by()
291288 self.end = unsafe { self.end.offset(step_size.wrapping_neg() as isize) };
0 commit comments