From f4c8ff33de0cd9ba5b465356c00908d817cb5c0e Mon Sep 17 00:00:00 2001 From: July Tikhonov Date: Wed, 23 Oct 2024 19:17:36 +0600 Subject: [PATCH] fix documentation of ptr::dangling() function --- library/core/src/ptr/mod.rs | 4 ++-- library/core/src/ptr/non_null.rs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index f769b5158771c..ea185f0fbe586 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -602,7 +602,7 @@ pub const fn without_provenance(addr: usize) -> *const T { unsafe { mem::transmute(addr) } } -/// Creates a new pointer that is dangling, but well-aligned. +/// Creates a new pointer that is dangling, but non-null and well-aligned. /// /// This is useful for initializing types which lazily allocate, like /// `Vec::new` does. @@ -645,7 +645,7 @@ pub const fn without_provenance_mut(addr: usize) -> *mut T { unsafe { mem::transmute(addr) } } -/// Creates a new pointer that is dangling, but well-aligned. +/// Creates a new pointer that is dangling, but non-null and well-aligned. /// /// This is useful for initializing types which lazily allocate, like /// `Vec::new` does. diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index d91bbe1a5a193..d80e1e700aa4d 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -107,9 +107,7 @@ impl NonNull { #[must_use] #[inline] pub const fn dangling() -> Self { - // SAFETY: mem::align_of() returns a non-zero usize which is then casted - // to a *mut T. Therefore, `ptr` is not null and the conditions for - // calling new_unchecked() are respected. + // SAFETY: ptr::dangling_mut() returns a non-null well-aligned pointer. unsafe { let ptr = crate::ptr::dangling_mut::(); NonNull::new_unchecked(ptr)