@@ -8,6 +8,7 @@ use rustc_hir::def::{DefKind, Res};
8
8
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
9
9
use rustc_hir::definitions::{DefKey, DefPath, Definitions};
10
10
use rustc_hir::intravisit;
11
+ use rustc_hir::intravisit::Visitor;
11
12
use rustc_hir::itemlikevisit::ItemLikeVisitor;
12
13
use rustc_hir::*;
13
14
use rustc_index::vec::IndexVec;
@@ -494,6 +495,15 @@ impl<'hir> Map<'hir> {
494
495
}
495
496
}
496
497
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
+
497
507
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
498
508
pub fn get(&self, id: HirId) -> Node<'hir> {
499
509
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> {
802
812
}
803
813
}
804
814
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
+
805
822
pub fn expect_expr(&self, id: HirId) -> &'hir Expr<'hir> {
806
823
match self.find(id) {
807
824
Some(Node::Expr(expr)) => expr,
@@ -821,6 +838,7 @@ impl<'hir> Map<'hir> {
821
838
Node::GenericParam(param) => param.name.ident().name,
822
839
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name,
823
840
Node::Ctor(..) => self.name(self.get_parent_item(id)),
841
+ Node::MacroDef(md) => md.ident.name,
824
842
_ => return None,
825
843
})
826
844
}
0 commit comments