@@ -8,6 +8,7 @@ use rustc_hir::def::{DefKind, Res};
88use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
99use rustc_hir:: definitions:: { DefKey , DefPath , Definitions } ;
1010use rustc_hir:: intravisit;
11+ use rustc_hir:: intravisit:: Visitor ;
1112use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
1213use rustc_hir:: * ;
1314use rustc_index:: vec:: IndexVec ;
@@ -494,6 +495,15 @@ impl<'hir> Map<'hir> {
494495 }
495496 }
496497
498+ pub fn visit_exported_macros_in_krate < V > ( & self , visitor : & mut V )
499+ where
500+ V : Visitor < ' hir > ,
501+ {
502+ for id in self . krate ( ) . exported_macros {
503+ visitor. visit_macro_def ( self . expect_macro_def ( id. hir_id ) ) ;
504+ }
505+ }
506+
497507 /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
498508 pub fn get ( & self , id : HirId ) -> Node < ' hir > {
499509 self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find hir id {} in the HIR map" , id) )
@@ -802,6 +812,13 @@ impl<'hir> Map<'hir> {
802812 }
803813 }
804814
815+ pub fn expect_macro_def ( & self , id : HirId ) -> & ' hir MacroDef < ' hir > {
816+ match self . find ( id) {
817+ Some ( Node :: MacroDef ( macro_def) ) => macro_def,
818+ _ => bug ! ( "expected macro def, found {}" , self . node_to_string( id) ) ,
819+ }
820+ }
821+
805822 pub fn expect_expr ( & self , id : HirId ) -> & ' hir Expr < ' hir > {
806823 match self . find ( id) {
807824 Some ( Node :: Expr ( expr) ) => expr,
@@ -821,6 +838,7 @@ impl<'hir> Map<'hir> {
821838 Node :: GenericParam ( param) => param. name . ident ( ) . name ,
822839 Node :: Binding ( & Pat { kind : PatKind :: Binding ( _, _, l, _) , .. } ) => l. name ,
823840 Node :: Ctor ( ..) => self . name ( self . get_parent_item ( id) ) ,
841+ Node :: MacroDef ( md) => md. ident . name ,
824842 _ => return None ,
825843 } )
826844 }
0 commit comments