On this page
Function std::ptr::invalid
pub const fn invalid<T>(addr: usize) -> *const T
strict_provenance
#95228)
Creates an invalid pointer with the given address.
This is different from addr as *const T
, which creates a pointer that picks up a previously exposed provenance. See from_exposed_addr
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.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ptr/fn.invalid.html