Skip to content

Commit

Permalink
Rollup merge of rust-lang#121935 - RalfJung:ptr-without-prov, r=scottmcm
Browse files Browse the repository at this point in the history
library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr

This might help clarify why you can't do memory accesses with it.
  • Loading branch information
matthiaskrgr authored Mar 3, 2024
2 parents 10234fc + d579caf commit dc8b71a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {

/// Creates a pointer with the given address and no provenance.
///
/// This is equivalent to `ptr::null().with_addr(addr)`.
///
/// Without provenance, this pointer is not associated with any actual allocation. Such a
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
/// non-zero-sized memory accesses with a no-provenance pointer are UB. No-provenance pointers are
Expand Down Expand Up @@ -616,6 +618,8 @@ pub const fn dangling<T>() -> *const T {

/// Creates a pointer with the given address and no provenance.
///
/// This is equivalent to `ptr::null_mut().with_addr(addr)`.
///
/// Without provenance, this pointer is not associated with any actual allocation. Such a
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
/// non-zero-sized memory accesses with a no-provenance pointer are UB. No-provenance pointers are
Expand Down

0 comments on commit dc8b71a

Please sign in to comment.