@@ -165,6 +165,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
165
165
if let Async :: Yes { closure_id, .. } = asyncness {
166
166
self . lower_expr_async_closure (
167
167
capture_clause,
168
+ e. id ,
168
169
closure_id,
169
170
decl,
170
171
body,
@@ -173,6 +174,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
173
174
} else {
174
175
self . lower_expr_closure (
175
176
capture_clause,
177
+ e. id ,
176
178
movability,
177
179
decl,
178
180
body,
@@ -604,6 +606,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
604
606
// `static |_task_context| -> <ret_ty> { body }`:
605
607
let generator_kind = hir:: ExprKind :: Closure {
606
608
capture_clause,
609
+ bound_generic_params : & [ ] ,
607
610
fn_decl,
608
611
body,
609
612
fn_decl_span : self . lower_span ( span) ,
@@ -828,6 +831,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
828
831
fn lower_expr_closure (
829
832
& mut self ,
830
833
capture_clause : CaptureBy ,
834
+ closure_id : NodeId ,
831
835
movability : Movability ,
832
836
decl : & FnDecl ,
833
837
body : & Expr ,
@@ -848,16 +852,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
848
852
( body_id, generator_option)
849
853
} ) ;
850
854
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
+ } )
861
868
}
862
869
863
870
fn generator_movability_for_fn (
@@ -897,6 +904,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
897
904
& mut self ,
898
905
capture_clause : CaptureBy ,
899
906
closure_id : NodeId ,
907
+ inner_closure_id : NodeId ,
900
908
decl : & FnDecl ,
901
909
body : & Expr ,
902
910
fn_decl_span : Span ,
@@ -927,7 +935,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
927
935
if let FnRetTy :: Ty ( ty) = & decl. output { Some ( ty. clone ( ) ) } else { None } ;
928
936
let async_body = this. make_async_expr (
929
937
capture_clause,
930
- closure_id ,
938
+ inner_closure_id ,
931
939
async_ret_ty,
932
940
body. span ,
933
941
hir:: AsyncGeneratorKind :: Closure ,
@@ -938,18 +946,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
938
946
body_id
939
947
} ) ;
940
948
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
+ } )
953
964
}
954
965
955
966
/// Destructure the LHS of complex assignments.
0 commit comments