Skip to content

Commit 2d62619

Browse files
committed
Add rustc_const_unstable attribute
1 parent b23fd43 commit 2d62619

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/libcore/ptr.rs

+25
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,17 @@ impl<T: ?Sized> !Send for NonNull<T> { }
28922892
impl<T: ?Sized> !Sync for NonNull<T> { }
28932893

28942894
impl<T: Sized> NonNull<T> {
2895+
/// No docs here
2896+
#[stable(feature = "nonnull", since = "1.25.0")]
2897+
#[inline]
2898+
#[cfg(stage0)]
2899+
pub fn dangling() -> Self {
2900+
unsafe {
2901+
let ptr = mem::align_of::<T>() as *mut T;
2902+
NonNull::new_unchecked(ptr)
2903+
}
2904+
}
2905+
28952906
/// Creates a new `NonNull` that is dangling, but well-aligned.
28962907
///
28972908
/// This is useful for initializing types which lazily allocate, like
@@ -2903,6 +2914,8 @@ impl<T: Sized> NonNull<T> {
29032914
/// some other means.
29042915
#[stable(feature = "nonnull", since = "1.25.0")]
29052916
#[inline]
2917+
#[cfg(not(stage0))]
2918+
#[rustc_const_unstable(feature = "const_ptr_nonnull")]
29062919
pub const fn dangling() -> Self {
29072920
unsafe {
29082921
let ptr = mem::align_of::<T>() as *mut T;
@@ -2963,9 +2976,21 @@ impl<T: ?Sized> NonNull<T> {
29632976
&mut *self.as_ptr()
29642977
}
29652978

2979+
/// No docs here
2980+
#[stable(feature = "nonnull_cast", since = "1.27.0")]
2981+
#[inline]
2982+
#[cfg(stage0)]
2983+
pub fn cast<U>(self) -> NonNull<U> {
2984+
unsafe {
2985+
NonNull::new_unchecked(self.as_ptr() as *mut U)
2986+
}
2987+
}
2988+
29662989
/// Cast to a pointer of another type
29672990
#[stable(feature = "nonnull_cast", since = "1.27.0")]
29682991
#[inline]
2992+
#[cfg(not(stage0))]
2993+
#[rustc_const_unstable(feature = "const_ptr_nonnull")]
29692994
pub const fn cast<U>(self) -> NonNull<U> {
29702995
unsafe {
29712996
NonNull::new_unchecked(self.as_ptr() as *mut U)

0 commit comments

Comments
 (0)