@@ -1417,20 +1417,18 @@ fn create_coroutine_resume_function<'tcx>(
1417
1417
cases. insert ( 0 , ( UNRESUMED , START_BLOCK ) ) ;
1418
1418
1419
1419
// Panic when resumed on the returned or poisoned state
1420
- let coroutine_kind = body. coroutine_kind ( ) . unwrap ( ) ;
1421
-
1422
1420
if can_unwind {
1423
1421
cases. insert (
1424
1422
1 ,
1425
- ( POISONED , insert_panic_block ( tcx, body, ResumedAfterPanic ( coroutine_kind) ) ) ,
1423
+ ( POISONED , insert_panic_block ( tcx, body, ResumedAfterPanic ( transform . coroutine_kind ) ) ) ,
1426
1424
) ;
1427
1425
}
1428
1426
1429
1427
if can_return {
1430
- let block = match coroutine_kind {
1428
+ let block = match transform . coroutine_kind {
1431
1429
CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _)
1432
1430
| CoroutineKind :: Coroutine ( _) => {
1433
- insert_panic_block ( tcx, body, ResumedAfterReturn ( coroutine_kind) )
1431
+ insert_panic_block ( tcx, body, ResumedAfterReturn ( transform . coroutine_kind ) )
1434
1432
}
1435
1433
CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _)
1436
1434
| CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => {
@@ -1444,7 +1442,7 @@ fn create_coroutine_resume_function<'tcx>(
1444
1442
1445
1443
make_coroutine_state_argument_indirect ( tcx, body) ;
1446
1444
1447
- match coroutine_kind {
1445
+ match transform . coroutine_kind {
1448
1446
// Iterator::next doesn't accept a pinned argument,
1449
1447
// unlike for all other coroutine kinds.
1450
1448
CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => { }
@@ -1614,12 +1612,6 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1614
1612
}
1615
1613
} ;
1616
1614
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 , _) ) ;
1623
1615
let new_ret_ty = match coroutine_kind {
1624
1616
CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
1625
1617
// Compute Poll<return_ty>
@@ -1653,7 +1645,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1653
1645
let old_ret_local = replace_local ( RETURN_PLACE , new_ret_ty, body, tcx) ;
1654
1646
1655
1647
// 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
+ ) {
1657
1652
transform_async_context ( tcx, body) ;
1658
1653
}
1659
1654
@@ -1662,11 +1657,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1662
1657
// case there is no `Assign` to it that the transform can turn into a store to the coroutine
1663
1658
// state. After the yield the slot in the coroutine state would then be uninitialized.
1664
1659
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 ;
1670
1661
let old_resume_local = replace_local ( resume_local, resume_ty, body, tcx) ;
1671
1662
1672
1663
// When first entering the coroutine, move the resume argument into its old local
@@ -1709,11 +1700,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1709
1700
// Run the transformation which converts Places from Local to coroutine struct
1710
1701
// accesses for locals in `remap`.
1711
1702
// 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 .
1714
1705
let mut transform = TransformVisitor {
1715
1706
tcx,
1716
- coroutine_kind : body . coroutine_kind ( ) . unwrap ( ) ,
1707
+ coroutine_kind,
1717
1708
remap,
1718
1709
storage_liveness,
1719
1710
always_live_locals,
@@ -1730,7 +1721,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1730
1721
body. spread_arg = None ;
1731
1722
1732
1723
// Remove the context argument within generator bodies.
1733
- if is_gen_kind {
1724
+ if matches ! ( coroutine_kind , CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _ ) ) {
1734
1725
transform_gen_context ( tcx, body) ;
1735
1726
}
1736
1727
0 commit comments