Skip to content

Commit 549463f

Browse files
authored
Rollup merge of #99973 - RalfJung:layout-things, r=eddyb
Layout things These two commits are pretty independent, but didn't seem worth doing individual PRs for: - Always check that size is a multiple of align, even without debug assertions - Change Layout debug printing to put `variants` last, since it often huge and not usually the part we are most interested in Cc `@eddyb`
2 parents c98e893 + abd80d9 commit 549463f

8 files changed

+931
-926
lines changed

compiler/rustc_middle/src/ty/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ fn sanity_check_layout<'tcx>(
232232
assert!(layout.abi.is_uninhabited());
233233
}
234234

235+
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
236+
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
237+
}
238+
235239
if cfg!(debug_assertions) {
236240
fn check_layout_abi<'tcx>(tcx: TyCtxt<'tcx>, layout: Layout<'tcx>) {
237241
match layout.abi() {

compiler/rustc_target/src/abi/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,14 @@ impl<'a> fmt::Debug for LayoutS<'a> {
12791279
// This is how `Layout` used to print before it become
12801280
// `Interned<LayoutS>`. We print it like this to avoid having to update
12811281
// expected output in a lot of tests.
1282+
let LayoutS { size, align, abi, fields, largest_niche, variants } = self;
12821283
f.debug_struct("Layout")
1283-
.field("fields", &self.fields)
1284-
.field("variants", &self.variants)
1285-
.field("abi", &self.abi)
1286-
.field("largest_niche", &self.largest_niche)
1287-
.field("align", &self.align)
1288-
.field("size", &self.size)
1284+
.field("size", size)
1285+
.field("align", align)
1286+
.field("abi", abi)
1287+
.field("fields", fields)
1288+
.field("largest_niche", largest_niche)
1289+
.field("variants", variants)
12891290
.finish()
12901291
}
12911292
}

0 commit comments

Comments
 (0)