@@ -1311,7 +1311,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1311
1311
) -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
1312
1312
use SavedLocalEligibility :: * ;
1313
1313
let tcx = self . tcx ;
1314
- let recompute_memory_index = |offsets : & Vec < u32 > | -> Vec < u32 > {
1314
+ let recompute_memory_index = |offsets : & [ Size ] | -> Vec < u32 > {
1315
1315
debug ! ( "recompute_memory_index({:?})" , offsets) ;
1316
1316
let mut inverse_index = ( 0 ..offsets. len ( ) as u32 ) . collect :: < Vec < _ > > ( ) ;
1317
1317
inverse_index. sort_unstable_by_key ( |i| offsets[ * i as usize ] ) ;
@@ -1349,19 +1349,14 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1349
1349
// get included in each variant that requested them in
1350
1350
// GeneratorLayout.
1351
1351
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)
1365
1360
}
1366
1361
_ => bug ! ( ) ,
1367
1362
} ;
@@ -1391,41 +1386,30 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1391
1386
StructKind :: Prefixed ( prefix_size, prefix_align. abi ) ) ?;
1392
1387
variant. variants = Variants :: Single { index } ;
1393
1388
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,
1396
1391
_ => bug ! ( ) ,
1397
1392
} ;
1398
1393
1399
1394
// Now, stitch the promoted and variant-only fields back together in
1400
1395
// the order they are mentioned by our GeneratorLayout.
1401
1396
let mut next_variant_field = 0 ;
1402
1397
let mut combined_offsets = Vec :: new ( ) ;
1403
- let mut combined_memory_index = Vec :: new ( ) ;
1404
1398
for local in variant_fields. iter ( ) {
1405
1399
match assignments[ * local] {
1406
1400
Unassigned => bug ! ( ) ,
1407
1401
Assigned ( _) => {
1408
1402
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] ) ;
1416
1403
next_variant_field += 1 ;
1417
1404
}
1418
1405
Ineligible ( field_idx) => {
1419
1406
let field_idx = field_idx. unwrap ( ) as usize ;
1420
1407
combined_offsets. push ( promoted_offsets[ field_idx] ) ;
1421
- combined_memory_index. push ( promoted_memory_index[ field_idx] ) ;
1422
1408
}
1423
1409
}
1424
1410
}
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 } ;
1429
1413
1430
1414
size = size. max ( variant. size ) ;
1431
1415
align = align. max ( variant. align ) ;
0 commit comments