Skip to content

Commit 2f06a6e

Browse files
committed
not just a note
1 parent 5ef11d9 commit 2f06a6e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ struct Foo {
7272
(In fact, one may use such field names in patterns or in accessor
7373
expressions like `foo.0`.)
7474

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.
81-
82-
**Note:** This is only true if the struct is inhabited. For structs like `(i32,
83-
!)` that do not have a valid inhabitant, the compiler has more freedom. After
84-
all, no references to fields can ever be taken. For example, such structs might
85-
be zero-sized.
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.
8681

8782
This can be visualized as follows:
8883
```text
@@ -95,6 +90,10 @@ layout). The compiler freely picks an order for the fields to be in (this does
9590
not have to be the order of declaration in the source), and it picks the gaps
9691
between the fields (under some constraints, such as alignment).
9792

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+
9897
How exactly the compiler picks order and gaps, as well as other aspects of
9998
layout beyond size and field offset, can be controlled by a `#[repr]` attribute:
10099

0 commit comments

Comments
 (0)