Skip to content

Commit 0c3adde

Browse files
committed
Switch addr_of_mut for raw borrow operators
Now that there is explicit syntax for this, let's use it.
1 parent ef987b4 commit 0c3adde

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/rust-2024/static-mut-references.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ unsafe {
4444

4545
Wherever possible, it is **strongly recommended** to use instead an *immutable* `static` of a type that provides *interior mutability* behind some *locally-reasoned abstraction* (which greatly reduces the complexity of ensuring that Rust's mutability XOR aliasing requirement is upheld).
4646

47-
In situations where no locally-reasoned abstraction is possible and you are therefore compelled still to reason globally about accesses to your `static` variable, you must now use raw pointers such as can be obtained via the [`addr_of_mut!`] macro. By first obtaining a raw pointer rather than directly taking a reference, (the safety requirements of) accesses through that pointer will be more familiar to `unsafe` developers and can be deferred until/limited to smaller regions of code.
47+
In situations where no locally-reasoned abstraction is possible and you are therefore compelled still to reason globally about accesses to your `static` variable, you must now use raw pointers such as can be obtained via the [`&raw const` or `&raw mut` operators][raw]. By first obtaining a raw pointer rather than directly taking a reference, (the safety requirements of) accesses through that pointer will be more familiar to `unsafe` developers and can be deferred until/limited to smaller regions of code.
4848

4949
[Undefined Behavior]: ../../reference/behavior-considered-undefined.html
5050
[`static mut`]: ../../reference/items/static-items.html#mutable-statics
5151
[`addr_of_mut!`]: https://docs.rust-lang.org/core/ptr/macro.addr_of_mut.html
52+
[raw]: ../../reference/expressions/operator-expr.html#raw-borrow-operators
5253

5354
## Migration
5455

0 commit comments

Comments
 (0)