@@ -282,8 +282,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
282
282
283
283
let mut align = if pack. is_some ( ) { dl. i8_align } else { dl. aggregate_align } ;
284
284
285
- let mut sized = true ;
286
- let mut offsets = vec ! [ Size :: ZERO ; fields. len( ) ] ;
287
285
let mut inverse_memory_index: Vec < u32 > = ( 0 ..fields. len ( ) as u32 ) . collect ( ) ;
288
286
289
287
let mut optimize = !repr. inhibit_struct_field_reordering_opt ( ) ;
@@ -320,6 +318,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
320
318
// At the bottom of this function, we invert `inverse_memory_index` to
321
319
// produce `memory_index` (see `invert_mapping`).
322
320
321
+ let mut sized = true ;
322
+ let mut offsets = vec ! [ Size :: ZERO ; fields. len( ) ] ;
323
323
let mut offset = Size :: ZERO ;
324
324
let mut largest_niche = None ;
325
325
let mut largest_niche_available = 0 ;
@@ -907,18 +907,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
907
907
let count = ( niche_variants. end ( ) . as_u32 ( )
908
908
- niche_variants. start ( ) . as_u32 ( )
909
909
+ 1 ) as u128 ;
910
- // FIXME(#62691) use the largest niche across all fields,
911
- // not just the first one.
912
- for ( field_index, & field) in variants[ i] . iter ( ) . enumerate ( ) {
913
- let niche = match & field. largest_niche {
914
- Some ( niche) => niche,
915
- _ => continue ,
916
- } ;
917
- let ( niche_start, niche_scalar) = match niche. reserve ( self , count) {
918
- Some ( pair) => pair,
919
- None => continue ,
920
- } ;
921
-
910
+ if let Some ( ( field_index, niche, ( niche_start, niche_scalar) ) ) = variants[ i]
911
+ . iter ( )
912
+ . enumerate ( )
913
+ . filter_map ( |( i, & field) | {
914
+ let niche = field. largest_niche . as_ref ( ) ?;
915
+ Some ( ( i, niche, niche. reserve ( self , count) ?) )
916
+ } )
917
+ . max_by_key ( |( _, niche, _) | niche. available ( dl) )
918
+ {
922
919
let mut align = dl. aggregate_align ;
923
920
let st = variants
924
921
. iter_enumerated ( )
0 commit comments