You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `&` (shared borrow) and `&mut` (mutable borrow) operators are unary prefix operators.
47
49
When applied to a [place expression], this expressions produces a reference (pointer) to the location that the value refers to.
@@ -79,20 +81,18 @@ let a = && && mut 10;
79
81
leta=&&&&mut10;
80
82
```
81
83
82
-
### Raw address-of operators
84
+
### Raw pointer operators
83
85
84
-
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)`][addr_of] and [`ptr::addr_of_mut!(expr)`][addr_of_mut].
86
+
Related to the borrow operators are the *raw pointer operators*, `&raw const` and `&raw mut`.
85
87
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`.
88
+
`&raw const expr` then creates a const raw pointer of type `*const T` to the given place, and `&raw mut expr` creates a mutable raw pointer of type `*mut T`.
87
89
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.
89
-
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.
90
+
The raw pointer 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.
91
+
In those situations, using a borrow operator would cause [undefined behavior] by creating an invalid reference, but a raw pointer may still be constructed.
90
92
91
93
The following is an example of creating a raw pointer to an unaligned place through a `packed` struct:
92
94
93
95
```rust
94
-
usestd::ptr;
95
-
96
96
#[repr(packed)]
97
97
structPacked {
98
98
f1:u8,
@@ -101,14 +101,14 @@ struct Packed {
101
101
102
102
letpacked=Packed { f1:1, f2:2 };
103
103
// `&packed.f2` would create an unaligned reference, and thus be Undefined Behavior!
0 commit comments