@@ -161,7 +161,7 @@ use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
161
161
use core:: marker:: PhantomData ;
162
162
use core:: mem:: { self , ManuallyDrop , SizedTypeProperties } ;
163
163
use core:: num:: NonZero ;
164
- use core:: ptr:: { self , NonNull } ;
164
+ use core:: ptr;
165
165
166
166
use super :: { InPlaceDrop , InPlaceDstDataSrcBufDrop , SpecFromIter , SpecFromIterNested , Vec } ;
167
167
@@ -254,28 +254,30 @@ where
254
254
let ( src_buf, src_ptr, src_cap, mut dst_buf, dst_end, dst_cap) = unsafe {
255
255
let inner = iterator. as_inner ( ) . as_into_iter ( ) ;
256
256
(
257
- inner. buf . as_ptr ( ) ,
257
+ inner. buf ,
258
258
inner. ptr ,
259
259
inner. cap ,
260
- inner. buf . as_ptr ( ) as * mut T ,
260
+ inner. buf . cast :: < T > ( ) ,
261
261
inner. end as * const T ,
262
262
inner. cap * mem:: size_of :: < I :: Src > ( ) / mem:: size_of :: < T > ( ) ,
263
263
)
264
264
} ;
265
265
266
266
// SAFETY: `dst_buf` and `dst_end` are the start and end of the buffer.
267
- let len = unsafe { SpecInPlaceCollect :: collect_in_place ( & mut iterator, dst_buf, dst_end) } ;
267
+ let len = unsafe {
268
+ SpecInPlaceCollect :: collect_in_place ( & mut iterator, dst_buf. as_ptr ( ) as * mut T , dst_end)
269
+ } ;
268
270
269
271
let src = unsafe { iterator. as_inner ( ) . as_into_iter ( ) } ;
270
272
// check if SourceIter contract was upheld
271
273
// caveat: if they weren't we might not even make it to this point
272
- debug_assert_eq ! ( src_buf, src. buf. as_ptr ( ) ) ;
274
+ debug_assert_eq ! ( src_buf, src. buf) ;
273
275
// check InPlaceIterable contract. This is only possible if the iterator advanced the
274
276
// source pointer at all. If it uses unchecked access via TrustedRandomAccess
275
277
// then the source pointer will stay in its initial position and we can't use it as reference
276
278
if src. ptr != src_ptr {
277
279
debug_assert ! (
278
- unsafe { dst_buf. add( len) as * const _ } <= src. ptr. as_ptr ( ) ,
280
+ unsafe { dst_buf. add( len) . cast ( ) } <= src. ptr,
279
281
"InPlaceIterable contract violation, write pointer advanced beyond read pointer"
280
282
) ;
281
283
}
@@ -315,18 +317,17 @@ where
315
317
let dst_size = mem:: size_of :: < T > ( ) . unchecked_mul ( dst_cap) ;
316
318
let new_layout = Layout :: from_size_align_unchecked ( dst_size, dst_align) ;
317
319
318
- let result =
319
- alloc. shrink ( NonNull :: new_unchecked ( dst_buf as * mut u8 ) , old_layout, new_layout) ;
320
+ let result = alloc. shrink ( dst_buf. cast ( ) , old_layout, new_layout) ;
320
321
let Ok ( reallocated) = result else { handle_alloc_error ( new_layout) } ;
321
- dst_buf = reallocated. as_ptr ( ) as * mut T ;
322
+ dst_buf = reallocated. cast :: < T > ( ) ;
322
323
}
323
324
} else {
324
325
debug_assert_eq ! ( src_cap * mem:: size_of:: <I :: Src >( ) , dst_cap * mem:: size_of:: <T >( ) ) ;
325
326
}
326
327
327
328
mem:: forget ( dst_guard) ;
328
329
329
- let vec = unsafe { Vec :: from_raw_parts ( dst_buf, len, dst_cap) } ;
330
+ let vec = unsafe { Vec :: from_nonnull ( dst_buf, len, dst_cap) } ;
330
331
331
332
vec
332
333
}
0 commit comments