@@ -99,8 +99,8 @@ use crate::{
9999 data:: adt:: VariantData ,
100100 db:: DefDatabase ,
101101 item_tree:: {
102- Const , Enum , ExternCrate , Function , Impl , ItemTreeId , ItemTreeNode , Macro2 , MacroRules ,
103- Static , Struct , Trait , TraitAlias , TypeAlias , Union , Use , Variant ,
102+ Const , Enum , ExternCrate , Function , Impl , ItemTreeId , ItemTreeModItemNode , Macro2 ,
103+ MacroRules , Static , Struct , Trait , TraitAlias , TypeAlias , Union , Use , Variant ,
104104 } ,
105105} ;
106106
@@ -213,57 +213,57 @@ impl ModuleId {
213213pub type LocalModuleId = Idx < nameres:: ModuleData > ;
214214
215215#[ derive( Debug ) ]
216- pub struct ItemLoc < N : ItemTreeNode > {
216+ pub struct ItemLoc < N : ItemTreeModItemNode > {
217217 pub container : ModuleId ,
218218 pub id : ItemTreeId < N > ,
219219}
220220
221- impl < N : ItemTreeNode > Clone for ItemLoc < N > {
221+ impl < N : ItemTreeModItemNode > Clone for ItemLoc < N > {
222222 fn clone ( & self ) -> Self {
223223 Self { container : self . container , id : self . id }
224224 }
225225}
226226
227- impl < N : ItemTreeNode > Copy for ItemLoc < N > { }
227+ impl < N : ItemTreeModItemNode > Copy for ItemLoc < N > { }
228228
229- impl < N : ItemTreeNode > PartialEq for ItemLoc < N > {
229+ impl < N : ItemTreeModItemNode > PartialEq for ItemLoc < N > {
230230 fn eq ( & self , other : & Self ) -> bool {
231231 self . container == other. container && self . id == other. id
232232 }
233233}
234234
235- impl < N : ItemTreeNode > Eq for ItemLoc < N > { }
235+ impl < N : ItemTreeModItemNode > Eq for ItemLoc < N > { }
236236
237- impl < N : ItemTreeNode > Hash for ItemLoc < N > {
237+ impl < N : ItemTreeModItemNode > Hash for ItemLoc < N > {
238238 fn hash < H : Hasher > ( & self , state : & mut H ) {
239239 self . container . hash ( state) ;
240240 self . id . hash ( state) ;
241241 }
242242}
243243
244244#[ derive( Debug ) ]
245- pub struct AssocItemLoc < N : ItemTreeNode > {
245+ pub struct AssocItemLoc < N : ItemTreeModItemNode > {
246246 pub container : ItemContainerId ,
247247 pub id : ItemTreeId < N > ,
248248}
249249
250- impl < N : ItemTreeNode > Clone for AssocItemLoc < N > {
250+ impl < N : ItemTreeModItemNode > Clone for AssocItemLoc < N > {
251251 fn clone ( & self ) -> Self {
252252 Self { container : self . container , id : self . id }
253253 }
254254}
255255
256- impl < N : ItemTreeNode > Copy for AssocItemLoc < N > { }
256+ impl < N : ItemTreeModItemNode > Copy for AssocItemLoc < N > { }
257257
258- impl < N : ItemTreeNode > PartialEq for AssocItemLoc < N > {
258+ impl < N : ItemTreeModItemNode > PartialEq for AssocItemLoc < N > {
259259 fn eq ( & self , other : & Self ) -> bool {
260260 self . container == other. container && self . id == other. id
261261 }
262262}
263263
264- impl < N : ItemTreeNode > Eq for AssocItemLoc < N > { }
264+ impl < N : ItemTreeModItemNode > Eq for AssocItemLoc < N > { }
265265
266- impl < N : ItemTreeNode > Hash for AssocItemLoc < N > {
266+ impl < N : ItemTreeModItemNode > Hash for AssocItemLoc < N > {
267267 fn hash < H : Hasher > ( & self , state : & mut H ) {
268268 self . container . hash ( state) ;
269269 self . id . hash ( state) ;
@@ -297,15 +297,14 @@ pub struct EnumId(salsa::InternId);
297297pub type EnumLoc = ItemLoc < Enum > ;
298298impl_intern ! ( EnumId , EnumLoc , intern_enum, lookup_intern_enum) ;
299299
300- // FIXME: rename to `VariantId`, only enums can ave variants
301300#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
302301pub struct EnumVariantId ( salsa:: InternId ) ;
303302
304303#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
305304pub struct EnumVariantLoc {
306- pub container : ModuleId ,
307305 pub id : ItemTreeId < Variant > ,
308306 pub parent : EnumId ,
307+ pub index : u32 ,
309308}
310309impl_intern ! ( EnumVariantId , EnumVariantLoc , intern_enum_variant, lookup_intern_enum_variant) ;
311310
@@ -992,7 +991,8 @@ impl HasModule for ItemContainerId {
992991 }
993992}
994993
995- impl < N : ItemTreeNode > HasModule for AssocItemLoc < N > {
994+ impl < N : ItemTreeModItemNode > HasModule for AssocItemLoc < N > {
995+ #[ inline]
996996 fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
997997 self . container . module ( db)
998998 }
@@ -1008,7 +1008,22 @@ impl HasModule for AdtId {
10081008 }
10091009}
10101010
1011+ impl HasModule for EnumId {
1012+ #[ inline]
1013+ fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1014+ self . lookup ( db) . container
1015+ }
1016+ }
1017+
1018+ impl HasModule for EnumVariantId {
1019+ #[ inline]
1020+ fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1021+ self . lookup ( db) . parent . module ( db)
1022+ }
1023+ }
1024+
10111025impl HasModule for ExternCrateId {
1026+ #[ inline]
10121027 fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
10131028 self . lookup ( db) . container
10141029 }
@@ -1017,7 +1032,7 @@ impl HasModule for ExternCrateId {
10171032impl HasModule for VariantId {
10181033 fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
10191034 match self {
1020- VariantId :: EnumVariantId ( it) => it. lookup ( db) . container ,
1035+ VariantId :: EnumVariantId ( it) => it. lookup ( db) . parent . module ( db ) ,
10211036 VariantId :: StructId ( it) => it. lookup ( db) . container ,
10221037 VariantId :: UnionId ( it) => it. lookup ( db) . container ,
10231038 }
@@ -1046,7 +1061,7 @@ impl HasModule for TypeOwnerId {
10461061 TypeOwnerId :: TraitAliasId ( it) => it. lookup ( db) . container ,
10471062 TypeOwnerId :: TypeAliasId ( it) => it. lookup ( db) . module ( db) ,
10481063 TypeOwnerId :: ImplId ( it) => it. lookup ( db) . container ,
1049- TypeOwnerId :: EnumVariantId ( it) => it. lookup ( db) . container ,
1064+ TypeOwnerId :: EnumVariantId ( it) => it. lookup ( db) . parent . module ( db ) ,
10501065 }
10511066 }
10521067}
@@ -1057,7 +1072,7 @@ impl HasModule for DefWithBodyId {
10571072 DefWithBodyId :: FunctionId ( it) => it. lookup ( db) . module ( db) ,
10581073 DefWithBodyId :: StaticId ( it) => it. lookup ( db) . module ( db) ,
10591074 DefWithBodyId :: ConstId ( it) => it. lookup ( db) . module ( db) ,
1060- DefWithBodyId :: VariantId ( it) => it. lookup ( db) . container ,
1075+ DefWithBodyId :: VariantId ( it) => it. lookup ( db) . parent . module ( db ) ,
10611076 DefWithBodyId :: InTypeConstId ( it) => it. lookup ( db) . owner . module ( db) ,
10621077 }
10631078 }
@@ -1072,19 +1087,21 @@ impl HasModule for GenericDefId {
10721087 GenericDefId :: TraitAliasId ( it) => it. lookup ( db) . container ,
10731088 GenericDefId :: TypeAliasId ( it) => it. lookup ( db) . module ( db) ,
10741089 GenericDefId :: ImplId ( it) => it. lookup ( db) . container ,
1075- GenericDefId :: EnumVariantId ( it) => it. lookup ( db) . container ,
1090+ GenericDefId :: EnumVariantId ( it) => it. lookup ( db) . parent . lookup ( db ) . container ,
10761091 GenericDefId :: ConstId ( it) => it. lookup ( db) . module ( db) ,
10771092 }
10781093 }
10791094}
10801095
10811096impl HasModule for TypeAliasId {
1097+ #[ inline]
10821098 fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
10831099 self . lookup ( db) . module ( db)
10841100 }
10851101}
10861102
10871103impl HasModule for TraitId {
1104+ #[ inline]
10881105 fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
10891106 self . lookup ( db) . container
10901107 }
@@ -1099,7 +1116,7 @@ impl ModuleDefId {
10991116 ModuleDefId :: ModuleId ( id) => * id,
11001117 ModuleDefId :: FunctionId ( id) => id. lookup ( db) . module ( db) ,
11011118 ModuleDefId :: AdtId ( id) => id. module ( db) ,
1102- ModuleDefId :: EnumVariantId ( id) => id. lookup ( db) . container ,
1119+ ModuleDefId :: EnumVariantId ( id) => id. lookup ( db) . parent . module ( db ) ,
11031120 ModuleDefId :: ConstId ( id) => id. lookup ( db) . container . module ( db) ,
11041121 ModuleDefId :: StaticId ( id) => id. lookup ( db) . module ( db) ,
11051122 ModuleDefId :: TraitId ( id) => id. lookup ( db) . container ,
@@ -1118,7 +1135,7 @@ impl AttrDefId {
11181135 AttrDefId :: FieldId ( it) => it. parent . module ( db) . krate ,
11191136 AttrDefId :: AdtId ( it) => it. module ( db) . krate ,
11201137 AttrDefId :: FunctionId ( it) => it. lookup ( db) . module ( db) . krate ,
1121- AttrDefId :: EnumVariantId ( it) => it. lookup ( db) . container . krate ,
1138+ AttrDefId :: EnumVariantId ( it) => it. lookup ( db) . parent . module ( db ) . krate ,
11221139 AttrDefId :: StaticId ( it) => it. lookup ( db) . module ( db) . krate ,
11231140 AttrDefId :: ConstId ( it) => it. lookup ( db) . module ( db) . krate ,
11241141 AttrDefId :: TraitId ( it) => it. lookup ( db) . container . krate ,
0 commit comments