@@ -505,28 +505,7 @@ impl LoweringContext<'_> {
505505 return ex;
506506 }
507507
508- ExprKind :: Yield ( ref opt_expr) => {
509- match self . generator_kind {
510- Some ( hir:: GeneratorKind :: Gen ) => { } ,
511- Some ( hir:: GeneratorKind :: Async ) => {
512- span_err ! (
513- self . sess,
514- e. span,
515- E0727 ,
516- "`async` generators are not yet supported" ,
517- ) ;
518- self . sess . abort_if_errors ( ) ;
519- } ,
520- None => {
521- self . generator_kind = Some ( hir:: GeneratorKind :: Gen ) ;
522- }
523- }
524- let expr = opt_expr
525- . as_ref ( )
526- . map ( |x| self . lower_expr ( x) )
527- . unwrap_or_else ( || self . expr_unit ( e. span ) ) ;
528- hir:: ExprKind :: Yield ( P ( expr) , hir:: YieldSource :: Yield )
529- }
508+ ExprKind :: Yield ( ref opt_expr) => self . lower_expr_yield ( e. span , opt_expr. as_deref ( ) ) ,
530509
531510 ExprKind :: Err => hir:: ExprKind :: Err ,
532511
@@ -547,6 +526,29 @@ impl LoweringContext<'_> {
547526 }
548527 }
549528
529+ fn lower_expr_yield ( & mut self , span : Span , opt_expr : Option < & Expr > ) -> hir:: ExprKind {
530+ match self . generator_kind {
531+ Some ( hir:: GeneratorKind :: Gen ) => { } ,
532+ Some ( hir:: GeneratorKind :: Async ) => {
533+ span_err ! (
534+ self . sess,
535+ span,
536+ E0727 ,
537+ "`async` generators are not yet supported" ,
538+ ) ;
539+ self . sess . abort_if_errors ( ) ;
540+ } ,
541+ None => self . generator_kind = Some ( hir:: GeneratorKind :: Gen ) ,
542+ }
543+
544+ let expr = opt_expr
545+ . as_ref ( )
546+ . map ( |x| self . lower_expr ( x) )
547+ . unwrap_or_else ( || self . expr_unit ( span) ) ;
548+
549+ hir:: ExprKind :: Yield ( P ( expr) , hir:: YieldSource :: Yield )
550+ }
551+
550552 /// Desugar `ExprForLoop` from: `[opt_ident]: for <pat> in <head> <body>` into:
551553 /// ```rust
552554 /// {
0 commit comments