@@ -1390,7 +1390,6 @@ 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) ;
13941393 let def_id = def_id. expect_local ( ) ;
13951394
13961395 let ( body, _) = tcx. mir_promoted ( ty:: WithOptConstParam :: unknown ( def_id) ) ;
@@ -1401,8 +1400,15 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14011400 let gen_ty = body. local_decls [ ty:: CAPTURE_STRUCT_LOCAL ] . ty ;
14021401
14031402 // Get the interior types and substs which typeck computed
1404- let movable = match * gen_ty. kind ( ) {
1405- ty:: Generator ( _, _, movability) => movability == hir:: Movability :: Movable ,
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+ }
14061412 _ => span_bug ! ( body. span, "unexpected generator type {}" , gen_ty) ,
14071413 } ;
14081414
@@ -1416,7 +1422,11 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14161422 // `storage_liveness` tells us which locals have live storage at suspension points
14171423 let ( _, generator_layout, _) = compute_layout ( tcx, liveness_info, body) ;
14181424
1419- check_suspend_tys ( tcx, & generator_layout, & body) ;
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+ }
14201430
14211431 generator_layout
14221432}
@@ -1434,15 +1444,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
14341444 let gen_ty = body. local_decls . raw [ 1 ] . ty ;
14351445
14361446 // Get the discriminant type and substs which typeck computed
1437- let ( discr_ty, upvars , interior , movable) = match * gen_ty. kind ( ) {
1447+ let ( discr_ty, movable) = match * gen_ty. kind ( ) {
14381448 ty:: Generator ( _, substs, movability) => {
14391449 let substs = substs. as_generator ( ) ;
1440- (
1441- substs. discr_ty ( tcx) ,
1442- substs. upvar_tys ( ) . collect :: < Vec < _ > > ( ) ,
1443- substs. witness ( ) ,
1444- movability == hir:: Movability :: Movable ,
1445- )
1450+ ( substs. discr_ty ( tcx) , movability == hir:: Movability :: Movable )
14461451 }
14471452 _ => {
14481453 tcx. sess
@@ -1519,12 +1524,6 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
15191524 // `storage_liveness` tells us which locals have live storage at suspension points
15201525 let ( remap, layout, storage_liveness) = compute_layout ( tcx, liveness_info, body) ;
15211526
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-
15281527 let can_return = can_return ( tcx, body, tcx. param_env ( body. source . def_id ( ) ) ) ;
15291528
15301529 // Run the transformation which converts Places from Local to generator struct
0 commit comments