@@ -689,7 +689,7 @@ pub enum TypeOwnerId {
689
689
}
690
690
691
691
impl TypeOwnerId {
692
- fn as_generic_def_id ( self ) -> Option < GenericDefId > {
692
+ fn as_generic_def_id ( self , db : & dyn DefDatabase ) -> Option < GenericDefId > {
693
693
Some ( match self {
694
694
TypeOwnerId :: FunctionId ( it) => GenericDefId :: FunctionId ( it) ,
695
695
TypeOwnerId :: ConstId ( it) => GenericDefId :: ConstId ( it) ,
@@ -698,7 +698,9 @@ impl TypeOwnerId {
698
698
TypeOwnerId :: TraitAliasId ( it) => GenericDefId :: TraitAliasId ( it) ,
699
699
TypeOwnerId :: TypeAliasId ( it) => GenericDefId :: TypeAliasId ( it) ,
700
700
TypeOwnerId :: ImplId ( it) => GenericDefId :: ImplId ( it) ,
701
- TypeOwnerId :: EnumVariantId ( it) => GenericDefId :: EnumVariantId ( it) ,
701
+ TypeOwnerId :: EnumVariantId ( it) => {
702
+ GenericDefId :: AdtId ( AdtId :: EnumId ( it. lookup ( db) . parent ) )
703
+ }
702
704
TypeOwnerId :: InTypeConstId ( _) | TypeOwnerId :: StaticId ( _) => return None ,
703
705
} )
704
706
}
@@ -740,7 +742,6 @@ impl From<GenericDefId> for TypeOwnerId {
740
742
GenericDefId :: TraitAliasId ( it) => it. into ( ) ,
741
743
GenericDefId :: TypeAliasId ( it) => it. into ( ) ,
742
744
GenericDefId :: ImplId ( it) => it. into ( ) ,
743
- GenericDefId :: EnumVariantId ( it) => it. into ( ) ,
744
745
GenericDefId :: ConstId ( it) => it. into ( ) ,
745
746
}
746
747
}
@@ -849,8 +850,8 @@ impl GeneralConstId {
849
850
pub fn generic_def ( self , db : & dyn DefDatabase ) -> Option < GenericDefId > {
850
851
match self {
851
852
GeneralConstId :: ConstId ( it) => Some ( it. into ( ) ) ,
852
- GeneralConstId :: ConstBlockId ( it) => it. lookup ( db) . parent . as_generic_def_id ( ) ,
853
- GeneralConstId :: InTypeConstId ( it) => it. lookup ( db) . owner . as_generic_def_id ( ) ,
853
+ GeneralConstId :: ConstBlockId ( it) => it. lookup ( db) . parent . as_generic_def_id ( db ) ,
854
+ GeneralConstId :: InTypeConstId ( it) => it. lookup ( db) . owner . as_generic_def_id ( db ) ,
854
855
}
855
856
}
856
857
@@ -888,12 +889,12 @@ impl From<EnumVariantId> for DefWithBodyId {
888
889
}
889
890
890
891
impl DefWithBodyId {
891
- pub fn as_generic_def_id ( self ) -> Option < GenericDefId > {
892
+ pub fn as_generic_def_id ( self , db : & dyn DefDatabase ) -> Option < GenericDefId > {
892
893
match self {
893
894
DefWithBodyId :: FunctionId ( f) => Some ( f. into ( ) ) ,
894
895
DefWithBodyId :: StaticId ( _) => None ,
895
896
DefWithBodyId :: ConstId ( c) => Some ( c. into ( ) ) ,
896
- DefWithBodyId :: VariantId ( c) => Some ( c. into ( ) ) ,
897
+ DefWithBodyId :: VariantId ( c) => Some ( c. lookup ( db ) . parent . into ( ) ) ,
897
898
// FIXME: stable rust doesn't allow generics in constants, but we should
898
899
// use `TypeOwnerId::as_generic_def_id` when it does.
899
900
DefWithBodyId :: InTypeConstId ( _) => None ,
@@ -921,10 +922,6 @@ pub enum GenericDefId {
921
922
TraitAliasId ( TraitAliasId ) ,
922
923
TypeAliasId ( TypeAliasId ) ,
923
924
ImplId ( ImplId ) ,
924
- // enum variants cannot have generics themselves, but their parent enums
925
- // can, and this makes some code easier to write
926
- // FIXME: Try to remove this as that will reduce the amount of query slots generated per enum?
927
- EnumVariantId ( EnumVariantId ) ,
928
925
// consts can have type parameters from their parents (i.e. associated consts of traits)
929
926
ConstId ( ConstId ) ,
930
927
}
@@ -935,7 +932,6 @@ impl_from!(
935
932
TraitAliasId ,
936
933
TypeAliasId ,
937
934
ImplId ,
938
- EnumVariantId ,
939
935
ConstId
940
936
for GenericDefId
941
937
) ;
@@ -967,7 +963,6 @@ impl GenericDefId {
967
963
GenericDefId :: TraitAliasId ( it) => file_id_and_params_of_item_loc ( db, it) ,
968
964
GenericDefId :: ImplId ( it) => file_id_and_params_of_item_loc ( db, it) ,
969
965
GenericDefId :: ConstId ( it) => ( it. lookup ( db) . id . file_id ( ) , None ) ,
970
- GenericDefId :: EnumVariantId ( it) => ( it. lookup ( db) . id . file_id ( ) , None ) ,
971
966
}
972
967
}
973
968
@@ -994,6 +989,46 @@ impl From<AssocItemId> for GenericDefId {
994
989
}
995
990
}
996
991
992
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
993
+ pub enum CallableDefId {
994
+ FunctionId ( FunctionId ) ,
995
+ StructId ( StructId ) ,
996
+ EnumVariantId ( EnumVariantId ) ,
997
+ }
998
+
999
+ impl InternValueTrivial for CallableDefId { }
1000
+
1001
+ impl_from ! ( FunctionId , StructId , EnumVariantId for CallableDefId ) ;
1002
+ impl From < CallableDefId > for ModuleDefId {
1003
+ fn from ( def : CallableDefId ) -> ModuleDefId {
1004
+ match def {
1005
+ CallableDefId :: FunctionId ( f) => ModuleDefId :: FunctionId ( f) ,
1006
+ CallableDefId :: StructId ( s) => ModuleDefId :: AdtId ( AdtId :: StructId ( s) ) ,
1007
+ CallableDefId :: EnumVariantId ( e) => ModuleDefId :: EnumVariantId ( e) ,
1008
+ }
1009
+ }
1010
+ }
1011
+
1012
+ impl CallableDefId {
1013
+ pub fn krate ( self , db : & dyn DefDatabase ) -> CrateId {
1014
+ match self {
1015
+ CallableDefId :: FunctionId ( f) => f. krate ( db) ,
1016
+ CallableDefId :: StructId ( s) => s. krate ( db) ,
1017
+ CallableDefId :: EnumVariantId ( e) => e. krate ( db) ,
1018
+ }
1019
+ }
1020
+ }
1021
+
1022
+ impl GenericDefId {
1023
+ pub fn from ( db : & dyn DefDatabase , def : CallableDefId ) -> GenericDefId {
1024
+ match def {
1025
+ CallableDefId :: FunctionId ( f) => f. into ( ) ,
1026
+ CallableDefId :: StructId ( s) => s. into ( ) ,
1027
+ CallableDefId :: EnumVariantId ( e) => e. lookup ( db) . parent . into ( ) ,
1028
+ }
1029
+ }
1030
+ }
1031
+
997
1032
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
998
1033
pub enum AttrDefId {
999
1034
ModuleId ( ModuleId ) ,
@@ -1310,7 +1345,6 @@ impl HasModule for GenericDefId {
1310
1345
GenericDefId :: TraitAliasId ( it) => it. module ( db) ,
1311
1346
GenericDefId :: TypeAliasId ( it) => it. module ( db) ,
1312
1347
GenericDefId :: ImplId ( it) => it. module ( db) ,
1313
- GenericDefId :: EnumVariantId ( it) => it. module ( db) ,
1314
1348
GenericDefId :: ConstId ( it) => it. module ( db) ,
1315
1349
}
1316
1350
}
0 commit comments