diff options
| author | Olivier Goffart <ogoffart@woboq.com> | 2020-03-25 22:42:13 +0100 |
|---|---|---|
| committer | Olivier Goffart <ogoffart@woboq.com> | 2020-03-25 23:08:23 +0100 |
| commit | 4d77d010962dc91e225437cbd508e1b10a9192cf (patch) | |
| tree | d5522ce77385dca55b6a5219cf17160e904bf78c /src/librustc | |
| parent | 02046a5d402c789c006d0da7662f800fe3c45faf (diff) | |
| download | rust-4d77d010962dc91e225437cbd508e1b10a9192cf.tar.gz rust-4d77d010962dc91e225437cbd508e1b10a9192cf.zip | |
Fix for #62691: use the largest niche across all fields
fixes #62691
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/ty/layout.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index c54360e0393..e63a9eac0e6 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -282,8 +282,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align }; - let mut sized = true; - let mut offsets = vec![Size::ZERO; fields.len()]; let mut inverse_memory_index: Vec<u32> = (0..fields.len() as u32).collect(); let mut optimize = !repr.inhibit_struct_field_reordering_opt(); @@ -320,6 +318,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // At the bottom of this function, we invert `inverse_memory_index` to // produce `memory_index` (see `invert_mapping`). + let mut sized = true; + let mut offsets = vec![Size::ZERO; fields.len()]; let mut offset = Size::ZERO; let mut largest_niche = None; let mut largest_niche_available = 0; @@ -907,18 +907,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let count = (niche_variants.end().as_u32() - niche_variants.start().as_u32() + 1) as u128; - // FIXME(#62691) use the largest niche across all fields, - // not just the first one. - for (field_index, &field) in variants[i].iter().enumerate() { - let niche = match &field.largest_niche { - Some(niche) => niche, - _ => continue, - }; - let (niche_start, niche_scalar) = match niche.reserve(self, count) { - Some(pair) => pair, - None => continue, - }; - + if let Some((field_index, niche, (niche_start, niche_scalar))) = variants[i] + .iter() + .enumerate() + .filter_map(|(i, &field)| { + let niche = field.largest_niche.as_ref()?; + Some((i, niche, niche.reserve(self, count)?)) + }) + .max_by_key(|(_, niche, _)| niche.available(dl)) + { let mut align = dl.aggregate_align; let st = variants .iter_enumerated() |
