@@ -223,6 +223,12 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
223
223
}
224
224
225
225
/// Obtain the list of lifetimes parameters to add to an item.
226
+ ///
227
+ /// Extra lifetime parameters should only be added in places that can appear
228
+ /// as a `binder` in `LifetimeRes`.
229
+ ///
230
+ /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
231
+ /// should appear at the enclosing `PolyTraitRef`.
226
232
fn take_extra_lifetime_params ( & mut self , id : NodeId ) -> Vec < ( Ident , NodeId , LifetimeRes ) > {
227
233
self . extra_lifetime_params_map . remove ( & id) . unwrap_or_default ( )
228
234
}
@@ -721,6 +727,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
721
727
}
722
728
723
729
/// Converts a lifetime into a new generic parameter.
730
+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
724
731
fn lifetime_res_to_generic_param (
725
732
& mut self ,
726
733
ident : Ident ,
@@ -787,11 +794,25 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
787
794
/// Register a binder to be ignored for lifetime capture.
788
795
#[ tracing:: instrument( level = "debug" , skip( self , f) ) ]
789
796
#[ inline]
790
- fn with_lifetime_binder < T > ( & mut self , binder : NodeId , f : impl FnOnce ( & mut Self ) -> T ) -> T {
797
+ fn with_lifetime_binder < T > (
798
+ & mut self ,
799
+ binder : NodeId ,
800
+ generic_params : & [ GenericParam ] ,
801
+ f : impl FnOnce ( & mut Self , & ' hir [ hir:: GenericParam < ' hir > ] ) -> T ,
802
+ ) -> T {
803
+ let mut generic_params: Vec < _ > = self . lower_generic_params_mut ( generic_params) . collect ( ) ;
804
+ let extra_lifetimes = self . resolver . take_extra_lifetime_params ( binder) ;
805
+ debug ! ( ?extra_lifetimes) ;
806
+ generic_params. extend ( extra_lifetimes. into_iter ( ) . filter_map ( |( ident, node_id, res) | {
807
+ self . lifetime_res_to_generic_param ( ident, node_id, res)
808
+ } ) ) ;
809
+ let generic_params = self . arena . alloc_from_iter ( generic_params) ;
810
+ debug ! ( ?generic_params) ;
811
+
791
812
if let Some ( ctxt) = & mut self . captured_lifetimes {
792
813
ctxt. binders_to_ignore . insert ( binder) ;
793
814
}
794
- let ret = f ( self ) ;
815
+ let ret = f ( self , generic_params ) ;
795
816
if let Some ( ctxt) = & mut self . captured_lifetimes {
796
817
ctxt. binders_to_ignore . remove ( & binder) ;
797
818
}
@@ -1188,15 +1209,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1188
1209
let lifetime = self . lower_lifetime ( & region) ;
1189
1210
hir:: TyKind :: Rptr ( lifetime, self . lower_mt ( mt, itctx) )
1190
1211
}
1191
- TyKind :: BareFn ( ref f) => self . with_lifetime_binder ( t. id , |this| {
1192
- hir:: TyKind :: BareFn ( this. arena . alloc ( hir:: BareFnTy {
1193
- generic_params : this. lower_generic_params ( & f. generic_params ) ,
1194
- unsafety : this. lower_unsafety ( f. unsafety ) ,
1195
- abi : this. lower_extern ( f. ext ) ,
1196
- decl : this. lower_fn_decl ( & f. decl , None , FnDeclKind :: Pointer , None ) ,
1197
- param_names : this. lower_fn_params_to_names ( & f. decl ) ,
1198
- } ) )
1199
- } ) ,
1212
+ TyKind :: BareFn ( ref f) => {
1213
+ self . with_lifetime_binder ( t. id , & f. generic_params , |this, generic_params| {
1214
+ hir:: TyKind :: BareFn ( this. arena . alloc ( hir:: BareFnTy {
1215
+ generic_params,
1216
+ unsafety : this. lower_unsafety ( f. unsafety ) ,
1217
+ abi : this. lower_extern ( f. ext ) ,
1218
+ decl : this. lower_fn_decl ( & f. decl , None , FnDeclKind :: Pointer , None ) ,
1219
+ param_names : this. lower_fn_params_to_names ( & f. decl ) ,
1220
+ } ) )
1221
+ } )
1222
+ }
1200
1223
TyKind :: Never => hir:: TyKind :: Never ,
1201
1224
TyKind :: Tup ( ref tys) => hir:: TyKind :: Tup (
1202
1225
self . arena . alloc_from_iter ( tys. iter ( ) . map ( |ty| self . lower_ty_direct ( ty, itctx) ) ) ,
@@ -1963,13 +1986,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1963
1986
p : & PolyTraitRef ,
1964
1987
itctx : ImplTraitContext ,
1965
1988
) -> hir:: PolyTraitRef < ' hir > {
1966
- let bound_generic_params = self . lower_generic_params ( & p. bound_generic_params ) ;
1967
-
1968
- let trait_ref = self . with_lifetime_binder ( p. trait_ref . ref_id , |this| {
1969
- this. lower_trait_ref ( & p. trait_ref , itctx)
1970
- } ) ;
1971
-
1972
- hir:: PolyTraitRef { bound_generic_params, trait_ref, span : self . lower_span ( p. span ) }
1989
+ self . with_lifetime_binder (
1990
+ p. trait_ref . ref_id ,
1991
+ & p. bound_generic_params ,
1992
+ |this, bound_generic_params| {
1993
+ let trait_ref = this. lower_trait_ref ( & p. trait_ref , itctx) ;
1994
+ hir:: PolyTraitRef { bound_generic_params, trait_ref, span : this. lower_span ( p. span ) }
1995
+ } ,
1996
+ )
1973
1997
}
1974
1998
1975
1999
fn lower_mt ( & mut self , mt : & MutTy , itctx : ImplTraitContext ) -> hir:: MutTy < ' hir > {
0 commit comments