@@ -4,7 +4,6 @@ use crate::alloc::{Allocator, Global};
4
4
use crate :: raw_vec:: RawVec ;
5
5
use core:: array;
6
6
use core:: fmt;
7
- use core:: intrinsics:: arith_offset;
8
7
use core:: iter:: {
9
8
FusedIterator , InPlaceIterable , SourceIter , TrustedLen , TrustedRandomAccessNoCoerce ,
10
9
} ;
@@ -154,7 +153,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
154
153
// purposefully don't use 'ptr.offset' because for
155
154
// vectors with 0-size elements this would return the
156
155
// 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 ) ;
158
157
159
158
// Make up a value of this ZST.
160
159
Some ( unsafe { mem:: zeroed ( ) } )
@@ -184,7 +183,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
184
183
// SAFETY: due to unchecked casts of unsigned amounts to signed offsets the wraparound
185
184
// effectively results in unsigned pointers representing positions 0..usize::MAX,
186
185
// 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) ;
188
187
} else {
189
188
// SAFETY: the min() above ensures that step_size is in bounds
190
189
self . ptr = unsafe { self . ptr . add ( step_size) } ;
@@ -217,7 +216,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
217
216
return Err ( unsafe { array:: IntoIter :: new_unchecked ( raw_ary, 0 ..len) } ) ;
218
217
}
219
218
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 ) ;
221
220
// Safety: ditto
222
221
return Ok ( unsafe { MaybeUninit :: array_assume_init ( raw_ary) } ) ;
223
222
}
@@ -267,7 +266,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
267
266
None
268
267
} else if mem:: size_of :: < T > ( ) == 0 {
269
268
// 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 ) ;
271
270
272
271
// Make up a value of this ZST.
273
272
Some ( unsafe { mem:: zeroed ( ) } )
@@ -283,9 +282,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
283
282
let step_size = self . len ( ) . min ( n) ;
284
283
if mem:: size_of :: < T > ( ) == 0 {
285
284
// 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) ;
289
286
} else {
290
287
// SAFETY: same as for advance_by()
291
288
self . end = unsafe { self . end . sub ( step_size) } ;
0 commit comments