@@ -1390,6 +1390,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
13901390 tcx : TyCtxt < ' tcx > ,
13911391 def_id : DefId ,
13921392) -> GeneratorLayout < ' tcx > {
1393+ assert ! ( tcx. sess. opts. unstable_opts. drop_tracking_mir) ;
13931394 let def_id = def_id. expect_local ( ) ;
13941395
13951396 let ( body, _) = tcx. mir_promoted ( ty:: WithOptConstParam :: unknown ( def_id) ) ;
@@ -1400,15 +1401,8 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14001401 let gen_ty = body. local_decls [ ty:: CAPTURE_STRUCT_LOCAL ] . ty ;
14011402
14021403 // 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 ,
14121406 _ => span_bug ! ( body. span, "unexpected generator type {}" , gen_ty) ,
14131407 } ;
14141408
@@ -1422,11 +1416,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14221416 // `storage_liveness` tells us which locals have live storage at suspension points
14231417 let ( _, generator_layout, _) = compute_layout ( tcx, liveness_info, body) ;
14241418
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) ;
14301420
14311421 generator_layout
14321422}
@@ -1444,10 +1434,15 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
14441434 let gen_ty = body. local_decls . raw [ 1 ] . ty ;
14451435
14461436 // 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 ( ) {
14481438 ty:: Generator ( _, substs, movability) => {
14491439 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+ )
14511446 }
14521447 _ => {
14531448 tcx. sess
@@ -1524,6 +1519,12 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
15241519 // `storage_liveness` tells us which locals have live storage at suspension points
15251520 let ( remap, layout, storage_liveness) = compute_layout ( tcx, liveness_info, body) ;
15261521
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+
15271528 let can_return = can_return ( tcx, body, tcx. param_env ( body. source . def_id ( ) ) ) ;
15281529
15291530 // Run the transformation which converts Places from Local to generator struct
0 commit comments