@@ -2,8 +2,7 @@ use super::errors::{
2
2
AsyncCoroutinesNotSupported , AwaitOnlyInAsyncFnAndBlocks , BaseExpressionDoubleDot ,
3
3
ClosureCannotBeStatic , CoroutineTooManyParameters ,
4
4
FunctionalRecordUpdateDestructuringAssignment , InclusiveRangeWithNoEnd , MatchArmWithNoBody ,
5
- NeverPatternWithBody , NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure ,
6
- UnderscoreExprLhsAssign ,
5
+ NeverPatternWithBody , NeverPatternWithGuard , UnderscoreExprLhsAssign ,
7
6
} ;
8
7
use super :: ResolverAstLoweringExt ;
9
8
use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
@@ -1027,30 +1026,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
1027
1026
fn_decl_span : Span ,
1028
1027
fn_arg_span : Span ,
1029
1028
) -> hir:: ExprKind < ' hir > {
1030
- if let & ClosureBinder :: For { span, .. } = binder {
1031
- self . dcx ( ) . emit_err ( NotSupportedForLifetimeBinderAsyncClosure { span } ) ;
1032
- }
1033
-
1034
1029
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
1035
1030
1036
1031
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
+
1037
1035
// Transform `async |x: u8| -> X { ... }` into
1038
1036
// `|x: u8| || -> X { ... }`.
1039
1037
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
-
1047
1038
let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1048
- decl ,
1039
+ & inner_decl ,
1049
1040
|this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
1050
1041
body. span ,
1051
1042
coroutine_kind,
1052
1043
hir:: CoroutineSource :: Closure ,
1053
- async_ret_ty,
1054
1044
) ;
1055
1045
1056
1046
let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
@@ -1061,15 +1051,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1061
1051
body_id
1062
1052
} ) ;
1063
1053
1064
- let outer_decl =
1065
- FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1066
-
1067
1054
let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
1068
1055
// We need to lower the declaration outside the new scope, because we
1069
1056
// have to conserve the state of being inside a loop condition for the
1070
1057
// closure argument types.
1071
1058
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 ) ;
1073
1060
1074
1061
let c = self . arena . alloc ( hir:: Closure {
1075
1062
def_id : self . local_def_id ( closure_id) ,
@@ -1080,7 +1067,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1080
1067
body,
1081
1068
fn_decl_span : self . lower_span ( fn_decl_span) ,
1082
1069
fn_arg_span : Some ( self . lower_span ( fn_arg_span) ) ,
1083
- kind : hir:: ClosureKind :: Closure ,
1070
+ kind : hir:: ClosureKind :: CoroutineClosure ( hir :: CoroutineDesugaring :: Async ) ,
1084
1071
constness : hir:: Constness :: NotConst ,
1085
1072
} ) ;
1086
1073
hir:: ExprKind :: Closure ( c)
0 commit comments