33//! generic parameters. See also the `Generics` type and the `generics_of` query
44//! in rustc.
55
6+ use std:: ops;
7+
68use either:: Either ;
79use hir_expand:: {
810 name:: { AsName , Name } ,
911 ExpandResult ,
1012} ;
1113use intern:: Interned ;
12- use la_arena:: { Arena , Idx } ;
14+ use la_arena:: Arena ;
1315use once_cell:: unsync:: Lazy ;
1416use stdx:: impl_from;
1517use syntax:: ast:: { self , HasGenericParams , HasName , HasTypeBounds } ;
@@ -23,7 +25,7 @@ use crate::{
2325 nameres:: { DefMap , MacroSubNs } ,
2426 type_ref:: { ConstRef , LifetimeRef , TypeBound , TypeRef } ,
2527 AdtId , ConstParamId , GenericDefId , HasModule , ItemTreeLoc , LifetimeParamId ,
26- LocalTypeOrConstParamId , Lookup , TypeOrConstParamId , TypeParamId ,
28+ LocalLifetimeParamId , LocalTypeOrConstParamId , Lookup , TypeOrConstParamId , TypeParamId ,
2729} ;
2830
2931/// Data about a generic type parameter (to a function, struct, impl, ...).
@@ -158,6 +160,20 @@ pub struct GenericParams {
158160 pub where_predicates : Box < [ WherePredicate ] > ,
159161}
160162
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+
161177/// A single predicate from a where clause, i.e. `where Type: Trait`. Combined
162178/// where clauses like `where T: Foo + Bar` are turned into multiple of these.
163179/// It might still result in multiple actual predicates though, because of
@@ -199,7 +215,7 @@ impl GenericParamsCollector {
199215 lower_ctx : & LowerCtx < ' _ > ,
200216 node : & dyn HasGenericParams ,
201217 add_param_attrs : impl FnMut (
202- Either < Idx < TypeOrConstParamData > , Idx < LifetimeParamData > > ,
218+ Either < LocalTypeOrConstParamId , LocalLifetimeParamId > ,
203219 ast:: GenericParam ,
204220 ) ,
205221 ) {
@@ -227,7 +243,7 @@ impl GenericParamsCollector {
227243 lower_ctx : & LowerCtx < ' _ > ,
228244 params : ast:: GenericParamList ,
229245 mut add_param_attrs : impl FnMut (
230- Either < Idx < TypeOrConstParamData > , Idx < LifetimeParamData > > ,
246+ Either < LocalTypeOrConstParamId , LocalLifetimeParamId > ,
231247 ast:: GenericParam ,
232248 ) ,
233249 ) {
@@ -416,16 +432,16 @@ impl GenericParams {
416432 }
417433
418434 /// Iterator of type_or_consts field
419- pub fn iter (
435+ pub fn iter_type_or_consts (
420436 & self ,
421- ) -> impl DoubleEndedIterator < Item = ( Idx < TypeOrConstParamData > , & TypeOrConstParamData ) > {
437+ ) -> impl DoubleEndedIterator < Item = ( LocalTypeOrConstParamId , & TypeOrConstParamData ) > {
422438 self . type_or_consts . iter ( )
423439 }
424440
425441 /// Iterator of lifetimes field
426442 pub fn iter_lt (
427443 & self ,
428- ) -> impl DoubleEndedIterator < Item = ( Idx < LifetimeParamData > , & LifetimeParamData ) > {
444+ ) -> impl DoubleEndedIterator < Item = ( LocalLifetimeParamId , & LifetimeParamData ) > {
429445 self . lifetimes . iter ( )
430446 }
431447
0 commit comments