Skip to content

Commit 2ee4159

Browse files
Rollup merge of rust-lang#133048 - cyrgani:ptr-doc-update, r=Amanieu
use `&raw` in `{read, write}_unaligned` documentation Fixes rust-lang#133024 by using `&raw const` and `&raw mut` instead of `addr_of!` and `addr_of_mut!`.
2 parents e1448de + 60ef479 commit 2ee4159

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

core/src/ptr/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,8 @@ pub const unsafe fn read<T>(src: *const T) -> T {
14071407
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
14081408
/// *undefined behavior* in your program.
14091409
///
1410-
/// Instead you must use the [`ptr::addr_of!`](addr_of) macro to
1411-
/// create the pointer. You may use that returned pointer together with this
1412-
/// function.
1410+
/// Instead you must use the `&raw const` syntax to create the pointer.
1411+
/// You may use that constructed pointer together with this function.
14131412
///
14141413
/// An example of what not to do and how this relates to `read_unaligned` is:
14151414
///
@@ -1427,7 +1426,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
14271426
///
14281427
/// // Take the address of a 32-bit integer which is not aligned.
14291428
/// // In contrast to `&packed.unaligned as *const _`, this has no undefined behavior.
1430-
/// let unaligned = std::ptr::addr_of!(packed.unaligned);
1429+
/// let unaligned = &raw const packed.unaligned;
14311430
///
14321431
/// let v = unsafe { std::ptr::read_unaligned(unaligned) };
14331432
/// assert_eq!(v, 0x01020304);
@@ -1615,9 +1614,8 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
16151614
/// As a result, using `&packed.unaligned as *const FieldType` causes immediate
16161615
/// *undefined behavior* in your program.
16171616
///
1618-
/// Instead, you must use the [`ptr::addr_of_mut!`](addr_of_mut)
1619-
/// macro to create the pointer. You may use that returned pointer together with
1620-
/// this function.
1617+
/// Instead, you must use the `&raw mut` syntax to create the pointer.
1618+
/// You may use that constructed pointer together with this function.
16211619
///
16221620
/// An example of how to do it and how this relates to `write_unaligned` is:
16231621
///
@@ -1632,7 +1630,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
16321630
///
16331631
/// // Take the address of a 32-bit integer which is not aligned.
16341632
/// // In contrast to `&packed.unaligned as *mut _`, this has no undefined behavior.
1635-
/// let unaligned = std::ptr::addr_of_mut!(packed.unaligned);
1633+
/// let unaligned = &raw mut packed.unaligned;
16361634
///
16371635
/// unsafe { std::ptr::write_unaligned(unaligned, 42) };
16381636
///

0 commit comments

Comments
 (0)