@@ -608,14 +608,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
608
608
} ) ;
609
609
610
610
// `static |_task_context| -> <ret_ty> { body }`:
611
- let generator_kind = hir:: ExprKind :: Closure {
612
- binder : & hir:: ClosureBinder :: Default ,
613
- capture_clause,
614
- bound_generic_params : & [ ] ,
615
- fn_decl,
616
- body,
617
- fn_decl_span : self . lower_span ( span) ,
618
- movability : Some ( hir:: Movability :: Static ) ,
611
+ let generator_kind = {
612
+ let c = self . arena . alloc ( hir:: Closure {
613
+ binder : hir:: ClosureBinder :: Default ,
614
+ capture_clause,
615
+ bound_generic_params : & [ ] ,
616
+ fn_decl,
617
+ body,
618
+ fn_decl_span : self . lower_span ( span) ,
619
+ movability : Some ( hir:: Movability :: Static ) ,
620
+ } ) ;
621
+
622
+ hir:: ExprKind :: Closure ( c)
619
623
} ;
620
624
let generator = hir:: Expr {
621
625
hir_id : self . lower_node_id ( closure_node_id) ,
@@ -864,15 +868,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
864
868
// Lower outside new scope to preserve `is_in_loop_condition`.
865
869
let fn_decl = this. lower_fn_decl ( decl, None , FnDeclKind :: Closure , None ) ;
866
870
867
- hir:: ExprKind :: Closure {
871
+ let c = self . arena . alloc ( hir:: Closure {
868
872
binder : binder_clause,
869
873
capture_clause,
870
874
bound_generic_params,
871
875
fn_decl,
872
876
body : body_id,
873
877
fn_decl_span : this. lower_span ( fn_decl_span) ,
874
878
movability : generator_option,
875
- }
879
+ } ) ;
880
+
881
+ hir:: ExprKind :: Closure ( c)
876
882
} )
877
883
}
878
884
@@ -917,7 +923,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
917
923
fn lower_closure_binder < ' c > (
918
924
& mut self ,
919
925
binder : & ' c ClosureBinder ,
920
- ) -> ( & ' hir hir:: ClosureBinder , & ' c [ GenericParam ] ) {
926
+ ) -> ( hir:: ClosureBinder , & ' c [ GenericParam ] ) {
921
927
let ( binder, params) = match binder {
922
928
ClosureBinder :: NotPresent => ( hir:: ClosureBinder :: Default , & [ ] [ ..] ) ,
923
929
& ClosureBinder :: For { span, ref generic_params } => {
@@ -926,7 +932,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
926
932
}
927
933
} ;
928
934
929
- ( self . arena . alloc ( binder) , params)
935
+ ( binder, params)
930
936
}
931
937
932
938
fn lower_expr_async_closure (
@@ -991,15 +997,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
991
997
// closure argument types.
992
998
let fn_decl = this. lower_fn_decl ( & outer_decl, None , FnDeclKind :: Closure , None ) ;
993
999
994
- hir:: ExprKind :: Closure {
1000
+ let c = self . arena . alloc ( hir:: Closure {
995
1001
binder : binder_clause,
996
1002
capture_clause,
997
1003
bound_generic_params,
998
1004
fn_decl,
999
1005
body,
1000
1006
fn_decl_span : this. lower_span ( fn_decl_span) ,
1001
1007
movability : None ,
1002
- }
1008
+ } ) ;
1009
+ hir:: ExprKind :: Closure ( c)
1003
1010
} )
1004
1011
}
1005
1012
0 commit comments