@@ -66,7 +66,7 @@ use std::marker::PhantomData;
66
66
use std:: mem;
67
67
use std:: mem:: MaybeUninit ;
68
68
use std:: ops;
69
- use std:: ptr;
69
+ use std:: ptr:: { self , NonNull } ;
70
70
use std:: slice:: { self , SliceIndex } ;
71
71
72
72
/// Creates a [`SmallVec`] containing the arguments.
@@ -223,7 +223,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> {
223
223
#[ cfg( feature = "union" ) ]
224
224
union SmallVecData < A : Array > {
225
225
inline : MaybeUninit < A > ,
226
- heap : ( * mut A :: Item , usize ) ,
226
+ heap : ( NonNull < A :: Item > , usize ) ,
227
227
}
228
228
229
229
#[ cfg( feature = "union" ) ]
@@ -246,37 +246,39 @@ impl<A: Array> SmallVecData<A> {
246
246
}
247
247
#[ inline]
248
248
unsafe fn heap ( & self ) -> ( * mut A :: Item , usize ) {
249
- self . heap
249
+ ( self . heap . 0 . as_ptr ( ) , self . heap . 1 )
250
250
}
251
251
#[ inline]
252
- unsafe fn heap_mut ( & mut self ) -> & mut ( * mut A :: Item , usize ) {
253
- & mut self . heap
252
+ unsafe fn heap_mut ( & mut self ) -> ( * mut A :: Item , & mut usize ) {
253
+ ( self . heap . 0 . as_ptr ( ) , & mut self . heap . 1 )
254
254
}
255
255
#[ inline]
256
256
fn from_heap ( ptr : * mut A :: Item , len : usize ) -> SmallVecData < A > {
257
- SmallVecData { heap : ( ptr, len) }
257
+ SmallVecData {
258
+ heap : ( NonNull :: new ( ptr) . unwrap ( ) , len) ,
259
+ }
258
260
}
259
261
}
260
262
261
263
#[ cfg( not( feature = "union" ) ) ]
262
264
enum SmallVecData < A : Array > {
263
265
Inline ( MaybeUninit < A > ) ,
264
- Heap ( ( * mut A :: Item , usize ) ) ,
266
+ Heap ( ( NonNull < A :: Item > , usize ) ) ,
265
267
}
266
268
267
269
#[ cfg( not( feature = "union" ) ) ]
268
270
impl < A : Array > SmallVecData < A > {
269
271
#[ inline]
270
272
unsafe fn inline ( & self ) -> * const A :: Item {
271
- match * self {
272
- SmallVecData :: Inline ( ref a) => a. as_ptr ( ) as * const A :: Item ,
273
+ match self {
274
+ SmallVecData :: Inline ( a) => a. as_ptr ( ) as * const A :: Item ,
273
275
_ => debug_unreachable ! ( ) ,
274
276
}
275
277
}
276
278
#[ inline]
277
279
unsafe fn inline_mut ( & mut self ) -> * mut A :: Item {
278
- match * self {
279
- SmallVecData :: Inline ( ref mut a) => a. as_mut_ptr ( ) as * mut A :: Item ,
280
+ match self {
281
+ SmallVecData :: Inline ( a) => a. as_mut_ptr ( ) as * mut A :: Item ,
280
282
_ => debug_unreachable ! ( ) ,
281
283
}
282
284
}
@@ -293,21 +295,21 @@ impl<A: Array> SmallVecData<A> {
293
295
}
294
296
#[ inline]
295
297
unsafe fn heap ( & self ) -> ( * mut A :: Item , usize ) {
296
- match * self {
297
- SmallVecData :: Heap ( data) => data,
298
+ match self {
299
+ SmallVecData :: Heap ( data) => ( data. 0 . as_ptr ( ) , data . 1 ) ,
298
300
_ => debug_unreachable ! ( ) ,
299
301
}
300
302
}
301
303
#[ inline]
302
- unsafe fn heap_mut ( & mut self ) -> & mut ( * mut A :: Item , usize ) {
303
- match * self {
304
- SmallVecData :: Heap ( ref mut data) => data,
304
+ unsafe fn heap_mut ( & mut self ) -> ( * mut A :: Item , & mut usize ) {
305
+ match self {
306
+ SmallVecData :: Heap ( data) => ( data. 0 . as_ptr ( ) , & mut data . 1 ) ,
305
307
_ => debug_unreachable ! ( ) ,
306
308
}
307
309
}
308
310
#[ inline]
309
311
fn from_heap ( ptr : * mut A :: Item , len : usize ) -> SmallVecData < A > {
310
- SmallVecData :: Heap ( ( ptr, len) )
312
+ SmallVecData :: Heap ( ( NonNull :: new ( ptr) . unwrap ( ) , len) )
311
313
}
312
314
}
313
315
@@ -534,7 +536,7 @@ impl<A: Array> SmallVec<A> {
534
536
fn triple_mut ( & mut self ) -> ( * mut A :: Item , & mut usize , usize ) {
535
537
unsafe {
536
538
if self . spilled ( ) {
537
- let & mut ( ptr, ref mut len_ptr) = self . data . heap_mut ( ) ;
539
+ let ( ptr, len_ptr) = self . data . heap_mut ( ) ;
538
540
( ptr, len_ptr, self . capacity )
539
541
} else {
540
542
( self . data . inline_mut ( ) , & mut self . capacity , A :: size ( ) )
0 commit comments