clarify that addr_of creates read-only pointers · patricklam/verify-rust-std@1933103 (original) (raw)

Original file line number Diff line number Diff line change
@@ -2285,6 +2285,10 @@ impl<F: FnPtr> fmt::Debug for F {
2285 2285 /// `addr_of!(expr)` is equivalent to `&raw const expr`. The macro is *soft-deprecated*;
2286 2286 /// use `&raw const` instead.
2287 2287 ///
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 +///
2288 2292 /// Creating a reference with `&`/`&mut` is only allowed if the pointer is properly aligned
2289 2293 /// and points to initialized data. For cases where those requirements do not hold,
2290 2294 /// raw pointers should be used instead. However, `&expr as *const _` creates a reference