Skip to content

Commit 0daf227

Browse files
committed
Extend the guarantee to all struct types
1 parent c847771 commit 0daf227

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

reference/src/layout/structs-and-tuples.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,17 @@ x: u16, y: T }` where `T = u32` are not guaranteed to be identical.
124124

125125
#### Zero-sized structs
126126

127-
Structs with default layout or default layout with increased alignment are
128-
zero-sized, if they contain no fields of non-zero size. That is, either the type
129-
has no fields, or all of its fields have zero size.
127+
Structs with default layout (`repr(Rust)`), layout with increased alignment
128+
(`repr(align(N))`), packed layout (`repr(packed(N))`), or C-compatible layout
129+
(`repr(C)`) are zero-sized, if they contain no fields of non-zero size. That is,
130+
either the type has no fields, or all of its fields have zero size.
130131

131132
For example, all these types are zero-sized:
132133

133134
```rust
134135
# use std::mem::size_of;
135136
#[repr(align(32))] struct Zst0;
136-
struct Zst1(Zst0);
137+
#[repr(C)] struct Zst1(Zst0);
137138
struct Zst2(Zst1, Zst0);
138139
# fn main() {
139140
# assert_eq!(size_of::<Zst0>(), 0);

0 commit comments

Comments
 (0)