diff options
| author | Olivier Goffart <ogoffart@woboq.com> | 2020-03-26 13:14:25 +0100 |
|---|---|---|
| committer | Olivier Goffart <ogoffart@woboq.com> | 2020-03-26 13:14:25 +0100 |
| commit | 0b00c20465c2cacf34b4d3d1a5f4d0427f384cb2 (patch) | |
| tree | 3ed18661d76b5c53c07356f3bf57e4b0f44c7b93 | |
| parent | bb3e513a2cfdc01a35c5226c24b15200d635135e (diff) | |
| download | rust-0b00c20465c2cacf34b4d3d1a5f4d0427f384cb2.tar.gz rust-0b00c20465c2cacf34b4d3d1a5f4d0427f384cb2.zip | |
Reorganize a bit the code and add a comment
| -rw-r--r-- | src/librustc/ty/layout.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 91d39334acb..dc34f076654 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -907,12 +907,18 @@ 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] + + // Find the field with the largest niche + let niche_candidate = variants[i] .iter() .enumerate() - .filter_map(|(i, &field)| Some((i, field.largest_niche.as_ref()?))) - .max_by_key(|(_, niche)| niche.available(dl)) - .and_then(|(i, niche)| Some((i, niche, niche.reserve(self, count)?))) + .filter_map(|(j, &field)| Some((j, field.largest_niche.as_ref()?))) + .max_by_key(|(_, niche)| niche.available(dl)); + + if let Some((field_index, niche, (niche_start, niche_scalar))) = + niche_candidate.and_then(|(field_index, niche)| { + Some((field_index, niche, niche.reserve(self, count)?)) + }) { let mut align = dl.aggregate_align; let st = variants |
