Skip to content

Commit 10f64a7

Browse files
committed
fix documentation of ptr::dangling() function
1 parent 054b256 commit 10f64a7

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

core/src/ptr/mod.rs

Lines changed: 2 additions & 2 deletions
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.

core/src/ptr/non_null.rs

Lines changed: 1 addition & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy