@@ -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 , _) => { }
@@ -1597,6 +1595,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1597
1595
1598
1596
// The first argument is the coroutine type passed by value
1599
1597
let coroutine_ty = body. local_decls . raw [ 1 ] . ty ;
1598
+ let coroutine_kind = body. coroutine_kind ( ) . unwrap ( ) ;
1600
1599
1601
1600
// Get the discriminant type and args which typeck computed
1602
1601
let ( discr_ty, movable) = match * coroutine_ty. kind ( ) {
@@ -1613,19 +1612,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1613
1612
}
1614
1613
} ;
1615
1614
1616
- let is_async_kind = matches ! (
1617
- body. coroutine_kind( ) ,
1618
- Some ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) )
1619
- ) ;
1620
- let is_async_gen_kind = matches ! (
1621
- body. coroutine_kind( ) ,
1622
- Some ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) )
1623
- ) ;
1624
- let is_gen_kind = matches ! (
1625
- body. coroutine_kind( ) ,
1626
- Some ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) )
1627
- ) ;
1628
- let new_ret_ty = match body. coroutine_kind ( ) . unwrap ( ) {
1615
+ let new_ret_ty = match coroutine_kind {
1629
1616
CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
1630
1617
// Compute Poll<return_ty>
1631
1618
let poll_did = tcx. require_lang_item ( LangItem :: Poll , None ) ;
@@ -1658,7 +1645,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1658
1645
let old_ret_local = replace_local ( RETURN_PLACE , new_ret_ty, body, tcx) ;
1659
1646
1660
1647
// Replace all occurrences of `ResumeTy` with `&mut Context<'_>` within async bodies.
1661
- if is_async_kind || is_async_gen_kind {
1648
+ if matches ! (
1649
+ coroutine_kind,
1650
+ CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _)
1651
+ ) {
1662
1652
transform_async_context ( tcx, body) ;
1663
1653
}
1664
1654
@@ -1667,11 +1657,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1667
1657
// case there is no `Assign` to it that the transform can turn into a store to the coroutine
1668
1658
// state. After the yield the slot in the coroutine state would then be uninitialized.
1669
1659
let resume_local = Local :: new ( 2 ) ;
1670
- let resume_ty = if is_async_kind {
1671
- Ty :: new_task_context ( tcx)
1672
- } else {
1673
- body. local_decls [ resume_local] . ty
1674
- } ;
1660
+ let resume_ty = body. local_decls [ resume_local] . ty ;
1675
1661
let old_resume_local = replace_local ( resume_local, resume_ty, body, tcx) ;
1676
1662
1677
1663
// When first entering the coroutine, move the resume argument into its old local
@@ -1714,11 +1700,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1714
1700
// Run the transformation which converts Places from Local to coroutine struct
1715
1701
// accesses for locals in `remap`.
1716
1702
// It also rewrites `return x` and `yield y` as writing a new coroutine state and returning
1717
- // either CoroutineState::Complete(x) and CoroutineState::Yielded(y),
1718
- // 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 .
1719
1705
let mut transform = TransformVisitor {
1720
1706
tcx,
1721
- coroutine_kind : body . coroutine_kind ( ) . unwrap ( ) ,
1707
+ coroutine_kind,
1722
1708
remap,
1723
1709
storage_liveness,
1724
1710
always_live_locals,
@@ -1735,7 +1721,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1735
1721
body. spread_arg = None ;
1736
1722
1737
1723
// Remove the context argument within generator bodies.
1738
- if is_gen_kind {
1724
+ if matches ! ( coroutine_kind , CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _ ) ) {
1739
1725
transform_gen_context ( tcx, body) ;
1740
1726
}
1741
1727
0 commit comments