@@ -785,26 +785,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
785785 self . opt_item_ident ( item_index, sess) . expect ( "no encoded ident for item" )
786786 }
787787
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-
792788 #[ inline]
793789 pub ( super ) fn map_encoded_cnum_to_current ( self , cnum : CrateNum ) -> CrateNum {
794790 if cnum == LOCAL_CRATE { self . cnum } else { self . cnum_map [ cnum] }
795791 }
796792
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-
808793 fn def_kind ( self , item_id : DefIndex ) -> DefKind {
809794 self . root . tables . opt_def_kind . get ( self , item_id) . unwrap_or_else ( || {
810795 bug ! (
@@ -856,11 +841,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
856841 )
857842 }
858843
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 {
860845 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 ,
864849 _ => bug ! ( ) ,
865850 } ;
866851
@@ -896,13 +881,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
896881 }
897882
898883 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) ;
900885 let did = self . local_def_id ( item_id) ;
901886
902887 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 ,
906891 _ => bug ! ( "get_adt_def called on a non-ADT {:?}" , did) ,
907892 } ;
908893 let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
@@ -914,7 +899,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
914899 . get ( self , item_id)
915900 . unwrap_or_else ( LazyArray :: empty)
916901 . 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) )
918903 . collect ( )
919904 } else {
920905 std:: iter:: once ( self . get_variant ( & kind, item_id, did) ) . collect ( )
@@ -1129,10 +1114,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11291114 fn get_associated_item ( self , id : DefIndex ) -> ty:: AssocItem {
11301115 let name = self . item_name ( id) ;
11311116
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 ,
11361121 _ => bug ! ( "cannot get associated-item of `{:?}`" , self . def_key( id) ) ,
11371122 } ;
11381123 let has_self = self . get_fn_has_self_parameter ( id) ;
@@ -1149,8 +1134,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11491134 }
11501135
11511136 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 => {
11541139 let vdata = self . root . tables . variant_data . get ( self , node_id) . unwrap ( ) . decode ( self ) ;
11551140 vdata. ctor . map ( |index| ( self . local_def_id ( index) , vdata. ctor_kind ) )
11561141 }
@@ -1339,18 +1324,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13391324 }
13401325
13411326 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 ( _ ) => {
13441329 self . root . tables . macro_definition . get ( self , id) . unwrap ( ) . decode ( ( self , sess) )
13451330 }
13461331 _ => bug ! ( ) ,
13471332 }
13481333 }
13491334
13501335 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
13541340 }
13551341 }
13561342
0 commit comments