@@ -2341,17 +2341,21 @@ impl<T: ?Sized> Unique<T> {
2341
2341
///
2342
2342
/// `ptr` must be non-null.
2343
2343
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2344
- Unique { pointer : NonZero :: new_unchecked ( ptr) , _marker : PhantomData }
2344
+ Unique { pointer : NonZero ( ptr as _ ) , _marker : PhantomData }
2345
2345
}
2346
2346
2347
2347
/// Creates a new `Unique` if `ptr` is non-null.
2348
2348
pub fn new ( ptr : * mut T ) -> Option < Self > {
2349
- NonZero :: new ( ptr as * const T ) . map ( |nz| Unique { pointer : nz, _marker : PhantomData } )
2349
+ if !ptr. is_null ( ) {
2350
+ Some ( Unique { pointer : NonZero ( ptr as _ ) , _marker : PhantomData } )
2351
+ } else {
2352
+ None
2353
+ }
2350
2354
}
2351
2355
2352
2356
/// Acquires the underlying `*mut` pointer.
2353
2357
pub fn as_ptr ( self ) -> * mut T {
2354
- self . pointer . get ( ) as * mut T
2358
+ self . pointer . 0 as * mut T
2355
2359
}
2356
2360
2357
2361
/// Dereferences the content.
@@ -2397,15 +2401,15 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
2397
2401
#[ allow( deprecated) ]
2398
2402
impl < ' a , T : ?Sized > From < & ' a mut T > for Unique < T > {
2399
2403
fn from ( reference : & ' a mut T ) -> Self {
2400
- Unique { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2404
+ Unique { pointer : NonZero ( reference as _ ) , _marker : PhantomData }
2401
2405
}
2402
2406
}
2403
2407
2404
2408
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2405
2409
#[ allow( deprecated) ]
2406
2410
impl < ' a , T : ?Sized > From < & ' a T > for Unique < T > {
2407
2411
fn from ( reference : & ' a T ) -> Self {
2408
- Unique { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2412
+ Unique { pointer : NonZero ( reference as _ ) , _marker : PhantomData }
2409
2413
}
2410
2414
}
2411
2415
@@ -2476,19 +2480,23 @@ impl<T: ?Sized> NonNull<T> {
2476
2480
/// `ptr` must be non-null.
2477
2481
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2478
2482
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2479
- NonNull { pointer : NonZero :: new_unchecked ( ptr) }
2483
+ NonNull { pointer : NonZero ( ptr as _ ) }
2480
2484
}
2481
2485
2482
2486
/// Creates a new `NonNull` if `ptr` is non-null.
2483
2487
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2484
2488
pub fn new ( ptr : * mut T ) -> Option < Self > {
2485
- NonZero :: new ( ptr as * const T ) . map ( |nz| NonNull { pointer : nz } )
2489
+ if !ptr. is_null ( ) {
2490
+ Some ( NonNull { pointer : NonZero ( ptr as _ ) } )
2491
+ } else {
2492
+ None
2493
+ }
2486
2494
}
2487
2495
2488
2496
/// Acquires the underlying `*mut` pointer.
2489
2497
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2490
2498
pub fn as_ptr ( self ) -> * mut T {
2491
- self . pointer . get ( ) as * mut T
2499
+ self . pointer . 0 as * mut T
2492
2500
}
2493
2501
2494
2502
/// Dereferences the content.
@@ -2589,14 +2597,14 @@ impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
2589
2597
#[ allow( deprecated) ]
2590
2598
impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
2591
2599
fn from ( reference : & ' a mut T ) -> Self {
2592
- NonNull { pointer : NonZero :: from ( reference) }
2600
+ NonNull { pointer : NonZero ( reference as _ ) }
2593
2601
}
2594
2602
}
2595
2603
2596
2604
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2597
2605
#[ allow( deprecated) ]
2598
2606
impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
2599
2607
fn from ( reference : & ' a T ) -> Self {
2600
- NonNull { pointer : NonZero :: from ( reference) }
2608
+ NonNull { pointer : NonZero ( reference as _ ) }
2601
2609
}
2602
2610
}
0 commit comments