Function core::ptr::invalid_mut
const: 1.61.0 · source · strict_provenance
#95228)Expand description
Creates an invalid mutable pointer with the given address.
This is different from addr as *mut T
, which creates a pointer that picks up a previously
exposed provenance. See from_exposed_addr_mut
for more details on that operation.
The module’s top-level documentation discusses the precise meaning of an “invalid” pointer but essentially this expresses that the pointer is not associated with any actual allocation and is little more than a usize address in disguise.
This pointer will have no provenance associated with it and is therefore
UB to read/write/offset. This mostly exists to facilitate things
like ptr::null
and NonNull::dangling
which make invalid pointers.
(Standard “Zero-Sized-Types get to cheat and lie” caveats apply, although it may be desirable to give them their own API just to make that 100% clear.)
This API and its claimed semantics are part of the Strict Provenance experiment, see the module documentation for details.