@@ -2,8 +2,7 @@ use super::errors::{
22 AsyncCoroutinesNotSupported , AwaitOnlyInAsyncFnAndBlocks , BaseExpressionDoubleDot ,
33 ClosureCannotBeStatic , CoroutineTooManyParameters ,
44 FunctionalRecordUpdateDestructuringAssignment , InclusiveRangeWithNoEnd , MatchArmWithNoBody ,
5- NeverPatternWithBody , NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure ,
6- UnderscoreExprLhsAssign ,
5+ NeverPatternWithBody , NeverPatternWithGuard , UnderscoreExprLhsAssign ,
76} ;
87use super :: ResolverAstLoweringExt ;
98use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
@@ -1026,30 +1025,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
10261025 fn_decl_span : Span ,
10271026 fn_arg_span : Span ,
10281027 ) -> hir:: ExprKind < ' hir > {
1029- if let & ClosureBinder :: For { span, .. } = binder {
1030- self . dcx ( ) . emit_err ( NotSupportedForLifetimeBinderAsyncClosure { span } ) ;
1031- }
1032-
10331028 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
10341029
10351030 let body = self . with_new_scopes ( fn_decl_span, |this| {
1031+ let inner_decl =
1032+ FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1033+
10361034 // Transform `async |x: u8| -> X { ... }` into
10371035 // `|x: u8| || -> X { ... }`.
10381036 let body_id = this. lower_body ( |this| {
1039- let async_ret_ty = if let FnRetTy :: Ty ( ty) = & decl. output {
1040- let itctx = ImplTraitContext :: Disallowed ( ImplTraitPosition :: AsyncBlock ) ;
1041- Some ( hir:: FnRetTy :: Return ( this. lower_ty ( ty, & itctx) ) )
1042- } else {
1043- None
1044- } ;
1045-
10461037 let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1047- decl ,
1038+ & inner_decl ,
10481039 |this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
10491040 body. span ,
10501041 coroutine_kind,
10511042 hir:: CoroutineSource :: Closure ,
1052- async_ret_ty,
10531043 ) ;
10541044
10551045 let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
@@ -1060,15 +1050,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10601050 body_id
10611051 } ) ;
10621052
1063- let outer_decl =
1064- FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1065-
10661053 let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
10671054 // We need to lower the declaration outside the new scope, because we
10681055 // have to conserve the state of being inside a loop condition for the
10691056 // closure argument types.
10701057 let fn_decl =
1071- self . lower_fn_decl ( & outer_decl , closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
1058+ self . lower_fn_decl ( & decl , closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
10721059
10731060 let c = self . arena . alloc ( hir:: Closure {
10741061 def_id : self . local_def_id ( closure_id) ,
@@ -1079,7 +1066,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10791066 body,
10801067 fn_decl_span : self . lower_span ( fn_decl_span) ,
10811068 fn_arg_span : Some ( self . lower_span ( fn_arg_span) ) ,
1082- kind : hir:: ClosureKind :: Closure ,
1069+ kind : hir:: ClosureKind :: CoroutineClosure ( hir :: CoroutineDesugaring :: Async ) ,
10831070 constness : hir:: Constness :: NotConst ,
10841071 } ) ;
10851072 hir:: ExprKind :: Closure ( c)
0 commit comments