diff --git a/src/type-layout.md b/src/type-layout.md index 4c87954f3..b304f64f3 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -56,12 +56,23 @@ Most primitives are generally aligned to their size, although this is platform-specific behavior. In particular, on x86 u64 and f64 are only aligned to 32 bits. +For the primitive numeric types (`u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, +`i64`, `u128`, `i128`, `usize`, `isize`, `f32`, and `f64`), every bit pattern +represents a valid instance of the type (in other words, +`transmute::<[u8; size_of::()], T>(...)` is always sound). For the primitive +numeric types and also for `bool` and `char`, every byte is guaranteed to be +initialized (in other words, `transmute::()]>(...) is always +sound). + ## Pointers and References Layout Pointers and references have the same layout. Mutability of the pointer or reference does not change the layout. -Pointers to sized types have the same size and alignment as `usize`. +Pointers to sized types have the same size and alignment as `usize`. Every +byte of a pointer to a sized type and of a reference to a sized type is +initialized (in other words, for such a pointer or reference type, `P`, +`transmute::()]>(...)` is always sound). Pointers to unsized types are sized. The size and alignment is guaranteed to be at least equal to the size and alignment of a pointer.