@@ -77,6 +77,13 @@ impl TypeOrConstParamData {
77
77
}
78
78
}
79
79
80
+ pub fn const_param ( & self ) -> Option < & ConstParamData > {
81
+ match self {
82
+ TypeOrConstParamData :: TypeParamData ( _) => None ,
83
+ TypeOrConstParamData :: ConstParamData ( x) => Some ( x) ,
84
+ }
85
+ }
86
+
80
87
pub fn is_trait_self ( & self ) -> bool {
81
88
match self {
82
89
TypeOrConstParamData :: TypeParamData ( x) => {
@@ -92,7 +99,7 @@ impl_from!(TypeParamData, ConstParamData for TypeOrConstParamData);
92
99
/// Data about the generic parameters of a function, struct, impl, etc.
93
100
#[ derive( Clone , PartialEq , Eq , Debug , Default , Hash ) ]
94
101
pub struct GenericParams {
95
- pub types : Arena < TypeOrConstParamData > ,
102
+ pub tocs : Arena < TypeOrConstParamData > ,
96
103
pub lifetimes : Arena < LifetimeParamData > ,
97
104
pub where_predicates : Vec < WherePredicate > ,
98
105
}
@@ -131,7 +138,13 @@ impl GenericParams {
131
138
pub fn type_iter < ' a > (
132
139
& ' a self ,
133
140
) -> 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 ( )
135
148
}
136
149
137
150
pub ( crate ) fn generic_params_query (
@@ -238,7 +251,7 @@ impl GenericParams {
238
251
default,
239
252
provenance : TypeParamProvenance :: TypeParamList ,
240
253
} ;
241
- self . types . alloc ( param. into ( ) ) ;
254
+ self . tocs . alloc ( param. into ( ) ) ;
242
255
let type_ref = TypeRef :: Path ( name. into ( ) ) ;
243
256
self . fill_bounds ( lower_ctx, & type_param, Either :: Left ( type_ref) ) ;
244
257
}
@@ -248,7 +261,7 @@ impl GenericParams {
248
261
. ty ( )
249
262
. map_or ( TypeRef :: Error , |it| TypeRef :: from_ast ( lower_ctx, it) ) ;
250
263
let param = ConstParamData { name, ty : Interned :: new ( ty) } ;
251
- self . types . alloc ( param. into ( ) ) ;
264
+ self . tocs . alloc ( param. into ( ) ) ;
252
265
}
253
266
}
254
267
}
@@ -335,7 +348,7 @@ impl GenericParams {
335
348
default : None ,
336
349
provenance : TypeParamProvenance :: ArgumentImplTrait ,
337
350
} ;
338
- let param_id = self . types . alloc ( param. into ( ) ) ;
351
+ let param_id = self . tocs . alloc ( param. into ( ) ) ;
339
352
for bound in bounds {
340
353
self . where_predicates . push ( WherePredicate :: TypeBound {
341
354
target : WherePredicateTypeTarget :: TypeOrConstParam ( param_id) ,
@@ -359,27 +372,27 @@ impl GenericParams {
359
372
}
360
373
361
374
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 ;
363
376
lifetimes. shrink_to_fit ( ) ;
364
377
types. shrink_to_fit ( ) ;
365
378
where_predicates. shrink_to_fit ( ) ;
366
379
}
367
380
368
381
pub fn find_type_by_name ( & self , name : & Name ) -> Option < LocalTypeOrConstParamId > {
369
- self . types
382
+ self . tocs
370
383
. iter ( )
371
384
. filter ( |x| matches ! ( x. 1 , TypeOrConstParamData :: TypeParamData ( _) ) )
372
385
. find_map ( |( id, p) | if p. name ( ) . as_ref ( ) == Some ( & name) { Some ( id) } else { None } )
373
386
}
374
387
375
388
pub fn find_type_or_const_by_name ( & self , name : & Name ) -> Option < LocalTypeOrConstParamId > {
376
- self . types
389
+ self . tocs
377
390
. iter ( )
378
391
. find_map ( |( id, p) | if p. name ( ) . as_ref ( ) == Some ( & name) { Some ( id) } else { None } )
379
392
}
380
393
381
394
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) | {
383
396
if let TypeOrConstParamData :: TypeParamData ( p) = p {
384
397
if p. provenance == TypeParamProvenance :: TraitSelf {
385
398
Some ( id)
@@ -438,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
438
451
db : & dyn DefDatabase ,
439
452
) -> InFile < ArenaMap < LocalTypeOrConstParamId , Self :: Value > > {
440
453
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) ;
442
455
443
456
let ( file_id, generic_params_list) = file_id_and_params_of ( * self , db) ;
444
457
@@ -492,7 +505,7 @@ impl ChildBySource for GenericDefId {
492
505
}
493
506
494
507
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) ;
496
509
let lts_idx_iter = generic_params. lifetimes . iter ( ) . map ( |( idx, _) | idx) ;
497
510
498
511
// For traits the first type index is `Self`, skip it.
0 commit comments