@@ -764,10 +764,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
764
764
Some ( hir:: CoroutineKind :: Coroutine ( _) )
765
765
| Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Gen , _) )
766
766
| None => {
767
- return hir:: ExprKind :: Err ( self . dcx ( ) . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
768
- await_kw_span,
769
- item_span : self . current_item ,
770
- } ) ) ;
767
+ let stmt_id = self . next_id ( ) ;
768
+ let expr_err = self . expr (
769
+ expr. span ,
770
+ hir:: ExprKind :: Err ( self . dcx ( ) . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
771
+ await_kw_span,
772
+ item_span : self . current_item ,
773
+ } ) ) ,
774
+ ) ;
775
+ return hir:: ExprKind :: Block (
776
+ self . block_all (
777
+ expr. span ,
778
+ arena_vec ! [ self ; hir:: Stmt {
779
+ hir_id: stmt_id,
780
+ kind: hir:: StmtKind :: Semi ( expr) ,
781
+ span: expr. span,
782
+ } ] ,
783
+ Some ( self . arena . alloc ( expr_err) ) ,
784
+ ) ,
785
+ None ,
786
+ ) ;
771
787
}
772
788
} ;
773
789
@@ -1500,12 +1516,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
1500
1516
}
1501
1517
1502
1518
fn lower_expr_yield ( & mut self , span : Span , opt_expr : Option < & Expr > ) -> hir:: ExprKind < ' hir > {
1519
+ let yielded =
1520
+ opt_expr. as_ref ( ) . map ( |x| self . lower_expr ( x) ) . unwrap_or_else ( || self . expr_unit ( span) ) ;
1521
+
1503
1522
let is_async_gen = match self . coroutine_kind {
1504
1523
Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Gen , _) ) => false ,
1505
1524
Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: AsyncGen , _) ) => true ,
1506
1525
Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Async , _) ) => {
1507
- return hir:: ExprKind :: Err (
1508
- self . dcx ( ) . emit_err ( AsyncCoroutinesNotSupported { span } ) ,
1526
+ let stmt_id = self . next_id ( ) ;
1527
+ let expr_err = self . expr (
1528
+ yielded. span ,
1529
+ hir:: ExprKind :: Err ( self . dcx ( ) . emit_err ( AsyncCoroutinesNotSupported { span } ) ) ,
1530
+ ) ;
1531
+ return hir:: ExprKind :: Block (
1532
+ self . block_all (
1533
+ yielded. span ,
1534
+ arena_vec ! [ self ; hir:: Stmt {
1535
+ hir_id: stmt_id,
1536
+ kind: hir:: StmtKind :: Semi ( yielded) ,
1537
+ span: yielded. span,
1538
+ } ] ,
1539
+ Some ( self . arena . alloc ( expr_err) ) ,
1540
+ ) ,
1541
+ None ,
1509
1542
) ;
1510
1543
}
1511
1544
Some ( hir:: CoroutineKind :: Coroutine ( _) ) => {
@@ -1535,9 +1568,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1535
1568
}
1536
1569
} ;
1537
1570
1538
- let yielded =
1539
- opt_expr. as_ref ( ) . map ( |x| self . lower_expr ( x) ) . unwrap_or_else ( || self . expr_unit ( span) ) ;
1540
-
1541
1571
if is_async_gen {
1542
1572
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
1543
1573
// This ensures that we store our resumed `ResumeContext` correctly, and also that
0 commit comments