@@ -165,6 +165,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
165165 if let Async :: Yes { closure_id, .. } = asyncness {
166166 self . lower_expr_async_closure (
167167 capture_clause,
168+ e. id ,
168169 closure_id,
169170 decl,
170171 body,
@@ -173,6 +174,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
173174 } else {
174175 self . lower_expr_closure (
175176 capture_clause,
177+ e. id ,
176178 movability,
177179 decl,
178180 body,
@@ -604,6 +606,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
604606 // `static |_task_context| -> <ret_ty> { body }`:
605607 let generator_kind = hir:: ExprKind :: Closure {
606608 capture_clause,
609+ bound_generic_params : & [ ] ,
607610 fn_decl,
608611 body,
609612 fn_decl_span : self . lower_span ( span) ,
@@ -828,6 +831,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
828831 fn lower_expr_closure (
829832 & mut self ,
830833 capture_clause : CaptureBy ,
834+ closure_id : NodeId ,
831835 movability : Movability ,
832836 decl : & FnDecl ,
833837 body : & Expr ,
@@ -848,16 +852,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
848852 ( body_id, generator_option)
849853 } ) ;
850854
851- // Lower outside new scope to preserve `is_in_loop_condition`.
852- let fn_decl = self . lower_fn_decl ( decl, None , FnDeclKind :: Closure , None ) ;
853-
854- hir:: ExprKind :: Closure {
855- capture_clause,
856- fn_decl,
857- body,
858- fn_decl_span : self . lower_span ( fn_decl_span) ,
859- movability : generator_option,
860- }
855+ self . with_lifetime_binder ( closure_id, & [ ] , |this, bound_generic_params| {
856+ // Lower outside new scope to preserve `is_in_loop_condition`.
857+ let fn_decl = this. lower_fn_decl ( decl, None , FnDeclKind :: Closure , None ) ;
858+
859+ hir:: ExprKind :: Closure {
860+ capture_clause,
861+ bound_generic_params,
862+ fn_decl,
863+ body,
864+ fn_decl_span : this. lower_span ( fn_decl_span) ,
865+ movability : generator_option,
866+ }
867+ } )
861868 }
862869
863870 fn generator_movability_for_fn (
@@ -897,6 +904,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
897904 & mut self ,
898905 capture_clause : CaptureBy ,
899906 closure_id : NodeId ,
907+ inner_closure_id : NodeId ,
900908 decl : & FnDecl ,
901909 body : & Expr ,
902910 fn_decl_span : Span ,
@@ -927,7 +935,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
927935 if let FnRetTy :: Ty ( ty) = & decl. output { Some ( ty. clone ( ) ) } else { None } ;
928936 let async_body = this. make_async_expr (
929937 capture_clause,
930- closure_id ,
938+ inner_closure_id ,
931939 async_ret_ty,
932940 body. span ,
933941 hir:: AsyncGeneratorKind :: Closure ,
@@ -938,18 +946,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
938946 body_id
939947 } ) ;
940948
941- // We need to lower the declaration outside the new scope, because we
942- // have to conserve the state of being inside a loop condition for the
943- // closure argument types.
944- let fn_decl = self . lower_fn_decl ( & outer_decl, None , FnDeclKind :: Closure , None ) ;
945-
946- hir:: ExprKind :: Closure {
947- capture_clause,
948- fn_decl,
949- body,
950- fn_decl_span : self . lower_span ( fn_decl_span) ,
951- movability : None ,
952- }
949+ self . with_lifetime_binder ( closure_id, & [ ] , |this, bound_generic_params| {
950+ // We need to lower the declaration outside the new scope, because we
951+ // have to conserve the state of being inside a loop condition for the
952+ // closure argument types.
953+ let fn_decl = this. lower_fn_decl ( & outer_decl, None , FnDeclKind :: Closure , None ) ;
954+
955+ hir:: ExprKind :: Closure {
956+ capture_clause,
957+ bound_generic_params,
958+ fn_decl,
959+ body,
960+ fn_decl_span : this. lower_span ( fn_decl_span) ,
961+ movability : None ,
962+ }
963+ } )
953964 }
954965
955966 /// Destructure the LHS of complex assignments.
0 commit comments