Skip to content

Commit 0f469dc

Browse files
authored
Merge pull request #163 from RalfJung/zst
fix and expand what we say about ZST
2 parents 7b3c50b + 8a3cc78 commit 0f469dc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/exotic-sizes.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,15 @@ support values.
111111

112112
Safe code need not worry about ZSTs, but *unsafe* code must be careful about the
113113
consequence of types with no size. In particular, pointer offsets are no-ops,
114-
and standard allocators may return `null` when a zero-sized allocation is
115-
requested, which is indistinguishable from the out of memory result.
114+
and allocators typically [require a non-zero size][alloc].
116115

116+
Note that references to ZSTs (including empty slices), just like all other
117+
references, must be non-null and suitably aligned. Dereferencing a null or
118+
unaligned pointer to a ZST is [undefined behavior][ub], just like for any other
119+
type.
117120

121+
[alloc]: https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html#tymethod.alloc
122+
[ub]: what-unsafe-does.html
118123

119124

120125

0 commit comments

Comments
 (0)