From 1ef4f5d9248b3885035cfd269cca050b6d94c3dc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 27 Aug 2024 12:21:35 +0200 Subject: [PATCH] clarify that addr_of creates read-only pointers --- library/core/src/ptr/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 859fad9e069..b83a1802719 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -2285,6 +2285,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { /// `addr_of!(expr)` is equivalent to `&raw const expr`. The macro is *soft-deprecated*; /// use `&raw const` instead. /// +/// It is still an open question whether writing through an `addr_of!`-created pointer is permitted +/// or not. Until that is decided, the same rules as for shared references apply: it is UB to write +/// through a pointer created with this operation, except for bytes located inside an `UnsafeCell`. +/// /// Creating a reference with `&`/`&mut` is only allowed if the pointer is properly aligned /// and points to initialized data. For cases where those requirements do not hold, /// raw pointers should be used instead. However, `&expr as *const _` creates a reference