@@ -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 } ;
@@ -1027,30 +1026,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
10271026 fn_decl_span : Span ,
10281027 fn_arg_span : Span ,
10291028 ) -> hir:: ExprKind < ' hir > {
1030- if let & ClosureBinder :: For { span, .. } = binder {
1031- self . dcx ( ) . emit_err ( NotSupportedForLifetimeBinderAsyncClosure { span } ) ;
1032- }
1033-
10341029 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
10351030
10361031 let body = self . with_new_scopes ( fn_decl_span, |this| {
1032+ let inner_decl =
1033+ FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1034+
10371035 // Transform `async |x: u8| -> X { ... }` into
10381036 // `|x: u8| || -> X { ... }`.
10391037 let body_id = this. lower_body ( |this| {
1040- let async_ret_ty = if let FnRetTy :: Ty ( ty) = & decl. output {
1041- let itctx = ImplTraitContext :: Disallowed ( ImplTraitPosition :: AsyncBlock ) ;
1042- Some ( hir:: FnRetTy :: Return ( this. lower_ty ( ty, & itctx) ) )
1043- } else {
1044- None
1045- } ;
1046-
10471038 let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1048- decl ,
1039+ & inner_decl ,
10491040 |this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
10501041 body. span ,
10511042 coroutine_kind,
10521043 hir:: CoroutineSource :: Closure ,
1053- async_ret_ty,
10541044 ) ;
10551045
10561046 let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
@@ -1061,15 +1051,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10611051 body_id
10621052 } ) ;
10631053
1064- let outer_decl =
1065- FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1066-
10671054 let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
10681055 // We need to lower the declaration outside the new scope, because we
10691056 // have to conserve the state of being inside a loop condition for the
10701057 // closure argument types.
10711058 let fn_decl =
1072- self . lower_fn_decl ( & outer_decl , closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
1059+ self . lower_fn_decl ( & decl , closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
10731060
10741061 let c = self . arena . alloc ( hir:: Closure {
10751062 def_id : self . local_def_id ( closure_id) ,
@@ -1080,7 +1067,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10801067 body,
10811068 fn_decl_span : self . lower_span ( fn_decl_span) ,
10821069 fn_arg_span : Some ( self . lower_span ( fn_arg_span) ) ,
1083- kind : hir:: ClosureKind :: Closure ,
1070+ kind : hir:: ClosureKind :: CoroutineClosure ( hir :: CoroutineDesugaring :: Async ) ,
10841071 constness : hir:: Constness :: NotConst ,
10851072 } ) ;
10861073 hir:: ExprKind :: Closure ( c)
0 commit comments