@@ -83,6 +83,16 @@ impl<'db> SingleGenerics<'db> {
8383 . map ( move |( local_id, data) | ( LifetimeParamId { parent, local_id } , data) )
8484 }
8585
86+ fn iter_late_bound_lifetimes (
87+ & self ,
88+ consider_late_bound : bool ,
89+ ) -> impl Iterator < Item = ( LifetimeParamId , & ' db LifetimeParamData ) > {
90+ let parent = self . def ;
91+ self . params . iter_late_bound_lt ( ) . filter_map ( move |( local_id, data) | {
92+ consider_late_bound. then_some ( ( LifetimeParamId { parent, local_id } , data) )
93+ } )
94+ }
95+
8696 pub ( crate ) fn iter_type_or_consts (
8797 & self ,
8898 ) -> impl Iterator < Item = ( TypeOrConstParamId , & ' db TypeOrConstParamData ) > {
@@ -118,23 +128,33 @@ impl<'db> SingleGenerics<'db> {
118128 ( trait_self, iter)
119129 }
120130
121- pub ( crate ) fn iter ( & self ) -> impl Iterator < Item = ( GenericParamId , GenericParamDataRef < ' db > ) > {
122- let lifetimes = self . iter_lifetimes ( ) . map ( |( id, data) | {
131+ pub ( crate ) fn iter (
132+ & self ,
133+ consider_late_bound : bool ,
134+ ) -> impl Iterator < Item = ( GenericParamId , GenericParamDataRef < ' db > ) > {
135+ let lifetime_map = |( id, data) | {
123136 ( GenericParamId :: LifetimeParamId ( id) , GenericParamDataRef :: LifetimeParamData ( data) )
124- } ) ;
137+ } ;
138+ let lifetimes = self . iter_lifetimes ( ) . map ( lifetime_map) ;
139+ let late_bound_lifetimes =
140+ self . iter_late_bound_lifetimes ( consider_late_bound) . map ( lifetime_map) ;
141+
125142 let ( trait_self, type_and_consts) = self . trait_self_and_others ( ) ;
126- trait_self. into_iter ( ) . chain ( lifetimes) . chain ( type_and_consts)
143+ trait_self. into_iter ( ) . chain ( lifetimes) . chain ( type_and_consts) . chain ( late_bound_lifetimes )
127144 }
128145
129146 pub ( crate ) fn iter_with_idx (
130147 & self ,
131148 ) -> impl Iterator < Item = ( u32 , GenericParamId , GenericParamDataRef < ' db > ) > {
132- std:: iter:: zip ( self . preceding_params_len .., self . iter ( ) )
149+ std:: iter:: zip ( self . preceding_params_len .., self . iter ( false ) )
133150 . map ( |( index, ( id, data) ) | ( index, id, data) )
134151 }
135152
136- pub ( crate ) fn iter_id ( & self ) -> impl Iterator < Item = GenericParamId > {
137- self . iter ( ) . map ( |( id, _) | id)
153+ pub ( crate ) fn iter_id (
154+ & self ,
155+ consider_late_bound : bool ,
156+ ) -> impl Iterator < Item = GenericParamId > {
157+ self . iter ( consider_late_bound) . map ( |( id, _) | id)
138158 }
139159
140160 pub ( crate ) fn iter_late_bound (
@@ -149,6 +169,18 @@ impl<'db> SingleGenerics<'db> {
149169 )
150170 } )
151171 }
172+
173+ pub ( crate ) fn type_or_const_param ( & self , param_id : TypeParamId ) -> GenericParamDataRef < ' db > {
174+ let data = & self . params [ param_id. local_id ( ) ] ;
175+ match data {
176+ TypeOrConstParamData :: TypeParamData ( type_param_data) => {
177+ GenericParamDataRef :: TypeParamData ( type_param_data)
178+ }
179+ TypeOrConstParamData :: ConstParamData ( const_param_data) => {
180+ GenericParamDataRef :: ConstParamData ( const_param_data)
181+ }
182+ }
183+ }
152184}
153185
154186impl < ' db > Generics < ' db > {
@@ -182,7 +214,7 @@ impl<'db> Generics<'db> {
182214 pub ( crate ) fn iter_self (
183215 & self ,
184216 ) -> impl Iterator < Item = ( GenericParamId , GenericParamDataRef < ' db > ) > {
185- self . owner ( ) . iter ( )
217+ self . owner ( ) . iter ( false )
186218 }
187219
188220 pub ( crate ) fn iter_self_with_idx (
@@ -198,7 +230,7 @@ impl<'db> Generics<'db> {
198230 }
199231
200232 pub ( crate ) fn iter_parent_id ( & self ) -> impl Iterator < Item = GenericParamId > {
201- self . parent ( ) . into_iter ( ) . flat_map ( |parent| parent. iter_id ( ) )
233+ self . parent ( ) . into_iter ( ) . flat_map ( move |parent| parent. iter_id ( false ) )
202234 }
203235
204236 pub ( crate ) fn iter_self_type_or_consts (
@@ -208,13 +240,18 @@ impl<'db> Generics<'db> {
208240 }
209241
210242 /// Iterate over the parent params followed by self params.
211- #[ cfg( test) ]
212- pub ( crate ) fn iter ( & self ) -> impl Iterator < Item = ( GenericParamId , GenericParamDataRef < ' _ > ) > {
213- self . iter_owners ( ) . flat_map ( |owner| owner. iter ( ) )
243+ pub ( crate ) fn iter (
244+ & self ,
245+ consider_late_bound : bool ,
246+ ) -> impl Iterator < Item = ( GenericParamId , GenericParamDataRef < ' db > ) > {
247+ self . iter_owners ( ) . flat_map ( move |owner| owner. iter ( consider_late_bound) )
214248 }
215249
216- pub ( crate ) fn iter_id ( & self ) -> impl Iterator < Item = GenericParamId > {
217- self . iter_owners ( ) . flat_map ( |owner| owner. iter_id ( ) )
250+ pub ( crate ) fn iter_id (
251+ & self ,
252+ consider_late_bound : bool ,
253+ ) -> impl Iterator < Item = GenericParamId > {
254+ self . iter_owners ( ) . flat_map ( move |owner| owner. iter_id ( consider_late_bound) )
218255 }
219256
220257 /// Returns total number of generic parameters in scope, including those from parent.
@@ -298,16 +335,19 @@ impl<'db> Generics<'db> {
298335 pub ( crate ) fn lifetime_param_idx (
299336 & self ,
300337 param : LifetimeParamId ,
301- is_opaque_lowering : bool ,
338+ is_lowering_impl_trait_bounds : bool ,
302339 ) -> ( u32 , bool ) {
303340 let owner = self . find_owner ( param. parent ) ;
304- if let Some ( late_bound_idx) =
305- owner. params . late_bound_lifetime_idx ( & param. local_id , is_opaque_lowering)
306- {
341+ if is_lowering_impl_trait_bounds {
342+ let idx = self . opaque_lifetime_idx ( param) ;
343+ return ( owner. preceding_params_len + ( idx as u32 ) , false ) ;
344+ }
345+
346+ if let Some ( late_bound_idx) = owner. params . late_bound_lifetime_idx ( & param. local_id ) {
307347 return ( late_bound_idx as u32 , true ) ;
308348 }
309349 let has_trait_self = matches ! ( owner. def, GenericDefId :: TraitId ( _) ) ;
310- match owner. params . early_bound_lifetime_idx ( & param. local_id , is_opaque_lowering ) {
350+ match owner. params . early_bound_lifetime_idx ( & param. local_id ) {
311351 Some ( idx) => {
312352 ( owner. preceding_params_len + u32:: from ( has_trait_self) + ( idx as u32 ) , false )
313353 }
@@ -326,6 +366,22 @@ impl<'db> Generics<'db> {
326366 } ) ;
327367 Generics { chain }
328368 }
369+
370+ pub ( crate ) fn type_or_const_param ( & self , param_id : TypeParamId ) -> GenericParamDataRef < ' db > {
371+ self . find_owner ( param_id. parent ( ) ) . type_or_const_param ( param_id)
372+ }
373+
374+ fn opaque_lifetime_idx ( & self , param : LifetimeParamId ) -> usize {
375+ self . find_owner ( param. parent )
376+ . iter_id ( true )
377+ . position ( |id| {
378+ let GenericParamId :: LifetimeParamId ( id) = id else {
379+ return false ;
380+ } ;
381+ param == id
382+ } )
383+ . unwrap ( )
384+ }
329385}
330386
331387pub ( crate ) struct ProvenanceSplit {
0 commit comments