Skip to content

Commit 55c50cd

Browse files
committed
Stabilize std::ptr::NonNull
1 parent 2d51e74 commit 55c50cd

File tree

8 files changed

+20
-30
lines changed

8 files changed

+20
-30
lines changed

src/liballoc/boxed.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,13 @@ impl<T: ?Sized> Box<T> {
288288
/// # Examples
289289
///
290290
/// ```
291-
/// #![feature(nonnull)]
292-
///
293291
/// fn main() {
294292
/// let x = Box::new(5);
295293
/// let ptr = Box::into_nonnull_raw(x);
296294
/// let x = unsafe { Box::from_nonnull_raw(ptr) };
297295
/// }
298296
/// ```
299-
#[unstable(feature = "nonnull", reason = "needs an RFC to flesh out design",
300-
issue = "27730")]
297+
#[stable(feature = "nonnull", since = "1.24.0")]
301298
#[inline]
302299
pub unsafe fn from_nonnull_raw(u: NonNull<T>) -> Self {
303300
Box(u.into())
@@ -352,15 +349,12 @@ impl<T: ?Sized> Box<T> {
352349
/// # Examples
353350
///
354351
/// ```
355-
/// #![feature(nonnull)]
356-
///
357352
/// fn main() {
358353
/// let x = Box::new(5);
359354
/// let ptr = Box::into_nonnull_raw(x);
360355
/// }
361356
/// ```
362-
#[unstable(feature = "nonnull", reason = "needs an RFC to flesh out design",
363-
issue = "27730")]
357+
#[stable(feature = "nonnull", since = "1.24.0")]
364358
#[inline]
365359
pub fn into_nonnull_raw(b: Box<T>) -> NonNull<T> {
366360
Box::into_unique(b).into()

src/liballoc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
#![feature(iter_rfold)]
104104
#![feature(lang_items)]
105105
#![feature(needs_allocator)]
106-
#![feature(nonnull)]
107106
#![feature(nonzero)]
108107
#![feature(offset_to)]
109108
#![feature(optin_builtin_traits)]

src/libcore/ptr.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,13 +2481,12 @@ pub type Shared<T> = NonNull<T>;
24812481
/// Usually this won't be necessary; covariance is correct for most safe abstractions,
24822482
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
24832483
/// 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")]
24862485
pub struct NonNull<T: ?Sized> {
24872486
pointer: NonZero<*const T>,
24882487
}
24892488

2490-
#[unstable(feature = "shared", issue = "27730")]
2489+
#[stable(feature = "nonnull", since = "1.24.0")]
24912490
impl<T: ?Sized> fmt::Debug for NonNull<T> {
24922491
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24932492
write!(f, "{:p}", self.as_ptr())
@@ -2496,20 +2495,20 @@ impl<T: ?Sized> fmt::Debug for NonNull<T> {
24962495

24972496
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
24982497
// 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")]
25002499
impl<T: ?Sized> !Send for NonNull<T> { }
25012500

25022501
/// `NonNull` pointers are not `Sync` because the data they reference may be aliased.
25032502
// 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")]
25052504
impl<T: ?Sized> !Sync for NonNull<T> { }
25062505

2507-
#[unstable(feature = "nonnull", issue = "27730")]
25082506
impl<T: Sized> NonNull<T> {
25092507
/// Creates a new `NonNull` that is dangling, but well-aligned.
25102508
///
25112509
/// This is useful for initializing types which lazily allocate, like
25122510
/// `Vec::new` does.
2511+
#[stable(feature = "nonnull", since = "1.24.0")]
25132512
pub fn empty() -> Self {
25142513
unsafe {
25152514
let ptr = mem::align_of::<T>() as *mut T;
@@ -2518,24 +2517,25 @@ impl<T: Sized> NonNull<T> {
25182517
}
25192518
}
25202519

2521-
#[unstable(feature = "nonnull", issue = "27730")]
25222520
impl<T: ?Sized> NonNull<T> {
25232521
/// Creates a new `NonNull`.
25242522
///
25252523
/// # Safety
25262524
///
25272525
/// `ptr` must be non-null.
2528-
#[unstable(feature = "nonnull", issue = "27730")]
2526+
#[stable(feature = "nonnull", since = "1.24.0")]
25292527
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
25302528
NonNull { pointer: NonZero::new_unchecked(ptr) }
25312529
}
25322530

25332531
/// Creates a new `NonNull` if `ptr` is non-null.
2532+
#[stable(feature = "nonnull", since = "1.24.0")]
25342533
pub fn new(ptr: *mut T) -> Option<Self> {
25352534
NonZero::new(ptr as *const T).map(|nz| NonNull { pointer: nz })
25362535
}
25372536

25382537
/// Acquires the underlying `*mut` pointer.
2538+
#[stable(feature = "nonnull", since = "1.24.0")]
25392539
pub fn as_ptr(self) -> *mut T {
25402540
self.pointer.get() as *mut T
25412541
}
@@ -2545,6 +2545,7 @@ impl<T: ?Sized> NonNull<T> {
25452545
/// The resulting lifetime is bound to self so this behaves "as if"
25462546
/// it were actually an instance of T that is getting borrowed. If a longer
25472547
/// (unbound) lifetime is needed, use `&*my_ptr.ptr()`.
2548+
#[stable(feature = "nonnull", since = "1.24.0")]
25482549
pub unsafe fn as_ref(&self) -> &T {
25492550
&*self.as_ptr()
25502551
}
@@ -2554,46 +2555,47 @@ impl<T: ?Sized> NonNull<T> {
25542555
/// The resulting lifetime is bound to self so this behaves "as if"
25552556
/// it were actually an instance of T that is getting borrowed. If a longer
25562557
/// (unbound) lifetime is needed, use `&mut *my_ptr.ptr_mut()`.
2558+
#[stable(feature = "nonnull", since = "1.24.0")]
25572559
pub unsafe fn as_mut(&mut self) -> &mut T {
25582560
&mut *self.as_ptr()
25592561
}
25602562
}
25612563

2562-
#[unstable(feature = "nonnull", issue = "27730")]
2564+
#[stable(feature = "nonnull", since = "1.24.0")]
25632565
impl<T: ?Sized> Clone for NonNull<T> {
25642566
fn clone(&self) -> Self {
25652567
*self
25662568
}
25672569
}
25682570

2569-
#[unstable(feature = "nonnull", issue = "27730")]
2571+
#[stable(feature = "nonnull", since = "1.24.0")]
25702572
impl<T: ?Sized> Copy for NonNull<T> { }
25712573

2572-
#[unstable(feature = "nonnull", issue = "27730")]
2574+
#[stable(feature = "nonnull", since = "1.24.0")]
25732575
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> { }
25742576

2575-
#[unstable(feature = "nonnull", issue = "27730")]
2577+
#[stable(feature = "nonnull", since = "1.24.0")]
25762578
impl<T: ?Sized> fmt::Pointer for NonNull<T> {
25772579
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25782580
fmt::Pointer::fmt(&self.as_ptr(), f)
25792581
}
25802582
}
25812583

2582-
#[unstable(feature = "nonnull", issue = "27730")]
2584+
#[stable(feature = "nonnull", since = "1.24.0")]
25832585
impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
25842586
fn from(unique: Unique<T>) -> Self {
25852587
NonNull { pointer: unique.pointer }
25862588
}
25872589
}
25882590

2589-
#[unstable(feature = "nonnull", issue = "27730")]
2591+
#[stable(feature = "nonnull", since = "1.24.0")]
25902592
impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> {
25912593
fn from(reference: &'a mut T) -> Self {
25922594
NonNull { pointer: NonZero::from(reference) }
25932595
}
25942596
}
25952597

2596-
#[unstable(feature = "nonnull", issue = "27730")]
2598+
#[stable(feature = "nonnull", since = "1.24.0")]
25972599
impl<'a, T: ?Sized> From<&'a T> for NonNull<T> {
25982600
fn from(reference: &'a T) -> Self {
25992601
NonNull { pointer: NonZero::from(reference) }

src/libcore/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#![feature(iterator_try_fold)]
2828
#![feature(iter_rfind)]
2929
#![feature(iter_rfold)]
30-
#![feature(nonnull)]
3130
#![feature(nonzero)]
3231
#![feature(pattern)]
3332
#![feature(raw)]

src/librustc_data_structures/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#![deny(warnings)]
2323

2424
#![feature(collections_range)]
25-
#![feature(nonnull)]
2625
#![feature(nonzero)]
2726
#![feature(unboxed_closures)]
2827
#![feature(fn_traits)]

src/libstd/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@
283283
#![feature(macro_vis_matcher)]
284284
#![feature(needs_panic_runtime)]
285285
#![feature(never_type)]
286-
#![feature(nonnull)]
287286
#![feature(num_bits_bytes)]
288287
#![feature(old_wrapping)]
289288
#![feature(on_unimplemented)]

src/libstd/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *const T {}
198198
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *mut T {}
199199
#[unstable(feature = "ptr_internals", issue = "0")]
200200
impl<T: UnwindSafe + ?Sized> UnwindSafe for Unique<T> {}
201-
#[unstable(feature = "nonnull", issue = "27730")]
201+
#[stable(feature = "nonnull", since = "1.24.0")]
202202
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for NonNull<T> {}
203203
#[stable(feature = "catch_unwind", since = "1.9.0")]
204204
impl<T: ?Sized> UnwindSafe for Mutex<T> {}

src/test/run-pass/issue-23433.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// Don't fail if we encounter a NonZero<*T> where T is an unsized type
1212

13-
#![feature(nonnull)]
14-
1513
use std::ptr::NonNull;
1614

1715
fn main() {

0 commit comments

Comments
 (0)