@@ -48,6 +48,7 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> {
4848 ChildContainer :: ModuleId ( it) => it. resolver ( self . db ) ,
4949 ChildContainer :: EnumId ( it) => it. resolver ( self . db ) ,
5050 ChildContainer :: VariantId ( it) => it. resolver ( self . db ) ,
51+ ChildContainer :: GenericDefId ( it) => it. resolver ( self . db ) ,
5152 } ;
5253 SourceAnalyzer :: new_for_resolver ( resolver, src)
5354 }
@@ -107,6 +108,19 @@ impl<DB: HirDatabase> SourceBinder<'_, DB> {
107108 let c = crate :: Module :: from_definition ( self . db , src. with_value ( module_source) ) ?;
108109 Some ( c. id . into ( ) )
109110 }
111+
112+ fn child_by_source ( & mut self , container : ChildContainer ) -> & DynMap {
113+ let db = self . db ;
114+ self . child_by_source_cache . entry ( container) . or_insert_with ( || match container {
115+ ChildContainer :: DefWithBodyId ( it) => it. child_by_source ( db) ,
116+ ChildContainer :: ModuleId ( it) => it. child_by_source ( db) ,
117+ ChildContainer :: TraitId ( it) => it. child_by_source ( db) ,
118+ ChildContainer :: ImplId ( it) => it. child_by_source ( db) ,
119+ ChildContainer :: EnumId ( it) => it. child_by_source ( db) ,
120+ ChildContainer :: VariantId ( it) => it. child_by_source ( db) ,
121+ ChildContainer :: GenericDefId ( it) => it. child_by_source ( db) ,
122+ } )
123+ }
110124}
111125
112126pub trait ToId : Sized {
@@ -157,6 +171,9 @@ enum ChildContainer {
157171 ImplId ( ImplId ) ,
158172 EnumId ( EnumId ) ,
159173 VariantId ( VariantId ) ,
174+ /// XXX: this might be the same def as, for example an `EnumId`. However,
175+ /// here the children generic parameters, and not, eg enum variants.
176+ GenericDefId ( GenericDefId ) ,
160177}
161178impl_froms ! {
162179 ChildContainer :
@@ -166,6 +183,7 @@ impl_froms! {
166183 ImplId ,
167184 EnumId ,
168185 VariantId ,
186+ GenericDefId
169187}
170188
171189pub trait ToIdByKey : Sized + AstNode + ' static {
@@ -189,6 +207,7 @@ impl<T: ToIdByKey> ToId for T {
189207 ChildContainer :: ImplId ( it) => it. child_by_source ( db) ,
190208 ChildContainer :: EnumId ( it) => it. child_by_source ( db) ,
191209 ChildContainer :: VariantId ( it) => it. child_by_source ( db) ,
210+ ChildContainer :: GenericDefId ( it) => it. child_by_source ( db) ,
192211 } ) ;
193212 dyn_map[ T :: KEY ] . get ( & src) . copied ( )
194213 }
@@ -283,7 +302,7 @@ impl ToDef for ast::TypeParam {
283302 } ;
284303 Some ( res)
285304 } ) ?;
286- let & id = parent . child_by_source ( sb . db ) [ keys:: TYPE_PARAM ] . get ( & src) ?;
305+ let & id = sb . child_by_source ( parent . into ( ) ) [ keys:: TYPE_PARAM ] . get ( & src) ?;
287306 Some ( TypeParam { id } )
288307 }
289308}
0 commit comments