Open
Description
Discussing what the validity invariants of aggregate types are (and assembling a full list of aggregate types).
Safe compound types include enums, structs, tuples, arrays, slices, closures, generators, SIMD vectors.
The obvious invariant is
- If applicable: The discriminant matches a possible variant (for enums). This applies to
repr(C)
enums as well! See #[repr(C)] C-like enums and out of range values rust-memory-model#41 for some discussion of that specific case. - All fields (of the active variant, for enums) are valid at their respective type.
- All bytes not covered by any field ("padding") may have arbitrary content (including uninitialized).
Is there any exception? Currently at least, generators are an exception: Their fields may be uninitialized, leading to special cases in both layout computation code and Miri.
(I put these all together because my expectation is that there's not much to say here. We can split this up into several topics if that seems necessary.)