@@ -23,7 +23,7 @@ use rustc::hir::intravisit::IdRange;
2323
2424use rustc:: middle:: cstore:: { DepKind , InlinedItem , LinkagePreference } ;
2525use rustc:: hir:: def:: { self , Def , CtorKind } ;
26- use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex , LOCAL_CRATE } ;
26+ use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX , LOCAL_CRATE } ;
2727use rustc:: middle:: lang_items;
2828use rustc:: ty:: { self , Ty , TyCtxt } ;
2929use rustc:: ty:: subst:: Substs ;
@@ -513,7 +513,14 @@ impl<'a, 'tcx> CrateMetadata {
513513 }
514514
515515 pub fn get_def ( & self , index : DefIndex ) -> Option < Def > {
516- self . entry ( index) . kind . to_def ( self . local_def_id ( index) )
516+ if self . proc_macros . is_some ( ) {
517+ Some ( match index {
518+ CRATE_DEF_INDEX => Def :: Mod ( self . local_def_id ( index) ) ,
519+ _ => Def :: Macro ( self . local_def_id ( index) ) ,
520+ } )
521+ } else {
522+ self . entry ( index) . kind . to_def ( self . local_def_id ( index) )
523+ }
517524 }
518525
519526 pub fn get_trait_def ( & self ,
@@ -643,15 +650,24 @@ impl<'a, 'tcx> CrateMetadata {
643650 }
644651
645652 pub fn get_stability ( & self , id : DefIndex ) -> Option < attr:: Stability > {
646- self . entry ( id) . stability . map ( |stab| stab. decode ( self ) )
653+ match self . proc_macros {
654+ Some ( _) if id != CRATE_DEF_INDEX => None ,
655+ _ => self . entry ( id) . stability . map ( |stab| stab. decode ( self ) ) ,
656+ }
647657 }
648658
649659 pub fn get_deprecation ( & self , id : DefIndex ) -> Option < attr:: Deprecation > {
650- self . entry ( id) . deprecation . map ( |depr| depr. decode ( self ) )
660+ match self . proc_macros {
661+ Some ( _) if id != CRATE_DEF_INDEX => None ,
662+ _ => self . entry ( id) . deprecation . map ( |depr| depr. decode ( self ) ) ,
663+ }
651664 }
652665
653666 pub fn get_visibility ( & self , id : DefIndex ) -> ty:: Visibility {
654- self . entry ( id) . visibility
667+ match self . proc_macros {
668+ Some ( _) => ty:: Visibility :: Public ,
669+ _ => self . entry ( id) . visibility ,
670+ }
655671 }
656672
657673 fn get_impl_data ( & self , id : DefIndex ) -> ImplData < ' tcx > {
@@ -692,11 +708,11 @@ impl<'a, 'tcx> CrateMetadata {
692708 where F : FnMut ( def:: Export )
693709 {
694710 if let Some ( ref proc_macros) = self . proc_macros {
695- for ( id , & ( name , _ ) ) in proc_macros . iter ( ) . enumerate ( ) {
696- callback ( def :: Export {
697- name : name ,
698- def : Def :: Macro ( DefId { krate : self . cnum , index : DefIndex :: new ( id ) , } ) ,
699- } )
711+ if id == CRATE_DEF_INDEX {
712+ for ( id , & ( name , _ ) ) in proc_macros . iter ( ) . enumerate ( ) {
713+ let def = Def :: Macro ( DefId { krate : self . cnum , index : DefIndex :: new ( id + 1 ) } ) ;
714+ callback ( def:: Export { name : name , def : def } ) ;
715+ }
700716 }
701717 return
702718 }
@@ -894,6 +910,9 @@ impl<'a, 'tcx> CrateMetadata {
894910 }
895911
896912 pub fn get_item_attrs ( & self , node_id : DefIndex ) -> Vec < ast:: Attribute > {
913+ if self . proc_macros . is_some ( ) && node_id != CRATE_DEF_INDEX {
914+ return Vec :: new ( ) ;
915+ }
897916 // The attributes for a tuple struct are attached to the definition, not the ctor;
898917 // we assume that someone passing in a tuple struct ctor is actually wanting to
899918 // look at the definition
0 commit comments