Skip to content

Commit 852440b

Browse files
authored
Rollup merge of rust-lang#134953 - DiuDiu777:unaligned-doc, r=RalfJung
Fix doc for read&write unaligned in zst operation ### PR Description This PR addresses an inconsistency in the Rust documentation regarding `read_unaligned ` and `write_unaligned` on zero-sized types (ZSTs). The current documentation for [pointer validity](https://doc.rust-lang.org/nightly/std/ptr/index.html#safety) states that for zero-sized types (ZSTs), null pointers are valid: > For zero-sized types (ZSTs), every pointer is valid, including the null pointer. However, there is an inconsistency in the documentation for the unaligned read operation in the function [ptr::read_unaligned](https://doc.rust-lang.org/nightly/std/ptr/fn.read_unaligned.html)(as well as `write_unaligned`), which states: > Note that even if T has size 0, the pointer must be non-null. This change is also supported by [PR rust-lang#134912](rust-lang#134912) > the _unaligned method docs should be fixed.
2 parents d08d132 + d9ef419 commit 852440b

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

library/core/src/ptr/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,6 @@ pub const unsafe fn read<T>(src: *const T) -> T {
14031403
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the returned
14041404
/// value and the value at `*src` can [violate memory safety][read-ownership].
14051405
///
1406-
/// Note that even if `T` has size `0`, the pointer must be non-null.
1407-
///
14081406
/// [read-ownership]: read#ownership-of-the-returned-value
14091407
/// [valid]: self#safety
14101408
///
@@ -1611,8 +1609,6 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
16111609
///
16121610
/// * `dst` must be [valid] for writes.
16131611
///
1614-
/// Note that even if `T` has size `0`, the pointer must be non-null.
1615-
///
16161612
/// [valid]: self#safety
16171613
///
16181614
/// ## On `packed` structs

0 commit comments

Comments
 (0)