@@ -1417,20 +1417,18 @@ fn create_coroutine_resume_function<'tcx>(
14171417 cases. insert ( 0 , ( UNRESUMED , START_BLOCK ) ) ;
14181418
14191419 // Panic when resumed on the returned or poisoned state
1420- let coroutine_kind = body. coroutine_kind ( ) . unwrap ( ) ;
1421-
14221420 if can_unwind {
14231421 cases. insert (
14241422 1 ,
1425- ( POISONED , insert_panic_block ( tcx, body, ResumedAfterPanic ( coroutine_kind) ) ) ,
1423+ ( POISONED , insert_panic_block ( tcx, body, ResumedAfterPanic ( transform . coroutine_kind ) ) ) ,
14261424 ) ;
14271425 }
14281426
14291427 if can_return {
1430- let block = match coroutine_kind {
1428+ let block = match transform . coroutine_kind {
14311429 CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _)
14321430 | CoroutineKind :: Coroutine ( _) => {
1433- insert_panic_block ( tcx, body, ResumedAfterReturn ( coroutine_kind) )
1431+ insert_panic_block ( tcx, body, ResumedAfterReturn ( transform . coroutine_kind ) )
14341432 }
14351433 CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _)
14361434 | CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => {
@@ -1444,7 +1442,7 @@ fn create_coroutine_resume_function<'tcx>(
14441442
14451443 make_coroutine_state_argument_indirect ( tcx, body) ;
14461444
1447- match coroutine_kind {
1445+ match transform . coroutine_kind {
14481446 // Iterator::next doesn't accept a pinned argument,
14491447 // unlike for all other coroutine kinds.
14501448 CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => { }
@@ -1614,12 +1612,6 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16141612 }
16151613 } ;
16161614
1617- let is_async_kind =
1618- matches ! ( coroutine_kind, CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) ;
1619- let is_async_gen_kind =
1620- matches ! ( coroutine_kind, CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) ;
1621- let is_gen_kind =
1622- matches ! ( coroutine_kind, CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) ;
16231615 let new_ret_ty = match coroutine_kind {
16241616 CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
16251617 // Compute Poll<return_ty>
@@ -1653,7 +1645,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16531645 let old_ret_local = replace_local ( RETURN_PLACE , new_ret_ty, body, tcx) ;
16541646
16551647 // Replace all occurrences of `ResumeTy` with `&mut Context<'_>` within async bodies.
1656- if is_async_kind || is_async_gen_kind {
1648+ if matches ! (
1649+ coroutine_kind,
1650+ CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _)
1651+ ) {
16571652 transform_async_context ( tcx, body) ;
16581653 }
16591654
@@ -1662,11 +1657,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
16621657 // case there is no `Assign` to it that the transform can turn into a store to the coroutine
16631658 // state. After the yield the slot in the coroutine state would then be uninitialized.
16641659 let resume_local = Local :: new ( 2 ) ;
1665- let resume_ty = if is_async_kind {
1666- Ty :: new_task_context ( tcx)
1667- } else {
1668- body. local_decls [ resume_local] . ty
1669- } ;
1660+ let resume_ty = body. local_decls [ resume_local] . ty ;
16701661 let old_resume_local = replace_local ( resume_local, resume_ty, body, tcx) ;
16711662
16721663 // When first entering the coroutine, move the resume argument into its old local
@@ -1709,11 +1700,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
17091700 // Run the transformation which converts Places from Local to coroutine struct
17101701 // accesses for locals in `remap`.
17111702 // It also rewrites `return x` and `yield y` as writing a new coroutine state and returning
1712- // either CoroutineState::Complete(x) and CoroutineState::Yielded(y),
1713- // or Poll::Ready(x) and Poll::Pending respectively depending on `is_async_kind` .
1703+ // either ` CoroutineState::Complete(x)` and ` CoroutineState::Yielded(y)` ,
1704+ // or ` Poll::Ready(x)` and ` Poll::Pending` respectively depending on the coroutine kind .
17141705 let mut transform = TransformVisitor {
17151706 tcx,
1716- coroutine_kind : body . coroutine_kind ( ) . unwrap ( ) ,
1707+ coroutine_kind,
17171708 remap,
17181709 storage_liveness,
17191710 always_live_locals,
@@ -1730,7 +1721,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
17301721 body. spread_arg = None ;
17311722
17321723 // Remove the context argument within generator bodies.
1733- if is_gen_kind {
1724+ if matches ! ( coroutine_kind , CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _ ) ) {
17341725 transform_gen_context ( tcx, body) ;
17351726 }
17361727
0 commit comments