Skip to content

Commit 33cc59a

Browse files
authored
Clarify that 0 is a valid multiple of a type's alignment
The reference currently states that "[t]he size of a value is always a multiple of its alignment." This might be taken to imply that a type's size is greater than or equal to its alignment. This commit clarifies that 0 is a valid multiple; zero-sized types have 0 size and nonzero alignment.
1 parent f62e93c commit 33cc59a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/type-layout.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ The alignment of a value can be checked with the [`align_of_val`] function.
2020

2121
The *size* of a value is the offset in bytes between successive elements in an
2222
array with that item type including alignment padding. The size of a value is
23-
always a multiple of its alignment. The size of a value can be checked with the
24-
[`size_of_val`] function.
23+
always a multiple of its alignment. Note that some types are zero-sized; 0 is
24+
considered a multiple of any alignment (for example, on some platforms, the type
25+
`[u16; 0]` has size 0 and alignment 2). The size of a value can be checked with
26+
the [`size_of_val`] function.
2527

2628
Types where all values have the same size and alignment, and both are known at
2729
compile time, implement the [`Sized`] trait and can be checked with the

0 commit comments

Comments
 (0)