From 8a3cc78962f6a306afdc5ad673c82d67ba9f3f92 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Aug 2019 12:26:50 +0200 Subject: [PATCH] fix and expand what we say about ZST --- src/exotic-sizes.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/exotic-sizes.md b/src/exotic-sizes.md index 6031988..1e8e7a0 100644 --- a/src/exotic-sizes.md +++ b/src/exotic-sizes.md @@ -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