Skip to content

Commit f4c8ff3

Browse files
committed
fix documentation of ptr::dangling() function
1 parent ffd978b commit f4c8ff3

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

library/core/src/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ pub const fn without_provenance<T>(addr: usize) -> *const T {
602602
unsafe { mem::transmute(addr) }
603603
}
604604

605-
/// Creates a new pointer that is dangling, but well-aligned.
605+
/// Creates a new pointer that is dangling, but non-null and well-aligned.
606606
///
607607
/// This is useful for initializing types which lazily allocate, like
608608
/// `Vec::new` does.
@@ -645,7 +645,7 @@ pub const fn without_provenance_mut<T>(addr: usize) -> *mut T {
645645
unsafe { mem::transmute(addr) }
646646
}
647647

648-
/// Creates a new pointer that is dangling, but well-aligned.
648+
/// Creates a new pointer that is dangling, but non-null and well-aligned.
649649
///
650650
/// This is useful for initializing types which lazily allocate, like
651651
/// `Vec::new` does.

library/core/src/ptr/non_null.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ impl<T: Sized> NonNull<T> {
107107
#[must_use]
108108
#[inline]
109109
pub const fn dangling() -> Self {
110-
// SAFETY: mem::align_of() returns a non-zero usize which is then casted
111-
// to a *mut T. Therefore, `ptr` is not null and the conditions for
112-
// calling new_unchecked() are respected.
110+
// SAFETY: ptr::dangling_mut() returns a non-null well-aligned pointer.
113111
unsafe {
114112
let ptr = crate::ptr::dangling_mut::<T>();
115113
NonNull::new_unchecked(ptr)

0 commit comments

Comments
 (0)