Skip to content

Commit 510e75c

Browse files
authored
Specify bit validity and padding of some types
Specify the bit validity and padding of the primitive numeric types, bool, char, and pointer and reference types. Closes #1291
1 parent f7e6f04 commit 510e75c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/type-layout.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ Most primitives are generally aligned to their size, although this is
5656
platform-specific behavior. In particular, on x86 u64 and f64 are only
5757
aligned to 32 bits.
5858

59+
For the primitive numeric types (`u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`,
60+
`i64`, `u128`, `i128`, `usize`, `isize`, `f32`, and `f64`), every bit pattern
61+
represents a valid instance of the type (in other words,
62+
`transmute::<[u8; size_of::<T>()], T>(...)` is always sound). For the primitive
63+
numeric types and also for `bool` and `char`, every byte is guaranteed to be
64+
initialized (in other words, `transmute::<T, [u8; size_of::<T>()]>(...) is always
65+
sound).
66+
5967
## Pointers and References Layout
6068

6169
Pointers and references have the same layout. Mutability of the pointer or
6270
reference does not change the layout.
6371

64-
Pointers to sized types have the same size and alignment as `usize`.
72+
Pointers to sized types have the same size and alignment as `usize`. Every
73+
byte of a pointer to a sized type and of a reference to a sized type is
74+
initialized (in other words, for such a pointer or reference type, `P`,
75+
`transmute::<P, [u8; size_of::<P>()]>(...)` is always sound).
6576

6677
Pointers to unsized types are sized. The size and alignment is guaranteed to be
6778
at least equal to the size and alignment of a pointer.

0 commit comments

Comments
 (0)