Skip to content

Commit 74f4082

Browse files
committed
further tweak addr_of exposition
1 parent b18545e commit 74f4082

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/expressions/operator-expr.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ let a = & & & & mut 10;
7474
### Raw address-of operators
7575

7676
Related to the borrow operators are the *raw address-of operators*, which do not have first-class syntax, but are exposed via the macros `ptr::addr_of!(expr)` and `ptr::addr_of_mut!(expr)`.
77-
Like with `&`/`&mut`, the expression `expr` is evaluated in place expression context.
78-
The difference is that `&`/`&mut` create *references* of type `&T`/`&mut T`, while `ptr::addr_of!(expr)` creates a (const) raw pointer of type `*const T` and `ptr::addr_of_mut!(expr)` creates a mutable raw pointer of type `*mut T`.
77+
The expression `expr` is evaluated in place expression context.
78+
`ptr::addr_of!(expr)` then creates a (const) raw pointer of type `*const T` to the given place, and `ptr::addr_of_mut!(expr)` creates a mutable raw pointer of type `*mut T`.
7979

80-
The raw address-of operators must be used whenever the place expression could evaluate to a place that is not properly aligned or does not store a valid value as determined by its type.
80+
The raw address-of operators must be used instead of a borrow operator whenever the place expression could evaluate to a place that is not properly aligned or does not store a valid value as determined by its type, or whenever creating a reference would introduce incorrect aliasing assumptions.
8181
In those situations, using a borrow operator would cause [undefined behavior] by creating an invalid reference, but a raw pointer may still be constructed using an address-of operator.
8282

8383
The following is an example of creating a raw pointer to an unaligned place through a `packed` struct:

0 commit comments

Comments
 (0)