Skip to content

Commit

Permalink
Zero Sized Types: stop saying that "dereferencing" a non-ZST is UB
Browse files Browse the repository at this point in the history
From discussion at
https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/What.20operations.20are.20allowed.20on.20ZST.20null.20pointers.3F

 - applying the dereference operator to a null pointer stopped being UB
   a few months ago

 - it's better to be explicit about whether we're talking about loads
   and stores or about applying the dereference operator

I think we don't need to mention field projections here.
  • Loading branch information
mattheww committed Oct 27, 2024
1 parent 2d896fa commit db1fac7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/exotic-sizes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].

Note that references to ZSTs (including empty slices), just like all other
references, must be non-null and suitably aligned. However, dereferencing a
null pointer to a ZST is not [undefined behavior][ub], unlike pointers to
other types.
references, must be non-null and suitably aligned. However, loading or storing
through a null pointer to a ZST is not [undefined behavior][ub], unlike
pointers to other types.

[alloc]: ../std/alloc/trait.GlobalAlloc.html#tymethod.alloc
[ub]: what-unsafe-does.html
Expand Down

0 comments on commit db1fac7

Please sign in to comment.