Skip to content

Commit 1ef4f5d

Browse files
committed
clarify that addr_of creates read-only pointers
1 parent bf662eb commit 1ef4f5d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/core/src/ptr/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,10 @@ impl<F: FnPtr> fmt::Debug for F {
22852285
/// `addr_of!(expr)` is equivalent to `&raw const expr`. The macro is *soft-deprecated*;
22862286
/// use `&raw const` instead.
22872287
///
2288+
/// It is still an open question whether writing through an `addr_of!`-created pointer is permitted
2289+
/// or not. Until that is decided, the same rules as for shared references apply: it is UB to write
2290+
/// through a pointer created with this operation, except for bytes located inside an `UnsafeCell`.
2291+
///
22882292
/// Creating a reference with `&`/`&mut` is only allowed if the pointer is properly aligned
22892293
/// and points to initialized data. For cases where those requirements do not hold,
22902294
/// raw pointers should be used instead. However, `&expr as *const _` creates a reference

0 commit comments

Comments
 (0)