@@ -72,12 +72,12 @@ struct Foo {
72
72
(In fact, one may use such field names in patterns or in accessor
73
73
expressions like ` foo.0 ` .)
74
74
75
- The degrees of freedom the compiler has when computing the layout of a struct or
76
- tuple is to determine the order of the fields, and the "gaps" (often called
77
- * padding* ) before, between, and after the fields. The layout of these fields
78
- themselves is already entirely determined by their types, and since we intend to
79
- allow creating references to fields (` &s.f1 ` ), structs do not have any
80
- wiggle-room there.
75
+ The degrees of freedom the compiler has when computing the layout of an
76
+ * inhabited * struct or tuple is to determine the order of the fields, and the
77
+ "gaps" (often called * padding* ) before, between, and after the fields. The
78
+ layout of these fields themselves is already entirely determined by their types,
79
+ and since we intend to allow creating references to fields (` &s.f1 ` ), structs do
80
+ not have any wiggle-room there.
81
81
82
82
This can be visualized as follows:
83
83
``` text
@@ -90,6 +90,10 @@ layout). The compiler freely picks an order for the fields to be in (this does
90
90
not have to be the order of declaration in the source), and it picks the gaps
91
91
between the fields (under some constraints, such as alignment).
92
92
93
+ For * uninhabited* structs or tuples like ` (i32, !) ` that do not have a valid
94
+ inhabitant, the compiler has more freedom. After all, no references to fields
95
+ can ever be taken. For example, such structs might be zero-sized.
96
+
93
97
How exactly the compiler picks order and gaps, as well as other aspects of
94
98
layout beyond size and field offset, can be controlled by a ` #[repr] ` attribute:
95
99
0 commit comments