@@ -1390,6 +1390,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
1390
1390
tcx : TyCtxt < ' tcx > ,
1391
1391
def_id : DefId ,
1392
1392
) -> GeneratorLayout < ' tcx > {
1393
+ assert ! ( tcx. sess. opts. unstable_opts. drop_tracking_mir) ;
1393
1394
let def_id = def_id. expect_local ( ) ;
1394
1395
1395
1396
let ( body, _) = tcx. mir_promoted ( ty:: WithOptConstParam :: unknown ( def_id) ) ;
@@ -1400,15 +1401,8 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
1400
1401
let gen_ty = body. local_decls [ ty:: CAPTURE_STRUCT_LOCAL ] . ty ;
1401
1402
1402
1403
// Get the interior types and substs which typeck computed
1403
- let ( upvars, interior, movable) = match * gen_ty. kind ( ) {
1404
- ty:: Generator ( _, substs, movability) => {
1405
- let substs = substs. as_generator ( ) ;
1406
- (
1407
- substs. upvar_tys ( ) . collect :: < Vec < _ > > ( ) ,
1408
- substs. witness ( ) ,
1409
- movability == hir:: Movability :: Movable ,
1410
- )
1411
- }
1404
+ let movable = match * gen_ty. kind ( ) {
1405
+ ty:: Generator ( _, _, movability) => movability == hir:: Movability :: Movable ,
1412
1406
_ => span_bug ! ( body. span, "unexpected generator type {}" , gen_ty) ,
1413
1407
} ;
1414
1408
@@ -1422,11 +1416,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
1422
1416
// `storage_liveness` tells us which locals have live storage at suspension points
1423
1417
let ( _, generator_layout, _) = compute_layout ( tcx, liveness_info, body) ;
1424
1418
1425
- if tcx. sess . opts . unstable_opts . drop_tracking_mir {
1426
- check_suspend_tys ( tcx, & generator_layout, & body) ;
1427
- } else {
1428
- sanitize_witness ( tcx, body, interior, upvars, & generator_layout) ;
1429
- }
1419
+ check_suspend_tys ( tcx, & generator_layout, & body) ;
1430
1420
1431
1421
generator_layout
1432
1422
}
@@ -1444,10 +1434,15 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1444
1434
let gen_ty = body. local_decls . raw [ 1 ] . ty ;
1445
1435
1446
1436
// Get the discriminant type and substs which typeck computed
1447
- let ( discr_ty, movable) = match * gen_ty. kind ( ) {
1437
+ let ( discr_ty, upvars , interior , movable) = match * gen_ty. kind ( ) {
1448
1438
ty:: Generator ( _, substs, movability) => {
1449
1439
let substs = substs. as_generator ( ) ;
1450
- ( substs. discr_ty ( tcx) , movability == hir:: Movability :: Movable )
1440
+ (
1441
+ substs. discr_ty ( tcx) ,
1442
+ substs. upvar_tys ( ) . collect :: < Vec < _ > > ( ) ,
1443
+ substs. witness ( ) ,
1444
+ movability == hir:: Movability :: Movable ,
1445
+ )
1451
1446
}
1452
1447
_ => {
1453
1448
tcx. sess
@@ -1524,6 +1519,12 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1524
1519
// `storage_liveness` tells us which locals have live storage at suspension points
1525
1520
let ( remap, layout, storage_liveness) = compute_layout ( tcx, liveness_info, body) ;
1526
1521
1522
+ if tcx. sess . opts . unstable_opts . validate_mir
1523
+ && !tcx. sess . opts . unstable_opts . drop_tracking_mir
1524
+ {
1525
+ sanitize_witness ( tcx, body, interior, upvars, & layout) ;
1526
+ }
1527
+
1527
1528
let can_return = can_return ( tcx, body, tcx. param_env ( body. source . def_id ( ) ) ) ;
1528
1529
1529
1530
// Run the transformation which converts Places from Local to generator struct
0 commit comments