Say that dereferencing a pointer to a ZST is no longer undefined

The new rules were tracked in
https://github.com/rust-lang/rust/issues/117945

The corresponding update to the Reference was
https://github.com/rust-lang/reference/pull/1541
pull/467/head
Matthew Woodcraft 2 months ago
parent 456b904f79
commit 2d896fa29e

@ -106,9 +106,9 @@ consequence of types with no size. In particular, pointer offsets are no-ops,
and allocators typically [require a non-zero size][alloc]. and allocators typically [require a non-zero size][alloc].
Note that references to ZSTs (including empty slices), just like all other Note that references to ZSTs (including empty slices), just like all other
references, must be non-null and suitably aligned. Dereferencing a null or references, must be non-null and suitably aligned. However, dereferencing a
unaligned pointer to a ZST is [undefined behavior][ub], just like for any other null pointer to a ZST is not [undefined behavior][ub], unlike pointers to
type. other types.
[alloc]: ../std/alloc/trait.GlobalAlloc.html#tymethod.alloc [alloc]: ../std/alloc/trait.GlobalAlloc.html#tymethod.alloc
[ub]: what-unsafe-does.html [ub]: what-unsafe-does.html

Loading…
Cancel
Save