@@ -201,18 +201,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
201201 fn_decl_span,
202202 fn_arg_span,
203203 } ) => match coroutine_kind {
204- Some ( coroutine_kind ) => self . lower_expr_coroutine_closure (
204+ Some ( kind @ CoroutineKind :: Async { .. } ) => self . lower_expr_coroutine_closure (
205205 binder,
206206 * capture_clause,
207207 e. id ,
208208 hir_id,
209- * coroutine_kind ,
209+ * kind ,
210210 fn_decl,
211211 body,
212212 * fn_decl_span,
213213 * fn_arg_span,
214214 ) ,
215- None => self . lower_expr_closure (
215+ _ => self . lower_expr_closure (
216216 binder,
217217 * capture_clause,
218218 e. id ,
@@ -222,6 +222,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222222 body,
223223 * fn_decl_span,
224224 * fn_arg_span,
225+ * coroutine_kind,
225226 ) ,
226227 } ,
227228 ExprKind :: Gen ( capture_clause, block, genblock_kind) => {
@@ -963,12 +964,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
963964 body : & Expr ,
964965 fn_decl_span : Span ,
965966 fn_arg_span : Span ,
967+ coroutine_kind : Option < CoroutineKind > ,
966968 ) -> hir:: ExprKind < ' hir > {
967969 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
968970
969971 let ( body_id, closure_kind) = self . with_new_scopes ( fn_decl_span, move |this| {
970- let mut coroutine_kind = None ;
972+ let mut coroutine_kind = coroutine_kind. map ( |k| match k {
973+ CoroutineKind :: Async { span, .. } => {
974+ span_bug ! ( span, "should have used lower_expr_coroutine_closure" )
975+ }
976+ CoroutineKind :: Gen { .. } => hir:: CoroutineKind :: Coroutine ( Movability :: Movable ) ,
977+ CoroutineKind :: AsyncGen { span, .. } => {
978+ span_bug ! ( span, "async gen closures are not supported yet" )
979+ }
980+ } ) ;
971981 let body_id = this. lower_fn_body ( decl, |this| {
982+ this. coroutine_kind = coroutine_kind;
972983 let e = this. lower_expr_mut ( body) ;
973984 coroutine_kind = this. coroutine_kind ;
974985 e
0 commit comments