3
3
//! generic parameters. See also the `Generics` type and the `generics_of` query
4
4
//! in rustc.
5
5
6
+ use std:: ops;
7
+
6
8
use either:: Either ;
7
9
use hir_expand:: {
8
10
name:: { AsName , Name } ,
9
11
ExpandResult ,
10
12
} ;
11
13
use intern:: Interned ;
12
- use la_arena:: { Arena , Idx } ;
14
+ use la_arena:: Arena ;
13
15
use once_cell:: unsync:: Lazy ;
14
16
use stdx:: impl_from;
15
17
use syntax:: ast:: { self , HasGenericParams , HasName , HasTypeBounds } ;
@@ -23,7 +25,7 @@ use crate::{
23
25
nameres:: { DefMap , MacroSubNs } ,
24
26
type_ref:: { ConstRef , LifetimeRef , TypeBound , TypeRef } ,
25
27
AdtId , ConstParamId , GenericDefId , HasModule , ItemTreeLoc , LifetimeParamId ,
26
- LocalTypeOrConstParamId , Lookup , TypeOrConstParamId , TypeParamId ,
28
+ LocalLifetimeParamId , LocalTypeOrConstParamId , Lookup , TypeOrConstParamId , TypeParamId ,
27
29
} ;
28
30
29
31
/// Data about a generic type parameter (to a function, struct, impl, ...).
@@ -158,6 +160,20 @@ pub struct GenericParams {
158
160
pub where_predicates : Box < [ WherePredicate ] > ,
159
161
}
160
162
163
+ impl ops:: Index < LocalTypeOrConstParamId > for GenericParams {
164
+ type Output = TypeOrConstParamData ;
165
+ fn index ( & self , index : LocalTypeOrConstParamId ) -> & TypeOrConstParamData {
166
+ & self . type_or_consts [ index]
167
+ }
168
+ }
169
+
170
+ impl ops:: Index < LocalLifetimeParamId > for GenericParams {
171
+ type Output = LifetimeParamData ;
172
+ fn index ( & self , index : LocalLifetimeParamId ) -> & LifetimeParamData {
173
+ & self . lifetimes [ index]
174
+ }
175
+ }
176
+
161
177
/// A single predicate from a where clause, i.e. `where Type: Trait`. Combined
162
178
/// where clauses like `where T: Foo + Bar` are turned into multiple of these.
163
179
/// It might still result in multiple actual predicates though, because of
@@ -199,7 +215,7 @@ impl GenericParamsCollector {
199
215
lower_ctx : & LowerCtx < ' _ > ,
200
216
node : & dyn HasGenericParams ,
201
217
add_param_attrs : impl FnMut (
202
- Either < Idx < TypeOrConstParamData > , Idx < LifetimeParamData > > ,
218
+ Either < LocalTypeOrConstParamId , LocalLifetimeParamId > ,
203
219
ast:: GenericParam ,
204
220
) ,
205
221
) {
@@ -227,7 +243,7 @@ impl GenericParamsCollector {
227
243
lower_ctx : & LowerCtx < ' _ > ,
228
244
params : ast:: GenericParamList ,
229
245
mut add_param_attrs : impl FnMut (
230
- Either < Idx < TypeOrConstParamData > , Idx < LifetimeParamData > > ,
246
+ Either < LocalTypeOrConstParamId , LocalLifetimeParamId > ,
231
247
ast:: GenericParam ,
232
248
) ,
233
249
) {
@@ -416,16 +432,16 @@ impl GenericParams {
416
432
}
417
433
418
434
/// Iterator of type_or_consts field
419
- pub fn iter (
435
+ pub fn iter_type_or_consts (
420
436
& self ,
421
- ) -> impl DoubleEndedIterator < Item = ( Idx < TypeOrConstParamData > , & TypeOrConstParamData ) > {
437
+ ) -> impl DoubleEndedIterator < Item = ( LocalTypeOrConstParamId , & TypeOrConstParamData ) > {
422
438
self . type_or_consts . iter ( )
423
439
}
424
440
425
441
/// Iterator of lifetimes field
426
442
pub fn iter_lt (
427
443
& self ,
428
- ) -> impl DoubleEndedIterator < Item = ( Idx < LifetimeParamData > , & LifetimeParamData ) > {
444
+ ) -> impl DoubleEndedIterator < Item = ( LocalLifetimeParamId , & LifetimeParamData ) > {
429
445
self . lifetimes . iter ( )
430
446
}
431
447
0 commit comments