Merge pull request #163 from RalfJung/zst

fix and expand what we say about ZST
pull/165/head
Mazdak Farrokhzad 5 years ago committed by GitHub
commit 0f469dcadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,10 +111,15 @@ support values.
Safe code need not worry about ZSTs, but *unsafe* code must be careful about the
consequence of types with no size. In particular, pointer offsets are no-ops,
and standard allocators may return `null` when a zero-sized allocation is
requested, which is indistinguishable from the out of memory result.
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. Dereferencing a null or
unaligned pointer to a ZST is [undefined behavior][ub], just like for any other
type.
[alloc]: https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html#tymethod.alloc
[ub]: what-unsafe-does.html

Loading…
Cancel
Save