@@ -1311,7 +1311,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
13111311 ) -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
13121312 use SavedLocalEligibility :: * ;
13131313 let tcx = self . tcx ;
1314- let recompute_memory_index = |offsets : & Vec < u32 > | -> Vec < u32 > {
1314+ let recompute_memory_index = |offsets : & [ Size ] | -> Vec < u32 > {
13151315 debug ! ( "recompute_memory_index({:?})" , offsets) ;
13161316 let mut inverse_index = ( 0 ..offsets. len ( ) as u32 ) . collect :: < Vec < _ > > ( ) ;
13171317 inverse_index. sort_unstable_by_key ( |i| offsets[ * i as usize ] ) ;
@@ -1349,19 +1349,14 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
13491349 // get included in each variant that requested them in
13501350 // GeneratorLayout.
13511351 debug ! ( "prefix = {:#?}" , prefix) ;
1352- let ( outer_fields, promoted_offsets, promoted_memory_index) = match prefix. fields {
1353- FieldPlacement :: Arbitrary { offsets, memory_index } => {
1354- let ( offsets_a, offsets_b) =
1355- offsets. split_at ( discr_index + 1 ) ;
1356- let ( memory_index_a, memory_index_b) =
1357- memory_index. split_at ( discr_index + 1 ) ;
1358- let outer_fields = FieldPlacement :: Arbitrary {
1359- offsets : offsets_a. to_vec ( ) ,
1360- memory_index : recompute_memory_index ( & memory_index_a. to_vec ( ) )
1361- } ;
1362- ( outer_fields,
1363- offsets_b. to_vec ( ) ,
1364- recompute_memory_index ( & memory_index_b. to_vec ( ) ) )
1352+ let ( outer_fields, promoted_offsets) = match prefix. fields {
1353+ FieldPlacement :: Arbitrary { mut offsets, .. } => {
1354+ let offsets_b = offsets. split_off ( discr_index + 1 ) ;
1355+ let offsets_a = offsets;
1356+
1357+ let memory_index = recompute_memory_index ( & offsets_a) ;
1358+ let outer_fields = FieldPlacement :: Arbitrary { offsets : offsets_a, memory_index } ;
1359+ ( outer_fields, offsets_b)
13651360 }
13661361 _ => bug ! ( ) ,
13671362 } ;
@@ -1391,41 +1386,30 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
13911386 StructKind :: Prefixed ( prefix_size, prefix_align. abi ) ) ?;
13921387 variant. variants = Variants :: Single { index } ;
13931388
1394- let ( offsets, memory_index ) = match variant. fields {
1395- FieldPlacement :: Arbitrary { offsets, memory_index } => ( offsets, memory_index ) ,
1389+ let offsets = match variant. fields {
1390+ FieldPlacement :: Arbitrary { offsets, .. } => offsets,
13961391 _ => bug ! ( ) ,
13971392 } ;
13981393
13991394 // Now, stitch the promoted and variant-only fields back together in
14001395 // the order they are mentioned by our GeneratorLayout.
14011396 let mut next_variant_field = 0 ;
14021397 let mut combined_offsets = Vec :: new ( ) ;
1403- let mut combined_memory_index = Vec :: new ( ) ;
14041398 for local in variant_fields. iter ( ) {
14051399 match assignments[ * local] {
14061400 Unassigned => bug ! ( ) ,
14071401 Assigned ( _) => {
14081402 combined_offsets. push ( offsets[ next_variant_field] ) ;
1409- // Shift memory indices by the number of promoted
1410- // fields, which all come first. We may not use all
1411- // promoted fields in our variant but that's okay; we'll
1412- // renumber them below.
1413- combined_memory_index. push (
1414- promoted_memory_index. len ( ) as u32 +
1415- memory_index[ next_variant_field] ) ;
14161403 next_variant_field += 1 ;
14171404 }
14181405 Ineligible ( field_idx) => {
14191406 let field_idx = field_idx. unwrap ( ) as usize ;
14201407 combined_offsets. push ( promoted_offsets[ field_idx] ) ;
1421- combined_memory_index. push ( promoted_memory_index[ field_idx] ) ;
14221408 }
14231409 }
14241410 }
1425- variant. fields = FieldPlacement :: Arbitrary {
1426- offsets : combined_offsets,
1427- memory_index : recompute_memory_index ( & combined_memory_index) ,
1428- } ;
1411+ let memory_index = recompute_memory_index ( & combined_offsets) ;
1412+ variant. fields = FieldPlacement :: Arbitrary { offsets : combined_offsets, memory_index } ;
14291413
14301414 size = size. max ( variant. size ) ;
14311415 align = align. max ( variant. align ) ;
0 commit comments