@@ -23,7 +23,7 @@ use fmt;
23
23
use hash;
24
24
use marker:: { PhantomData , Unsize } ;
25
25
use mem;
26
- use nonzero:: NonZero ;
26
+ # [ allow ( deprecated ) ] use nonzero:: NonZero ;
27
27
28
28
use cmp:: Ordering :: { self , Less , Equal , Greater } ;
29
29
@@ -2285,6 +2285,7 @@ impl<T: ?Sized> PartialOrd for *mut T {
2285
2285
#[ unstable( feature = "ptr_internals" , issue = "0" ,
2286
2286
reason = "use NonNull instead and consider PhantomData<T> \
2287
2287
(if you also use #[may_dangle]), Send, and/or Sync") ]
2288
+ #[ allow( deprecated) ]
2288
2289
pub struct Unique < T : ?Sized > {
2289
2290
pointer : NonZero < * const T > ,
2290
2291
// NOTE: this marker has no consequences for variance, but is necessary
@@ -2332,24 +2333,29 @@ impl<T: Sized> Unique<T> {
2332
2333
}
2333
2334
2334
2335
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2336
+ #[ allow( deprecated) ]
2335
2337
impl < T : ?Sized > Unique < T > {
2336
2338
/// Creates a new `Unique`.
2337
2339
///
2338
2340
/// # Safety
2339
2341
///
2340
2342
/// `ptr` must be non-null.
2341
2343
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2342
- Unique { pointer : NonZero :: new_unchecked ( ptr) , _marker : PhantomData }
2344
+ Unique { pointer : NonZero ( ptr as _ ) , _marker : PhantomData }
2343
2345
}
2344
2346
2345
2347
/// Creates a new `Unique` if `ptr` is non-null.
2346
2348
pub fn new ( ptr : * mut T ) -> Option < Self > {
2347
- 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
+ }
2348
2354
}
2349
2355
2350
2356
/// Acquires the underlying `*mut` pointer.
2351
2357
pub fn as_ptr ( self ) -> * mut T {
2352
- self . pointer . get ( ) as * mut T
2358
+ self . pointer . 0 as * mut T
2353
2359
}
2354
2360
2355
2361
/// Dereferences the content.
@@ -2392,16 +2398,18 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
2392
2398
}
2393
2399
2394
2400
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2401
+ #[ allow( deprecated) ]
2395
2402
impl < ' a , T : ?Sized > From < & ' a mut T > for Unique < T > {
2396
2403
fn from ( reference : & ' a mut T ) -> Self {
2397
- Unique { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2404
+ Unique { pointer : NonZero ( reference as _ ) , _marker : PhantomData }
2398
2405
}
2399
2406
}
2400
2407
2401
2408
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2409
+ #[ allow( deprecated) ]
2402
2410
impl < ' a , T : ?Sized > From < & ' a T > for Unique < T > {
2403
2411
fn from ( reference : & ' a T ) -> Self {
2404
- Unique { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2412
+ Unique { pointer : NonZero ( reference as _ ) , _marker : PhantomData }
2405
2413
}
2406
2414
}
2407
2415
@@ -2412,11 +2420,6 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
2412
2420
}
2413
2421
}
2414
2422
2415
- /// Previous name of `NonNull`.
2416
- #[ rustc_deprecated( since = "1.25.0" , reason = "renamed to `NonNull`" ) ]
2417
- #[ unstable( feature = "shared" , issue = "27730" ) ]
2418
- pub type Shared < T > = NonNull < T > ;
2419
-
2420
2423
/// `*mut T` but non-zero and covariant.
2421
2424
///
2422
2425
/// This is often the correct thing to use when building data structures using
@@ -2436,7 +2439,7 @@ pub type Shared<T> = NonNull<T>;
2436
2439
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
2437
2440
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2438
2441
pub struct NonNull < T : ?Sized > {
2439
- pointer : NonZero < * const T > ,
2442
+ # [ allow ( deprecated ) ] pointer : NonZero < * const T > ,
2440
2443
}
2441
2444
2442
2445
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
@@ -2463,6 +2466,7 @@ impl<T: Sized> NonNull<T> {
2463
2466
}
2464
2467
}
2465
2468
2469
+ #[ allow( deprecated) ]
2466
2470
impl < T : ?Sized > NonNull < T > {
2467
2471
/// Creates a new `NonNull`.
2468
2472
///
@@ -2471,19 +2475,23 @@ impl<T: ?Sized> NonNull<T> {
2471
2475
/// `ptr` must be non-null.
2472
2476
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2473
2477
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2474
- NonNull { pointer : NonZero :: new_unchecked ( ptr) }
2478
+ NonNull { pointer : NonZero ( ptr as _ ) }
2475
2479
}
2476
2480
2477
2481
/// Creates a new `NonNull` if `ptr` is non-null.
2478
2482
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2479
2483
pub fn new ( ptr : * mut T ) -> Option < Self > {
2480
- NonZero :: new ( ptr as * const T ) . map ( |nz| NonNull { pointer : nz } )
2484
+ if !ptr. is_null ( ) {
2485
+ Some ( NonNull { pointer : NonZero ( ptr as _ ) } )
2486
+ } else {
2487
+ None
2488
+ }
2481
2489
}
2482
2490
2483
2491
/// Acquires the underlying `*mut` pointer.
2484
2492
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2485
2493
pub fn as_ptr ( self ) -> * mut T {
2486
- self . pointer . get ( ) as * mut T
2494
+ self . pointer . 0 as * mut T
2487
2495
}
2488
2496
2489
2497
/// Dereferences the content.
@@ -2581,15 +2589,17 @@ impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
2581
2589
}
2582
2590
2583
2591
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2592
+ #[ allow( deprecated) ]
2584
2593
impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
2585
2594
fn from ( reference : & ' a mut T ) -> Self {
2586
- NonNull { pointer : NonZero :: from ( reference) }
2595
+ NonNull { pointer : NonZero ( reference as _ ) }
2587
2596
}
2588
2597
}
2589
2598
2590
2599
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2600
+ #[ allow( deprecated) ]
2591
2601
impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
2592
2602
fn from ( reference : & ' a T ) -> Self {
2593
- NonNull { pointer : NonZero :: from ( reference) }
2603
+ NonNull { pointer : NonZero ( reference as _ ) }
2594
2604
}
2595
2605
}
0 commit comments