Skip to content

Commit 01fac39

Browse files
committed
further tweak addr_of exposition
1 parent a775f10 commit 01fac39

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/expressions/operator-expr.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ let a = & & & & mut 10;
7373
### Raw address-of operators
7474

7575
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)`.
76-
Like with `&`/`&mut`, the expression `expr` is evaluated in place expression context.
77-
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`.
76+
The expression `expr` is evaluated in place expression context.
77+
`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`.
7878

79-
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.
79+
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.
8080
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.
8181

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

0 commit comments

Comments
 (0)