Skip to content

Commit 9b5148c

Browse files
RalfJungjoshtriplett
authored andcommitted
further tweak addr_of exposition
1 parent 3501d85 commit 9b5148c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: src/expressions/operator-expr.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ let a = & & & & mut 10;
8282
### Raw address-of operators
8383

8484
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)`.
85-
Like with `&`/`&mut`, the expression `expr` is evaluated in place expression context.
86-
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`.
85+
The expression `expr` is evaluated in place expression context.
86+
`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`.
8787

88-
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.
88+
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.
8989
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.
9090

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

0 commit comments

Comments
 (0)