@@ -77,6 +77,13 @@ impl TypeOrConstParamData {
7777 }
7878 }
7979
80+ pub fn const_param ( & self ) -> Option < & ConstParamData > {
81+ match self {
82+ TypeOrConstParamData :: TypeParamData ( _) => None ,
83+ TypeOrConstParamData :: ConstParamData ( x) => Some ( x) ,
84+ }
85+ }
86+
8087 pub fn is_trait_self ( & self ) -> bool {
8188 match self {
8289 TypeOrConstParamData :: TypeParamData ( x) => {
@@ -92,7 +99,7 @@ impl_from!(TypeParamData, ConstParamData for TypeOrConstParamData);
9299/// Data about the generic parameters of a function, struct, impl, etc.
93100#[ derive( Clone , PartialEq , Eq , Debug , Default , Hash ) ]
94101pub struct GenericParams {
95- pub types : Arena < TypeOrConstParamData > ,
102+ pub tocs : Arena < TypeOrConstParamData > ,
96103 pub lifetimes : Arena < LifetimeParamData > ,
97104 pub where_predicates : Vec < WherePredicate > ,
98105}
@@ -131,7 +138,13 @@ impl GenericParams {
131138 pub fn type_iter < ' a > (
132139 & ' a self ,
133140 ) -> impl Iterator < Item = ( Idx < TypeOrConstParamData > , & TypeParamData ) > {
134- self . types . iter ( ) . filter_map ( |x| x. 1 . type_param ( ) . map ( |y| ( x. 0 , y) ) )
141+ self . tocs . iter ( ) . filter_map ( |x| x. 1 . type_param ( ) . map ( |y| ( x. 0 , y) ) )
142+ }
143+
144+ pub fn toc_iter < ' a > (
145+ & ' a self ,
146+ ) -> impl Iterator < Item = ( Idx < TypeOrConstParamData > , & TypeOrConstParamData ) > {
147+ self . tocs . iter ( )
135148 }
136149
137150 pub ( crate ) fn generic_params_query (
@@ -238,7 +251,7 @@ impl GenericParams {
238251 default,
239252 provenance : TypeParamProvenance :: TypeParamList ,
240253 } ;
241- self . types . alloc ( param. into ( ) ) ;
254+ self . tocs . alloc ( param. into ( ) ) ;
242255 let type_ref = TypeRef :: Path ( name. into ( ) ) ;
243256 self . fill_bounds ( lower_ctx, & type_param, Either :: Left ( type_ref) ) ;
244257 }
@@ -248,7 +261,7 @@ impl GenericParams {
248261 . ty ( )
249262 . map_or ( TypeRef :: Error , |it| TypeRef :: from_ast ( lower_ctx, it) ) ;
250263 let param = ConstParamData { name, ty : Interned :: new ( ty) } ;
251- self . types . alloc ( param. into ( ) ) ;
264+ self . tocs . alloc ( param. into ( ) ) ;
252265 }
253266 }
254267 }
@@ -335,7 +348,7 @@ impl GenericParams {
335348 default : None ,
336349 provenance : TypeParamProvenance :: ArgumentImplTrait ,
337350 } ;
338- let param_id = self . types . alloc ( param. into ( ) ) ;
351+ let param_id = self . tocs . alloc ( param. into ( ) ) ;
339352 for bound in bounds {
340353 self . where_predicates . push ( WherePredicate :: TypeBound {
341354 target : WherePredicateTypeTarget :: TypeOrConstParam ( param_id) ,
@@ -359,27 +372,27 @@ impl GenericParams {
359372 }
360373
361374 pub ( crate ) fn shrink_to_fit ( & mut self ) {
362- let Self { lifetimes, types, where_predicates } = self ;
375+ let Self { lifetimes, tocs : types, where_predicates } = self ;
363376 lifetimes. shrink_to_fit ( ) ;
364377 types. shrink_to_fit ( ) ;
365378 where_predicates. shrink_to_fit ( ) ;
366379 }
367380
368381 pub fn find_type_by_name ( & self , name : & Name ) -> Option < LocalTypeOrConstParamId > {
369- self . types
382+ self . tocs
370383 . iter ( )
371384 . filter ( |x| matches ! ( x. 1 , TypeOrConstParamData :: TypeParamData ( _) ) )
372385 . find_map ( |( id, p) | if p. name ( ) . as_ref ( ) == Some ( & name) { Some ( id) } else { None } )
373386 }
374387
375388 pub fn find_type_or_const_by_name ( & self , name : & Name ) -> Option < LocalTypeOrConstParamId > {
376- self . types
389+ self . tocs
377390 . iter ( )
378391 . find_map ( |( id, p) | if p. name ( ) . as_ref ( ) == Some ( & name) { Some ( id) } else { None } )
379392 }
380393
381394 pub fn find_trait_self_param ( & self ) -> Option < LocalTypeOrConstParamId > {
382- self . types . iter ( ) . find_map ( |( id, p) | {
395+ self . tocs . iter ( ) . find_map ( |( id, p) | {
383396 if let TypeOrConstParamData :: TypeParamData ( p) = p {
384397 if p. provenance == TypeParamProvenance :: TraitSelf {
385398 Some ( id)
@@ -438,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
438451 db : & dyn DefDatabase ,
439452 ) -> InFile < ArenaMap < LocalTypeOrConstParamId , Self :: Value > > {
440453 let generic_params = db. generic_params ( * self ) ;
441- let mut idx_iter = generic_params. types . iter ( ) . map ( |( idx, _) | idx) ;
454+ let mut idx_iter = generic_params. tocs . iter ( ) . map ( |( idx, _) | idx) ;
442455
443456 let ( file_id, generic_params_list) = file_id_and_params_of ( * self , db) ;
444457
@@ -492,7 +505,7 @@ impl ChildBySource for GenericDefId {
492505 }
493506
494507 let generic_params = db. generic_params ( * self ) ;
495- let mut toc_idx_iter = generic_params. types . iter ( ) . map ( |( idx, _) | idx) ;
508+ let mut toc_idx_iter = generic_params. tocs . iter ( ) . map ( |( idx, _) | idx) ;
496509 let lts_idx_iter = generic_params. lifetimes . iter ( ) . map ( |( idx, _) | idx) ;
497510
498511 // For traits the first type index is `Self`, skip it.
0 commit comments