@@ -23,7 +23,7 @@ use rustc::hir::intravisit::IdRange;
23
23
24
24
use rustc:: middle:: cstore:: { DepKind , InlinedItem , LinkagePreference } ;
25
25
use 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 } ;
27
27
use rustc:: middle:: lang_items;
28
28
use rustc:: ty:: { self , Ty , TyCtxt } ;
29
29
use rustc:: ty:: subst:: Substs ;
@@ -513,7 +513,14 @@ impl<'a, 'tcx> CrateMetadata {
513
513
}
514
514
515
515
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
+ }
517
524
}
518
525
519
526
pub fn get_trait_def ( & self ,
@@ -643,15 +650,24 @@ impl<'a, 'tcx> CrateMetadata {
643
650
}
644
651
645
652
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
+ }
647
657
}
648
658
649
659
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
+ }
651
664
}
652
665
653
666
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
+ }
655
671
}
656
672
657
673
fn get_impl_data ( & self , id : DefIndex ) -> ImplData < ' tcx > {
@@ -692,11 +708,11 @@ impl<'a, 'tcx> CrateMetadata {
692
708
where F : FnMut ( def:: Export )
693
709
{
694
710
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
+ }
700
716
}
701
717
return
702
718
}
@@ -894,6 +910,9 @@ impl<'a, 'tcx> CrateMetadata {
894
910
}
895
911
896
912
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
+ }
897
916
// The attributes for a tuple struct are attached to the definition, not the ctor;
898
917
// we assume that someone passing in a tuple struct ctor is actually wanting to
899
918
// look at the definition
0 commit comments