1
1
use super :: errors:: {
2
- AsyncCoroutinesNotSupported , AsyncNonMoveClosureNotSupported , AwaitOnlyInAsyncFnAndBlocks ,
3
- BaseExpressionDoubleDot , ClosureCannotBeStatic , CoroutineTooManyParameters ,
2
+ AsyncCoroutinesNotSupported , AwaitOnlyInAsyncFnAndBlocks , BaseExpressionDoubleDot ,
3
+ ClosureCannotBeStatic , CoroutineTooManyParameters ,
4
4
FunctionalRecordUpdateDestructuringAssignment , InclusiveRangeWithNoEnd , MatchArmWithNoBody ,
5
5
NeverPatternWithBody , NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure ,
6
6
UnderscoreExprLhsAssign ,
@@ -13,7 +13,6 @@ use rustc_ast::*;
13
13
use rustc_data_structures:: stack:: ensure_sufficient_stack;
14
14
use rustc_hir as hir;
15
15
use rustc_hir:: def:: { DefKind , Res } ;
16
- use rustc_middle:: span_bug;
17
16
use rustc_session:: errors:: report_lit_error;
18
17
use rustc_span:: source_map:: { respan, Spanned } ;
19
18
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -1028,51 +1027,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
1028
1027
fn_decl_span : Span ,
1029
1028
fn_arg_span : Span ,
1030
1029
) -> hir:: ExprKind < ' hir > {
1031
- let CoroutineKind :: Async { closure_id : inner_closure_id, .. } = coroutine_kind else {
1032
- span_bug ! ( fn_decl_span, "`async gen` and `gen` closures are not supported, yet" ) ;
1033
- } ;
1034
-
1035
1030
if let & ClosureBinder :: For { span, .. } = binder {
1036
1031
self . dcx ( ) . emit_err ( NotSupportedForLifetimeBinderAsyncClosure { span } ) ;
1037
1032
}
1038
1033
1039
1034
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
1040
1035
1041
- let outer_decl =
1042
- FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1043
-
1044
1036
let body = self . with_new_scopes ( fn_decl_span, |this| {
1045
- // FIXME(cramertj): allow `async` non-`move` closures with arguments.
1046
- if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
1047
- this. dcx ( ) . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
1048
- }
1049
-
1050
1037
// Transform `async |x: u8| -> X { ... }` into
1051
1038
// `|x: u8| || -> X { ... }`.
1052
- let body_id = this. lower_fn_body ( & outer_decl , |this| {
1039
+ let body_id = this. lower_body ( |this| {
1053
1040
let async_ret_ty = if let FnRetTy :: Ty ( ty) = & decl. output {
1054
1041
let itctx = ImplTraitContext :: Disallowed ( ImplTraitPosition :: AsyncBlock ) ;
1055
1042
Some ( hir:: FnRetTy :: Return ( this. lower_ty ( ty, & itctx) ) )
1056
1043
} else {
1057
1044
None
1058
1045
} ;
1059
1046
1060
- let async_body = this. make_desugared_coroutine_expr (
1061
- capture_clause,
1062
- inner_closure_id,
1063
- async_ret_ty,
1047
+ let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1048
+ decl,
1049
+ |this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
1064
1050
body. span ,
1065
- hir :: CoroutineDesugaring :: Async ,
1051
+ coroutine_kind ,
1066
1052
hir:: CoroutineSource :: Closure ,
1067
- |this| this . with_new_scopes ( fn_decl_span , |this| this . lower_expr_mut ( body ) ) ,
1053
+ async_ret_ty ,
1068
1054
) ;
1069
- let hir_id = this. lower_node_id ( inner_closure_id) ;
1055
+
1056
+ let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
1070
1057
this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
1071
- hir:: Expr { hir_id, kind : async_body, span : this. lower_span ( body. span ) }
1058
+
1059
+ ( parameters, expr)
1072
1060
} ) ;
1073
1061
body_id
1074
1062
} ) ;
1075
1063
1064
+ let outer_decl =
1065
+ FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1066
+
1076
1067
let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
1077
1068
// We need to lower the declaration outside the new scope, because we
1078
1069
// have to conserve the state of being inside a loop condition for the
0 commit comments