diff --git a/src/type-layout.md b/src/type-layout.md index d338eb7bc..6cc920014 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -32,6 +32,29 @@ as [dynamically sized types]. Since all values of a `Sized` type share the same size and alignment, we refer to those shared values as the size of the type and the alignment of the type respectively. +### Minimum Size and Alignment + +Every type, including [dynamically sized types], has a "minimum size" and "minimum +alignment." Every value of a type must have a size at least as large as the type's +minimum size and an alignment at least as large as the type's minimum alignment. +Some notable cases of minimum size and alignment are: +- For [`Sized`] types, the type's minimum size and minimum alignment + are always equal to the type's size and alignment, respectively +- For a [slice type](#slice-layout), `[T]`, the minimum size is 0 bytes (corresponding + to a slice with 0 elements), and the minimum alignment is the alignment of `T` +- For a [trait object](#trait-object-layout), the minimum size is 0 and the minimum + alignment is 1 +- For a struct type with a dynamically-sized field, the minimum size is taken to be + the size of the struct when the dynamically-sized field has *its* minimum size and + its minimum alignment. The struct's minimum alignment is taken to be the alignment + of the struct when the dynamically-sized field has *its* minimum alignment. When + relying on this property of dynamically-sized structs, be careful not to assume too + much! For example, this property provides *no* guarantees about + [`repr(Rust)`](#the-rust-representation) types, as such a type can have arbitrarily + large size and alignment regardless of the sizes and alignments of its fields + +Every type's minimum size is less than or equal to `isize::MAX`. + ## Primitive Data Layout The size of most primitives is given in this table.