Skip to content

Commit 0b00c20

Browse files
committed
Reorganize a bit the code and add a comment
1 parent bb3e513 commit 0b00c20

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/librustc/ty/layout.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,18 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
907907
let count = (niche_variants.end().as_u32()
908908
- niche_variants.start().as_u32()
909909
+ 1) as u128;
910-
if let Some((field_index, niche, (niche_start, niche_scalar))) = variants[i]
910+
911+
// Find the field with the largest niche
912+
let niche_candidate = variants[i]
911913
.iter()
912914
.enumerate()
913-
.filter_map(|(i, &field)| Some((i, field.largest_niche.as_ref()?)))
914-
.max_by_key(|(_, niche)| niche.available(dl))
915-
.and_then(|(i, niche)| Some((i, niche, niche.reserve(self, count)?)))
915+
.filter_map(|(j, &field)| Some((j, field.largest_niche.as_ref()?)))
916+
.max_by_key(|(_, niche)| niche.available(dl));
917+
918+
if let Some((field_index, niche, (niche_start, niche_scalar))) =
919+
niche_candidate.and_then(|(field_index, niche)| {
920+
Some((field_index, niche, niche.reserve(self, count)?))
921+
})
916922
{
917923
let mut align = dl.aggregate_align;
918924
let st = variants

0 commit comments

Comments
 (0)