@@ -201,18 +201,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
201
201
fn_decl_span,
202
202
fn_arg_span,
203
203
} ) => match coroutine_kind {
204
- Some ( coroutine_kind ) => self . lower_expr_coroutine_closure (
204
+ Some ( kind @ CoroutineKind :: Async { .. } ) => self . lower_expr_coroutine_closure (
205
205
binder,
206
206
* capture_clause,
207
207
e. id ,
208
208
hir_id,
209
- * coroutine_kind ,
209
+ * kind ,
210
210
fn_decl,
211
211
body,
212
212
* fn_decl_span,
213
213
* fn_arg_span,
214
214
) ,
215
- None => self . lower_expr_closure (
215
+ _ => self . lower_expr_closure (
216
216
binder,
217
217
* capture_clause,
218
218
e. id ,
@@ -222,6 +222,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222
222
body,
223
223
* fn_decl_span,
224
224
* fn_arg_span,
225
+ * coroutine_kind,
225
226
) ,
226
227
} ,
227
228
ExprKind :: Gen ( capture_clause, block, genblock_kind) => {
@@ -963,12 +964,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
963
964
body : & Expr ,
964
965
fn_decl_span : Span ,
965
966
fn_arg_span : Span ,
967
+ coroutine_kind : Option < CoroutineKind > ,
966
968
) -> hir:: ExprKind < ' hir > {
967
969
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
968
970
969
971
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
+ } ) ;
971
981
let body_id = this. lower_fn_body ( decl, |this| {
982
+ this. coroutine_kind = coroutine_kind;
972
983
let e = this. lower_expr_mut ( body) ;
973
984
coroutine_kind = this. coroutine_kind ;
974
985
e
0 commit comments