Skip to content

Commit 5d4e71a

Browse files
committed
ptr::invalid is not equivalent to a int2ptr cast
1 parent 4ed08f9 commit 5d4e71a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

core/src/ptr/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,16 @@ pub const fn null_mut<T>() -> *mut T {
557557

558558
/// Creates an invalid pointer with the given address.
559559
///
560-
/// This is *currently* equivalent to `addr as *const T` but it expresses the intended semantic
561-
/// more clearly, and may become important under future memory models.
560+
/// This is different from `addr as *const T`, which creates a pointer that picks up a previously
561+
/// exposed provenance. See [`from_exposed_addr`] for more details on that operation.
562562
///
563563
/// The module's top-level documentation discusses the precise meaning of an "invalid"
564564
/// pointer but essentially this expresses that the pointer is not associated
565565
/// with any actual allocation and is little more than a usize address in disguise.
566566
///
567567
/// This pointer will have no provenance associated with it and is therefore
568568
/// UB to read/write/offset. This mostly exists to facilitate things
569-
/// like ptr::null and NonNull::dangling which make invalid pointers.
569+
/// like `ptr::null` and `NonNull::dangling` which make invalid pointers.
570570
///
571571
/// (Standard "Zero-Sized-Types get to cheat and lie" caveats apply, although it
572572
/// may be desirable to give them their own API just to make that 100% clear.)
@@ -588,16 +588,16 @@ pub const fn invalid<T>(addr: usize) -> *const T {
588588

589589
/// Creates an invalid mutable pointer with the given address.
590590
///
591-
/// This is *currently* equivalent to `addr as *mut T` but it expresses the intended semantic
592-
/// more clearly, and may become important under future memory models.
591+
/// This is different from `addr as *mut T`, which creates a pointer that picks up a previously
592+
/// exposed provenance. See [`from_exposed_addr_mut`] for more details on that operation.
593593
///
594594
/// The module's top-level documentation discusses the precise meaning of an "invalid"
595595
/// pointer but essentially this expresses that the pointer is not associated
596596
/// with any actual allocation and is little more than a usize address in disguise.
597597
///
598598
/// This pointer will have no provenance associated with it and is therefore
599599
/// UB to read/write/offset. This mostly exists to facilitate things
600-
/// like ptr::null and NonNull::dangling which make invalid pointers.
600+
/// like `ptr::null` and `NonNull::dangling` which make invalid pointers.
601601
///
602602
/// (Standard "Zero-Sized-Types get to cheat and lie" caveats apply, although it
603603
/// may be desirable to give them their own API just to make that 100% clear.)

0 commit comments

Comments
 (0)