@@ -2481,13 +2481,12 @@ pub type Shared<T> = NonNull<T>;
2481
2481
/// Usually this won't be necessary; covariance is correct for most safe abstractions,
2482
2482
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
2483
2483
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
2484
- #[ unstable( feature = "shared" , reason = "needs an RFC to flesh out design" ,
2485
- issue = "27730" ) ]
2484
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2486
2485
pub struct NonNull < T : ?Sized > {
2487
2486
pointer : NonZero < * const T > ,
2488
2487
}
2489
2488
2490
- #[ unstable ( feature = "shared " , issue = "27730 " ) ]
2489
+ #[ stable ( feature = "nonnull " , since = "1.24.0 " ) ]
2491
2490
impl < T : ?Sized > fmt:: Debug for NonNull < T > {
2492
2491
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2493
2492
write ! ( f, "{:p}" , self . as_ptr( ) )
@@ -2496,20 +2495,20 @@ impl<T: ?Sized> fmt::Debug for NonNull<T> {
2496
2495
2497
2496
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
2498
2497
// NB: This impl is unnecessary, but should provide better error messages.
2499
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2498
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2500
2499
impl < T : ?Sized > !Send for NonNull < T > { }
2501
2500
2502
2501
/// `NonNull` pointers are not `Sync` because the data they reference may be aliased.
2503
2502
// NB: This impl is unnecessary, but should provide better error messages.
2504
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2503
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2505
2504
impl < T : ?Sized > !Sync for NonNull < T > { }
2506
2505
2507
- #[ unstable( feature = "nonnull" , issue = "27730" ) ]
2508
2506
impl < T : Sized > NonNull < T > {
2509
2507
/// Creates a new `NonNull` that is dangling, but well-aligned.
2510
2508
///
2511
2509
/// This is useful for initializing types which lazily allocate, like
2512
2510
/// `Vec::new` does.
2511
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2513
2512
pub fn empty ( ) -> Self {
2514
2513
unsafe {
2515
2514
let ptr = mem:: align_of :: < T > ( ) as * mut T ;
@@ -2518,24 +2517,25 @@ impl<T: Sized> NonNull<T> {
2518
2517
}
2519
2518
}
2520
2519
2521
- #[ unstable( feature = "nonnull" , issue = "27730" ) ]
2522
2520
impl < T : ?Sized > NonNull < T > {
2523
2521
/// Creates a new `NonNull`.
2524
2522
///
2525
2523
/// # Safety
2526
2524
///
2527
2525
/// `ptr` must be non-null.
2528
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2526
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2529
2527
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2530
2528
NonNull { pointer : NonZero :: new_unchecked ( ptr) }
2531
2529
}
2532
2530
2533
2531
/// Creates a new `NonNull` if `ptr` is non-null.
2532
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2534
2533
pub fn new ( ptr : * mut T ) -> Option < Self > {
2535
2534
NonZero :: new ( ptr as * const T ) . map ( |nz| NonNull { pointer : nz } )
2536
2535
}
2537
2536
2538
2537
/// Acquires the underlying `*mut` pointer.
2538
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2539
2539
pub fn as_ptr ( self ) -> * mut T {
2540
2540
self . pointer . get ( ) as * mut T
2541
2541
}
@@ -2545,6 +2545,7 @@ impl<T: ?Sized> NonNull<T> {
2545
2545
/// The resulting lifetime is bound to self so this behaves "as if"
2546
2546
/// it were actually an instance of T that is getting borrowed. If a longer
2547
2547
/// (unbound) lifetime is needed, use `&*my_ptr.ptr()`.
2548
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2548
2549
pub unsafe fn as_ref ( & self ) -> & T {
2549
2550
& * self . as_ptr ( )
2550
2551
}
@@ -2554,46 +2555,47 @@ impl<T: ?Sized> NonNull<T> {
2554
2555
/// The resulting lifetime is bound to self so this behaves "as if"
2555
2556
/// it were actually an instance of T that is getting borrowed. If a longer
2556
2557
/// (unbound) lifetime is needed, use `&mut *my_ptr.ptr_mut()`.
2558
+ #[ stable( feature = "nonnull" , since = "1.24.0" ) ]
2557
2559
pub unsafe fn as_mut ( & mut self ) -> & mut T {
2558
2560
& mut * self . as_ptr ( )
2559
2561
}
2560
2562
}
2561
2563
2562
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2564
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2563
2565
impl < T : ?Sized > Clone for NonNull < T > {
2564
2566
fn clone ( & self ) -> Self {
2565
2567
* self
2566
2568
}
2567
2569
}
2568
2570
2569
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2571
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2570
2572
impl < T : ?Sized > Copy for NonNull < T > { }
2571
2573
2572
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2574
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2573
2575
impl < T : ?Sized , U : ?Sized > CoerceUnsized < NonNull < U > > for NonNull < T > where T : Unsize < U > { }
2574
2576
2575
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2577
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2576
2578
impl < T : ?Sized > fmt:: Pointer for NonNull < T > {
2577
2579
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2578
2580
fmt:: Pointer :: fmt ( & self . as_ptr ( ) , f)
2579
2581
}
2580
2582
}
2581
2583
2582
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2584
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2583
2585
impl < T : ?Sized > From < Unique < T > > for NonNull < T > {
2584
2586
fn from ( unique : Unique < T > ) -> Self {
2585
2587
NonNull { pointer : unique. pointer }
2586
2588
}
2587
2589
}
2588
2590
2589
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2591
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2590
2592
impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
2591
2593
fn from ( reference : & ' a mut T ) -> Self {
2592
2594
NonNull { pointer : NonZero :: from ( reference) }
2593
2595
}
2594
2596
}
2595
2597
2596
- #[ unstable ( feature = "nonnull" , issue = "27730 " ) ]
2598
+ #[ stable ( feature = "nonnull" , since = "1.24.0 " ) ]
2597
2599
impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
2598
2600
fn from ( reference : & ' a T ) -> Self {
2599
2601
NonNull { pointer : NonZero :: from ( reference) }
0 commit comments