@@ -72,18 +72,23 @@ 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
- When layout out a struct, the compiler in particular has to decide how the
76
- fields of the struct are arranged, which can be visualized as follows:
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" before, between,
77
+ and after the fields. The layout of these fields themselves is already entirely
78
+ determined by their types, and since we intend to allow creating references to
79
+ fields (` &s.f1 ` ), structs do not have any wiggle-room there.
80
+
81
+ This can be visualized as follows:
77
82
``` text
78
- [ <--> [field 1 ] <-----> [field 2 ] <-> [ field 3 ] <--> ]
83
+ [ <--> [field 3 ] <-----> [field 1 ] <-> [ field 2 ] <--> ]
79
84
```
80
- The individual fields are blocks of fixed size (determined by the field's
85
+ Here, the individual fields are blocks of fixed size (determined by the field's
81
86
layout). The compiler freely picks an order for the fields to be in (this does
82
87
not have to be the order of declaration in the source), and it picks the gaps
83
88
between the fields (under some constraints, such as alignment).
84
89
85
- What exactly the compiler does , as well as other aspects of layout beyond size
86
- and field offset, can be controlled by a ` #[repr] ` attribute:
90
+ How exactly the compiler picks order and gaps , as well as other aspects of
91
+ layout beyond size and field offset, can be controlled by a ` #[repr] ` attribute:
87
92
88
93
- ` #[repr(Rust)] ` -- the default.
89
94
- ` #[repr(C)] ` -- request C compatibility
0 commit comments