about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/layout.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index e63a9eac0e6..e8c0ec89cc4 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -907,14 +907,25 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
                         let count = (niche_variants.end().as_u32()
                             - niche_variants.start().as_u32()
                             + 1) as u128;
-                        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)?))
+                        let mut niche_size = 0;
+                        if let Some((field_index, niche, niche_start, niche_scalar)) =
+                            variants[i].iter().enumerate().fold(None, |acc, (j, &field)| {
+                                let niche = match &field.largest_niche {
+                                    Some(niche) => niche,
+                                    _ => return acc,
+                                };
+                                let ns = niche.available(dl);
+                                if ns <= niche_size {
+                                    return acc;
+                                }
+                                match niche.reserve(self, count) {
+                                    Some(pair) => {
+                                        niche_size = ns;
+                                        Some((j, niche, pair.0, pair.1))
+                                    }
+                                    None => acc,
+                                }
                             })
-                            .max_by_key(|(_, niche, _)| niche.available(dl))
                         {
                             let mut align = dl.aggregate_align;
                             let st = variants