Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify bit validity and padding of some types #1392

Merged
merged 14 commits into from
Sep 9, 2023
13 changes: 12 additions & 1 deletion src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, for every primitive numeric
type, `T`, `transmute::<[u8; size_of::<T>()], 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, for every such type, `T`,
`transmute::<T, [u8; size_of::<T>()]>(...)` is always sound).
RalfJung marked this conversation as resolved.
Show resolved Hide resolved

## 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::<P, [u8; size_of::<P>()]>(...)` is always sound).
joshlf marked this conversation as resolved.
Show resolved Hide resolved

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.
Expand Down