Skip to content

Commit bf91321

Browse files
committed
there seems to be no reason to treat ZST specially in these cases
1 parent 0da9409 commit bf91321

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

Diff for: compiler/rustc_abi/src/layout.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,8 @@ pub trait LayoutCalculator {
359359
// It'll fit, but we need to make some adjustments.
360360
match layout.fields {
361361
FieldsShape::Arbitrary { ref mut offsets, .. } => {
362-
for (j, offset) in offsets.iter_enumerated_mut() {
363-
// keep ZST at offset 0 to simplify Scalar/ScalarPair layout
364-
if !variants[i][j].0.is_zst() {
365-
*offset += this_offset;
366-
} else {
367-
debug_assert_eq!(offset.bytes(), 0);
368-
}
362+
for offset in offsets.iter_mut() {
363+
*offset += this_offset;
369364
}
370365
}
371366
_ => {
@@ -962,11 +957,6 @@ fn univariant(
962957
};
963958

964959
(
965-
// Place ZSTs first to avoid "interesting offsets", especially with only
966-
// one or two non-ZST fields. This helps Scalar/ScalarPair layouts. Note
967-
// that these can ignore even some aligned ZST as long as the alignment
968-
// is less than that of the scalar, hence we treat *all* ZST like that.
969-
!f.0.is_zst(),
970960
// Then place largest alignments first.
971961
cmp::Reverse(alignment_group_key(f)),
972962
// Then prioritize niche placement within alignment group according to

Diff for: tests/ui/layout/debug.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ error: layout_of(S) = Layout {
117117
fields: Arbitrary {
118118
offsets: [
119119
Size(0 bytes),
120-
Size(0 bytes),
120+
Size(8 bytes),
121121
Size(4 bytes),
122122
],
123123
memory_index: [
124-
1,
125124
0,
126125
2,
126+
1,
127127
],
128128
},
129129
largest_niche: None,

Diff for: tests/ui/print_type_sizes/zero-sized-fields.stdout

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
print-type-size type: `S5<(), Empty>`: 16 bytes, alignment: 4 bytes
2+
print-type-size field `.w`: 4 bytes
3+
print-type-size field `.x`: 4 bytes
4+
print-type-size field `.y`: 4 bytes
5+
print-type-size field `.z`: 4 bytes
26
print-type-size field `.tagw`: 0 bytes
37
print-type-size field `.unit`: 0 bytes
48
print-type-size field `.void`: 0 bytes
59
print-type-size field `.empty`: 0 bytes
610
print-type-size field `.tagz`: 0 bytes
7-
print-type-size field `.w`: 4 bytes
8-
print-type-size field `.x`: 4 bytes
9-
print-type-size field `.y`: 4 bytes
10-
print-type-size field `.z`: 4 bytes
1111
print-type-size type: `S1`: 8 bytes, alignment: 4 bytes
12-
print-type-size field `.tag`: 0 bytes
1312
print-type-size field `.x`: 4 bytes
1413
print-type-size field `.y`: 4 bytes
14+
print-type-size field `.tag`: 0 bytes
1515
print-type-size type: `Empty`: 0 bytes, alignment: 1 bytes
1616
print-type-size type: `Void`: 0 bytes, alignment: 1 bytes

0 commit comments

Comments
 (0)