Skip to content

Commit baea3c7

Browse files
committed
Use cfg_attr to prevent duplication
1 parent 278cb91 commit baea3c7

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

src/libcore/ptr.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -2892,17 +2892,6 @@ 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-
29062895
/// Creates a new `NonNull` that is dangling, but well-aligned.
29072896
///
29082897
/// This is useful for initializing types which lazily allocate, like
@@ -2914,8 +2903,7 @@ impl<T: Sized> NonNull<T> {
29142903
/// some other means.
29152904
#[stable(feature = "nonnull", since = "1.25.0")]
29162905
#[inline]
2917-
#[cfg(not(stage0))]
2918-
#[rustc_const_unstable(feature = "const_ptr_nonnull")]
2906+
#[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
29192907
pub const fn dangling() -> Self {
29202908
unsafe {
29212909
let ptr = mem::align_of::<T>() as *mut T;
@@ -2976,21 +2964,10 @@ impl<T: ?Sized> NonNull<T> {
29762964
&mut *self.as_ptr()
29772965
}
29782966

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-
29892967
/// Cast to a pointer of another type
29902968
#[stable(feature = "nonnull_cast", since = "1.27.0")]
29912969
#[inline]
2992-
#[cfg(not(stage0))]
2993-
#[rustc_const_unstable(feature = "const_ptr_nonnull")]
2970+
#[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
29942971
pub const fn cast<U>(self) -> NonNull<U> {
29952972
unsafe {
29962973
NonNull::new_unchecked(self.as_ptr() as *mut U)

0 commit comments

Comments
 (0)