Skip to content

Commit

Permalink
addr_of on places derived from raw pointers should preserve permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 27, 2024
1 parent 1ef4f5d commit a14b1db
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,11 @@ impl<F: FnPtr> fmt::Debug for F {
/// 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`.
/// or not. Specifically, if the place `expr` evaluates to is based on a raw pointer, then the
/// result of `addr_of!` inherits all permissions from that raw pointer. However, if the place is
/// based on a reference, local variable, or `static`, then until all details are 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,
Expand Down

0 comments on commit a14b1db

Please sign in to comment.