Get rid of niche selection's dependence on fields's order
This commit is contained in:
parent
f6bcd094ab
commit
9ac23dde37
2 changed files with 24 additions and 9 deletions
|
@ -527,15 +527,10 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
|
|||
let count =
|
||||
(niche_variants.end().index() as u128 - niche_variants.start().index() as u128) + 1;
|
||||
|
||||
// Find the field with the largest niche
|
||||
let (field_index, niche, (niche_start, niche_scalar)) = variants[largest_variant_index]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(j, field)| Some((j, field.largest_niche?)))
|
||||
.max_by_key(|(_, niche)| niche.available(dl))
|
||||
.and_then(|(j, niche)| Some((j, niche, niche.reserve(dl, count)?)))?;
|
||||
let niche_offset =
|
||||
niche.offset + variant_layouts[largest_variant_index].fields.offset(field_index);
|
||||
// Use the largest niche in the largest variant.
|
||||
let niche = variant_layouts[largest_variant_index].largest_niche?;
|
||||
let (niche_start, niche_scalar) = niche.reserve(dl, count)?;
|
||||
let niche_offset = niche.offset;
|
||||
let niche_size = niche.value.size(dl);
|
||||
let size = variant_layouts[largest_variant_index].size.align_to(align.abi);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue