@@ -99,8 +99,8 @@ use crate::{
99
99
data:: adt:: VariantData ,
100
100
db:: DefDatabase ,
101
101
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 ,
104
104
} ,
105
105
} ;
106
106
@@ -213,57 +213,57 @@ impl ModuleId {
213
213
pub type LocalModuleId = Idx < nameres:: ModuleData > ;
214
214
215
215
#[ derive( Debug ) ]
216
- pub struct ItemLoc < N : ItemTreeNode > {
216
+ pub struct ItemLoc < N : ItemTreeModItemNode > {
217
217
pub container : ModuleId ,
218
218
pub id : ItemTreeId < N > ,
219
219
}
220
220
221
- impl < N : ItemTreeNode > Clone for ItemLoc < N > {
221
+ impl < N : ItemTreeModItemNode > Clone for ItemLoc < N > {
222
222
fn clone ( & self ) -> Self {
223
223
Self { container : self . container , id : self . id }
224
224
}
225
225
}
226
226
227
- impl < N : ItemTreeNode > Copy for ItemLoc < N > { }
227
+ impl < N : ItemTreeModItemNode > Copy for ItemLoc < N > { }
228
228
229
- impl < N : ItemTreeNode > PartialEq for ItemLoc < N > {
229
+ impl < N : ItemTreeModItemNode > PartialEq for ItemLoc < N > {
230
230
fn eq ( & self , other : & Self ) -> bool {
231
231
self . container == other. container && self . id == other. id
232
232
}
233
233
}
234
234
235
- impl < N : ItemTreeNode > Eq for ItemLoc < N > { }
235
+ impl < N : ItemTreeModItemNode > Eq for ItemLoc < N > { }
236
236
237
- impl < N : ItemTreeNode > Hash for ItemLoc < N > {
237
+ impl < N : ItemTreeModItemNode > Hash for ItemLoc < N > {
238
238
fn hash < H : Hasher > ( & self , state : & mut H ) {
239
239
self . container . hash ( state) ;
240
240
self . id . hash ( state) ;
241
241
}
242
242
}
243
243
244
244
#[ derive( Debug ) ]
245
- pub struct AssocItemLoc < N : ItemTreeNode > {
245
+ pub struct AssocItemLoc < N : ItemTreeModItemNode > {
246
246
pub container : ItemContainerId ,
247
247
pub id : ItemTreeId < N > ,
248
248
}
249
249
250
- impl < N : ItemTreeNode > Clone for AssocItemLoc < N > {
250
+ impl < N : ItemTreeModItemNode > Clone for AssocItemLoc < N > {
251
251
fn clone ( & self ) -> Self {
252
252
Self { container : self . container , id : self . id }
253
253
}
254
254
}
255
255
256
- impl < N : ItemTreeNode > Copy for AssocItemLoc < N > { }
256
+ impl < N : ItemTreeModItemNode > Copy for AssocItemLoc < N > { }
257
257
258
- impl < N : ItemTreeNode > PartialEq for AssocItemLoc < N > {
258
+ impl < N : ItemTreeModItemNode > PartialEq for AssocItemLoc < N > {
259
259
fn eq ( & self , other : & Self ) -> bool {
260
260
self . container == other. container && self . id == other. id
261
261
}
262
262
}
263
263
264
- impl < N : ItemTreeNode > Eq for AssocItemLoc < N > { }
264
+ impl < N : ItemTreeModItemNode > Eq for AssocItemLoc < N > { }
265
265
266
- impl < N : ItemTreeNode > Hash for AssocItemLoc < N > {
266
+ impl < N : ItemTreeModItemNode > Hash for AssocItemLoc < N > {
267
267
fn hash < H : Hasher > ( & self , state : & mut H ) {
268
268
self . container . hash ( state) ;
269
269
self . id . hash ( state) ;
@@ -297,15 +297,14 @@ pub struct EnumId(salsa::InternId);
297
297
pub type EnumLoc = ItemLoc < Enum > ;
298
298
impl_intern ! ( EnumId , EnumLoc , intern_enum, lookup_intern_enum) ;
299
299
300
- // FIXME: rename to `VariantId`, only enums can ave variants
301
300
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
302
301
pub struct EnumVariantId ( salsa:: InternId ) ;
303
302
304
303
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
305
304
pub struct EnumVariantLoc {
306
- pub container : ModuleId ,
307
305
pub id : ItemTreeId < Variant > ,
308
306
pub parent : EnumId ,
307
+ pub index : u32 ,
309
308
}
310
309
impl_intern ! ( EnumVariantId , EnumVariantLoc , intern_enum_variant, lookup_intern_enum_variant) ;
311
310
@@ -992,7 +991,8 @@ impl HasModule for ItemContainerId {
992
991
}
993
992
}
994
993
995
- impl < N : ItemTreeNode > HasModule for AssocItemLoc < N > {
994
+ impl < N : ItemTreeModItemNode > HasModule for AssocItemLoc < N > {
995
+ #[ inline]
996
996
fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
997
997
self . container . module ( db)
998
998
}
@@ -1008,7 +1008,22 @@ impl HasModule for AdtId {
1008
1008
}
1009
1009
}
1010
1010
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
+
1011
1025
impl HasModule for ExternCrateId {
1026
+ #[ inline]
1012
1027
fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1013
1028
self . lookup ( db) . container
1014
1029
}
@@ -1017,7 +1032,7 @@ impl HasModule for ExternCrateId {
1017
1032
impl HasModule for VariantId {
1018
1033
fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1019
1034
match self {
1020
- VariantId :: EnumVariantId ( it) => it. lookup ( db) . container ,
1035
+ VariantId :: EnumVariantId ( it) => it. lookup ( db) . parent . module ( db ) ,
1021
1036
VariantId :: StructId ( it) => it. lookup ( db) . container ,
1022
1037
VariantId :: UnionId ( it) => it. lookup ( db) . container ,
1023
1038
}
@@ -1046,7 +1061,7 @@ impl HasModule for TypeOwnerId {
1046
1061
TypeOwnerId :: TraitAliasId ( it) => it. lookup ( db) . container ,
1047
1062
TypeOwnerId :: TypeAliasId ( it) => it. lookup ( db) . module ( db) ,
1048
1063
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 ) ,
1050
1065
}
1051
1066
}
1052
1067
}
@@ -1057,7 +1072,7 @@ impl HasModule for DefWithBodyId {
1057
1072
DefWithBodyId :: FunctionId ( it) => it. lookup ( db) . module ( db) ,
1058
1073
DefWithBodyId :: StaticId ( it) => it. lookup ( db) . module ( db) ,
1059
1074
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 ) ,
1061
1076
DefWithBodyId :: InTypeConstId ( it) => it. lookup ( db) . owner . module ( db) ,
1062
1077
}
1063
1078
}
@@ -1072,19 +1087,21 @@ impl HasModule for GenericDefId {
1072
1087
GenericDefId :: TraitAliasId ( it) => it. lookup ( db) . container ,
1073
1088
GenericDefId :: TypeAliasId ( it) => it. lookup ( db) . module ( db) ,
1074
1089
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 ,
1076
1091
GenericDefId :: ConstId ( it) => it. lookup ( db) . module ( db) ,
1077
1092
}
1078
1093
}
1079
1094
}
1080
1095
1081
1096
impl HasModule for TypeAliasId {
1097
+ #[ inline]
1082
1098
fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1083
1099
self . lookup ( db) . module ( db)
1084
1100
}
1085
1101
}
1086
1102
1087
1103
impl HasModule for TraitId {
1104
+ #[ inline]
1088
1105
fn module ( & self , db : & dyn DefDatabase ) -> ModuleId {
1089
1106
self . lookup ( db) . container
1090
1107
}
@@ -1099,7 +1116,7 @@ impl ModuleDefId {
1099
1116
ModuleDefId :: ModuleId ( id) => * id,
1100
1117
ModuleDefId :: FunctionId ( id) => id. lookup ( db) . module ( db) ,
1101
1118
ModuleDefId :: AdtId ( id) => id. module ( db) ,
1102
- ModuleDefId :: EnumVariantId ( id) => id. lookup ( db) . container ,
1119
+ ModuleDefId :: EnumVariantId ( id) => id. lookup ( db) . parent . module ( db ) ,
1103
1120
ModuleDefId :: ConstId ( id) => id. lookup ( db) . container . module ( db) ,
1104
1121
ModuleDefId :: StaticId ( id) => id. lookup ( db) . module ( db) ,
1105
1122
ModuleDefId :: TraitId ( id) => id. lookup ( db) . container ,
@@ -1118,7 +1135,7 @@ impl AttrDefId {
1118
1135
AttrDefId :: FieldId ( it) => it. parent . module ( db) . krate ,
1119
1136
AttrDefId :: AdtId ( it) => it. module ( db) . krate ,
1120
1137
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 ,
1122
1139
AttrDefId :: StaticId ( it) => it. lookup ( db) . module ( db) . krate ,
1123
1140
AttrDefId :: ConstId ( it) => it. lookup ( db) . module ( db) . krate ,
1124
1141
AttrDefId :: TraitId ( it) => it. lookup ( db) . container . krate ,
0 commit comments