From bf91321e0fc9cb9cd921263ac473c5255dc8cc14 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 27 Aug 2023 18:06:59 +0200 Subject: [PATCH] there seems to be no reason to treat ZST specially in these cases --- compiler/rustc_abi/src/layout.rs | 14 ++------------ tests/ui/layout/debug.stderr | 4 ++-- tests/ui/print_type_sizes/zero-sized-fields.stdout | 10 +++++----- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 76c5ac460a1..0706dc18f0e 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -359,13 +359,8 @@ struct TmpLayout { // It'll fit, but we need to make some adjustments. match layout.fields { FieldsShape::Arbitrary { ref mut offsets, .. } => { - for (j, offset) in offsets.iter_enumerated_mut() { - // keep ZST at offset 0 to simplify Scalar/ScalarPair layout - if !variants[i][j].0.is_zst() { - *offset += this_offset; - } else { - debug_assert_eq!(offset.bytes(), 0); - } + for offset in offsets.iter_mut() { + *offset += this_offset; } } _ => { @@ -962,11 +957,6 @@ fn univariant( }; ( - // Place ZSTs first to avoid "interesting offsets", especially with only - // one or two non-ZST fields. This helps Scalar/ScalarPair layouts. Note - // that these can ignore even some aligned ZST as long as the alignment - // is less than that of the scalar, hence we treat *all* ZST like that. - !f.0.is_zst(), // Then place largest alignments first. cmp::Reverse(alignment_group_key(f)), // Then prioritize niche placement within alignment group according to diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index ea5e1ad9dce..c20a0198ccb 100644 --- a/tests/ui/layout/debug.stderr +++ b/tests/ui/layout/debug.stderr @@ -117,13 +117,13 @@ error: layout_of(S) = Layout { fields: Arbitrary { offsets: [ Size(0 bytes), - Size(0 bytes), + Size(8 bytes), Size(4 bytes), ], memory_index: [ - 1, 0, 2, + 1, ], }, largest_niche: None, diff --git a/tests/ui/print_type_sizes/zero-sized-fields.stdout b/tests/ui/print_type_sizes/zero-sized-fields.stdout index 72f59c4bb57..e4d44241e43 100644 --- a/tests/ui/print_type_sizes/zero-sized-fields.stdout +++ b/tests/ui/print_type_sizes/zero-sized-fields.stdout @@ -1,16 +1,16 @@ print-type-size type: `S5<(), Empty>`: 16 bytes, alignment: 4 bytes +print-type-size field `.w`: 4 bytes +print-type-size field `.x`: 4 bytes +print-type-size field `.y`: 4 bytes +print-type-size field `.z`: 4 bytes print-type-size field `.tagw`: 0 bytes print-type-size field `.unit`: 0 bytes print-type-size field `.void`: 0 bytes print-type-size field `.empty`: 0 bytes print-type-size field `.tagz`: 0 bytes -print-type-size field `.w`: 4 bytes -print-type-size field `.x`: 4 bytes -print-type-size field `.y`: 4 bytes -print-type-size field `.z`: 4 bytes print-type-size type: `S1`: 8 bytes, alignment: 4 bytes -print-type-size field `.tag`: 0 bytes print-type-size field `.x`: 4 bytes print-type-size field `.y`: 4 bytes +print-type-size field `.tag`: 0 bytes print-type-size type: `Empty`: 0 bytes, alignment: 1 bytes print-type-size type: `Void`: 0 bytes, alignment: 1 bytes