about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-03 22:56:14 +0100
committerGitHub <noreply@github.com>2024-03-03 22:56:14 +0100
commitdc8b71ae2bad080b2f1ca488fc21693ddbf78ad5 (patch)
tree09bf85ce74c718470ef0d249bfd438017914be8b
parent10234fc246d9b3a954d003b25dbe5589965efc9a (diff)
parentd579caf384b752715663f481f944f60cbae35a3e (diff)
downloadrust-dc8b71ae2bad080b2f1ca488fc21693ddbf78ad5.tar.gz
rust-dc8b71ae2bad080b2f1ca488fc21693ddbf78ad5.zip
Rollup merge of #121935 - RalfJung:ptr-without-prov, r=scottmcm
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.
-rw-r--r--library/core/src/ptr/mod.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs
index 018efd4b9b3..389e0d680a0 100644
--- a/library/core/src/ptr/mod.rs
+++ b/library/core/src/ptr/mod.rs
@@ -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
@@ -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