@@ -785,26 +785,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
785
785
self . opt_item_ident ( item_index, sess) . expect ( "no encoded ident for item" )
786
786
}
787
787
788
- fn maybe_kind ( self , item_id : DefIndex ) -> Option < EntryKind > {
789
- self . root . tables . kind . get ( self , item_id) . map ( |k| k. decode ( self ) )
790
- }
791
-
792
788
#[ inline]
793
789
pub ( super ) fn map_encoded_cnum_to_current ( self , cnum : CrateNum ) -> CrateNum {
794
790
if cnum == LOCAL_CRATE { self . cnum } else { self . cnum_map [ cnum] }
795
791
}
796
792
797
- fn kind ( self , item_id : DefIndex ) -> EntryKind {
798
- self . maybe_kind ( item_id) . unwrap_or_else ( || {
799
- bug ! (
800
- "CrateMetadata::kind({:?}): id not found, in crate {:?} with number {}" ,
801
- item_id,
802
- self . root. name,
803
- self . cnum,
804
- )
805
- } )
806
- }
807
-
808
793
fn def_kind ( self , item_id : DefIndex ) -> DefKind {
809
794
self . root . tables . opt_def_kind . get ( self , item_id) . unwrap_or_else ( || {
810
795
bug ! (
@@ -856,11 +841,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
856
841
)
857
842
}
858
843
859
- fn get_variant ( self , kind : & EntryKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
844
+ fn get_variant ( self , kind : & DefKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
860
845
let adt_kind = match kind {
861
- EntryKind :: Variant => ty:: AdtKind :: Enum ,
862
- EntryKind :: Struct => ty:: AdtKind :: Struct ,
863
- EntryKind :: Union => ty:: AdtKind :: Union ,
846
+ DefKind :: Variant => ty:: AdtKind :: Enum ,
847
+ DefKind :: Struct => ty:: AdtKind :: Struct ,
848
+ DefKind :: Union => ty:: AdtKind :: Union ,
864
849
_ => bug ! ( ) ,
865
850
} ;
866
851
@@ -896,13 +881,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
896
881
}
897
882
898
883
fn get_adt_def ( self , item_id : DefIndex , tcx : TyCtxt < ' tcx > ) -> ty:: AdtDef < ' tcx > {
899
- let kind = self . kind ( item_id) ;
884
+ let kind = self . def_kind ( item_id) ;
900
885
let did = self . local_def_id ( item_id) ;
901
886
902
887
let adt_kind = match kind {
903
- EntryKind :: Enum => ty:: AdtKind :: Enum ,
904
- EntryKind :: Struct => ty:: AdtKind :: Struct ,
905
- EntryKind :: Union => ty:: AdtKind :: Union ,
888
+ DefKind :: Enum => ty:: AdtKind :: Enum ,
889
+ DefKind :: Struct => ty:: AdtKind :: Struct ,
890
+ DefKind :: Union => ty:: AdtKind :: Union ,
906
891
_ => bug ! ( "get_adt_def called on a non-ADT {:?}" , did) ,
907
892
} ;
908
893
let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
@@ -914,7 +899,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
914
899
. get ( self , item_id)
915
900
. unwrap_or_else ( LazyArray :: empty)
916
901
. decode ( self )
917
- . map ( |index| self . get_variant ( & self . kind ( index) , index, did) )
902
+ . map ( |index| self . get_variant ( & self . def_kind ( index) , index, did) )
918
903
. collect ( )
919
904
} else {
920
905
std:: iter:: once ( self . get_variant ( & kind, item_id, did) ) . collect ( )
@@ -1129,10 +1114,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1129
1114
fn get_associated_item ( self , id : DefIndex ) -> ty:: AssocItem {
1130
1115
let name = self . item_name ( id) ;
1131
1116
1132
- let kind = match self . kind ( id) {
1133
- EntryKind :: AssocConst => ty:: AssocKind :: Const ,
1134
- EntryKind :: AssocFn => ty:: AssocKind :: Fn ,
1135
- EntryKind :: AssocType => ty:: AssocKind :: Type ,
1117
+ let kind = match self . def_kind ( id) {
1118
+ DefKind :: AssocConst => ty:: AssocKind :: Const ,
1119
+ DefKind :: AssocFn => ty:: AssocKind :: Fn ,
1120
+ DefKind :: AssocTy => ty:: AssocKind :: Type ,
1136
1121
_ => bug ! ( "cannot get associated-item of `{:?}`" , self . def_key( id) ) ,
1137
1122
} ;
1138
1123
let has_self = self . get_fn_has_self_parameter ( id) ;
@@ -1149,8 +1134,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1149
1134
}
1150
1135
1151
1136
fn get_ctor_def_id_and_kind ( self , node_id : DefIndex ) -> Option < ( DefId , CtorKind ) > {
1152
- match self . kind ( node_id) {
1153
- EntryKind :: Struct | EntryKind :: Variant => {
1137
+ match self . def_kind ( node_id) {
1138
+ DefKind :: Struct | DefKind :: Variant => {
1154
1139
let vdata = self . root . tables . variant_data . get ( self , node_id) . unwrap ( ) . decode ( self ) ;
1155
1140
vdata. ctor . map ( |index| ( self . local_def_id ( index) , vdata. ctor_kind ) )
1156
1141
}
@@ -1339,18 +1324,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1339
1324
}
1340
1325
1341
1326
fn get_macro ( self , id : DefIndex , sess : & Session ) -> ast:: MacroDef {
1342
- match self . kind ( id) {
1343
- EntryKind :: MacroDef => {
1327
+ match self . def_kind ( id) {
1328
+ DefKind :: Macro ( _ ) => {
1344
1329
self . root . tables . macro_definition . get ( self , id) . unwrap ( ) . decode ( ( self , sess) )
1345
1330
}
1346
1331
_ => bug ! ( ) ,
1347
1332
}
1348
1333
}
1349
1334
1350
1335
fn is_foreign_item ( self , id : DefIndex ) -> bool {
1351
- match self . kind ( id) {
1352
- EntryKind :: ForeignStatic | EntryKind :: ForeignFn => true ,
1353
- _ => false ,
1336
+ if let Some ( parent) = self . def_key ( id) . parent {
1337
+ matches ! ( self . def_kind( parent) , DefKind :: ForeignMod )
1338
+ } else {
1339
+ false
1354
1340
}
1355
1341
}
1356
1342
0 commit comments