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
12 changes: 12 additions & 0 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ 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 every primitive numeric type (`u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`,
`i64`, `u128`, `i128`, `usize`, `isize`, `f32`, and `f64`), `T`, the bit validity
of `T` is equivalent to the bit validity of `[u8; size_of::<T>()]`. `u8` has 256
valid representations (namely, every 8-bit sequence). An uninitialized byte is not
a valid `u8`. A byte at any offset in a reference or pointer type may not be a
valid `u8` (the semantics of transmuting a reference or pointer to a non-pointer
type is currently undecided).

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