Skip to content

Commit b60d5b3

Browse files
authored
Rollup merge of #145308 - giltho:dangling-doc, r=scottmcm
Adjust documentation of `dangling` I believe the current doc of `dangling` is slightly off as it indicates: `Note that the pointer value may potentially represent a valid pointer to a T` The returned pointer has no provenance, so it may not be a valid pointer (except in the case of ZSTs, but I don't think this is what the documentation is trying to warn about). See: https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Dangling.20pointers.3A.20definition The value returned by dangling may never be used to dereference a value that isn't a ZST, even if address equality is detected with that of a valid pointer. This is a minor fix, but this doc still got me confused for a second
2 parents a0ed088 + 427be23 commit b60d5b3

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

library/core/src/alloc/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ impl Layout {
226226

227227
/// Creates a `NonNull` that is dangling, but well-aligned for this Layout.
228228
///
229-
/// Note that the pointer value may potentially represent a valid pointer,
230-
/// which means this must not be used as a "not yet initialized"
231-
/// sentinel value. Types that lazily allocate must track initialization by
232-
/// some other means.
229+
/// Note that the address of the returned pointer may potentially
230+
/// be that of a valid pointer, which means this must not be used
231+
/// as a "not yet initialized" sentinel value.
232+
/// Types that lazily allocate must track initialization by some other means.
233233
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
234234
#[must_use]
235235
#[inline]

library/core/src/ptr/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,10 @@ pub const fn without_provenance<T>(addr: usize) -> *const T {
885885
/// This is useful for initializing types which lazily allocate, like
886886
/// `Vec::new` does.
887887
///
888-
/// Note that the pointer value may potentially represent a valid pointer to
889-
/// a `T`, which means this must not be used as a "not yet initialized"
890-
/// sentinel value. Types that lazily allocate must track initialization by
891-
/// some other means.
888+
/// Note that the address of the returned pointer may potentially
889+
/// be that of a valid pointer, which means this must not be used
890+
/// as a "not yet initialized" sentinel value.
891+
/// Types that lazily allocate must track initialization by some other means.
892892
#[inline(always)]
893893
#[must_use]
894894
#[stable(feature = "strict_provenance", since = "1.84.0")]
@@ -928,10 +928,10 @@ pub const fn without_provenance_mut<T>(addr: usize) -> *mut T {
928928
/// This is useful for initializing types which lazily allocate, like
929929
/// `Vec::new` does.
930930
///
931-
/// Note that the pointer value may potentially represent a valid pointer to
932-
/// a `T`, which means this must not be used as a "not yet initialized"
933-
/// sentinel value. Types that lazily allocate must track initialization by
934-
/// some other means.
931+
/// Note that the address of the returned pointer may potentially
932+
/// be that of a valid pointer, which means this must not be used
933+
/// as a "not yet initialized" sentinel value.
934+
/// Types that lazily allocate must track initialization by some other means.
935935
#[inline(always)]
936936
#[must_use]
937937
#[stable(feature = "strict_provenance", since = "1.84.0")]

library/core/src/ptr/non_null.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ impl<T: Sized> NonNull<T> {
109109
/// This is useful for initializing types which lazily allocate, like
110110
/// `Vec::new` does.
111111
///
112-
/// Note that the pointer value may potentially represent a valid pointer to
113-
/// a `T`, which means this must not be used as a "not yet initialized"
114-
/// sentinel value. Types that lazily allocate must track initialization by
115-
/// some other means.
112+
/// Note that the address of the returned pointer may potentially
113+
/// be that of a valid pointer, which means this must not be used
114+
/// as a "not yet initialized" sentinel value.
115+
/// Types that lazily allocate must track initialization by some other means.
116116
///
117117
/// # Examples
118118
///

library/core/src/ptr/unique.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ impl<T: Sized> Unique<T> {
6363
/// This is useful for initializing types which lazily allocate, like
6464
/// `Vec::new` does.
6565
///
66-
/// Note that the pointer value may potentially represent a valid pointer to
67-
/// a `T`, which means this must not be used as a "not yet initialized"
68-
/// sentinel value. Types that lazily allocate must track initialization by
69-
/// some other means.
66+
/// Note that the address of the returned pointer may potentially
67+
/// be that of a valid pointer, which means this must not be used
68+
/// as a "not yet initialized" sentinel value.
69+
/// Types that lazily allocate must track initialization by some other means.
7070
#[must_use]
7171
#[inline]
7272
pub const fn dangling() -> Self {

0 commit comments

Comments
 (0)