Skip to content

Commit 9125538

Browse files
committed
use &raw instead of addr_of macros
1 parent b23eb69 commit 9125538

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

src/behavior-considered-undefined.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ the pointer that was dereferenced, *not* the type of the field that is being
102102
accessed.
103103

104104
Note that a place based on a misaligned pointer only leads to Undefined Behavior
105-
when it is loaded from or stored to. `addr_of!`/`addr_of_mut!` on such a place
105+
when it is loaded from or stored to. `&raw const`/`&raw mut` on such a place
106106
is allowed. `&`/`&mut` on a place requires the alignment of the field type (or
107107
else the program would be "producing an invalid value"), which generally is a
108108
less restrictive requirement than being based on an aligned pointer. Taking a

src/items/static-items.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ unsafe fn bump_levels_unsafe() -> u32 {
117117
// must still guard against concurrent access.
118118
fn bump_levels_safe() -> u32 {
119119
unsafe {
120-
return atomic_add(std::ptr::addr_of_mut!(LEVELS), 1);
120+
return atomic_add(&raw mut LEVELS, 1);
121121
}
122122
}
123123
```

src/type-layout.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,9 @@ was wrapped in a newtype `struct` with the same `align` modifier.
575575
> println!("{}", {e.f2});
576576
> // Or if you need a pointer, use the unaligned methods for reading and writing
577577
> // instead of dereferencing the pointer directly.
578-
> let ptr: *const u16 = std::ptr::addr_of!(e.f2);
578+
> let ptr: *const u16 = &raw const e.f2;
579579
> let value = unsafe { ptr.read_unaligned() };
580-
> let mut_ptr: *mut u16 = std::ptr::addr_of_mut!(e.f2);
580+
> let mut_ptr: *mut u16 = &raw mut e.f2;
581581
> unsafe { mut_ptr.write_unaligned(3) }
582582
> ```
583583

src/types/pointer.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ they exist to support interoperability with foreign code, and writing performanc
4444
When comparing raw pointers they are compared by their address, rather than by what they point to.
4545
When comparing raw pointers to [dynamically sized types] they also have their additional data compared.
4646

47-
Raw pointers can be created directly using [`core::ptr::addr_of!`] for `*const` pointers and [`core::ptr::addr_of_mut!`] for `*mut` pointers.
47+
Raw pointers can be created directly using `&raw const` for `*const` pointers and `&raw mut` for `*mut` pointers.
4848

4949
## Smart Pointers
5050

@@ -60,8 +60,6 @@ For thin raw pointers (i.e., for `P = *const T` or `P = *mut T` for `T: Sized`),
6060
the inverse direction (transmuting from an integer or array of integers to `P`) is always valid.
6161
However, the pointer produced via such a transmutation may not be dereferenced (not even if `T` has size zero).
6262

63-
[`core::ptr::addr_of!`]: ../../core/ptr/macro.addr_of.html
64-
[`core::ptr::addr_of_mut!`]: ../../core/ptr/macro.addr_of_mut.html
6563
[Interior mutability]: ../interior-mutability.md
6664
[_Lifetime_]: ../trait-bounds.md
6765
[_TypeNoBounds_]: ../types.md#type-expressions

0 commit comments

Comments
 (0)