Treat macros as HIR items
This commit is contained in:
@@ -394,20 +394,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
|
||||
// Exported macros are visited directly from the crate root,
|
||||
// so they do not have `parent_node` set.
|
||||
// Find the correct enclosing module from their DefKey.
|
||||
let def_key = self.definitions.def_key(macro_def.def_id);
|
||||
let parent = def_key.parent.map_or(hir::CRATE_HIR_ID, |local_def_index| {
|
||||
self.definitions.local_def_id_to_hir_id(LocalDefId { local_def_index })
|
||||
});
|
||||
self.insert_owner(macro_def.def_id, OwnerNode::MacroDef(macro_def));
|
||||
self.with_parent(parent, |this| {
|
||||
this.insert_nested(macro_def.def_id);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics<'hir>, item_id: HirId) {
|
||||
self.insert(v.span, v.id, Node::Variant(v));
|
||||
self.with_parent(v.id, |this| {
|
||||
|
||||
@@ -10,7 +10,6 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::*;
|
||||
use rustc_index::vec::Idx;
|
||||
@@ -218,6 +217,7 @@ impl<'hir> Map<'hir> {
|
||||
ItemKind::Static(..) => DefKind::Static,
|
||||
ItemKind::Const(..) => DefKind::Const,
|
||||
ItemKind::Fn(..) => DefKind::Fn,
|
||||
ItemKind::Macro(..) => DefKind::Macro(MacroKind::Bang),
|
||||
ItemKind::Mod(..) => DefKind::Mod,
|
||||
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
|
||||
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||
@@ -543,15 +543,6 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_exported_macros_in_krate<V>(&self, visitor: &mut V)
|
||||
where
|
||||
V: Visitor<'hir>,
|
||||
{
|
||||
for macro_def in self.krate().exported_macros() {
|
||||
visitor.visit_macro_def(macro_def);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
|
||||
pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> {
|
||||
@@ -1013,7 +1004,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
|
||||
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
|
||||
tcx.untracked_crate.non_exported_macro_attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
|
||||
let crate_hash: Fingerprint = stable_hasher.finish();
|
||||
Svh::new(crate_hash.to_smaller_hash())
|
||||
@@ -1062,6 +1052,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
|
||||
ItemKind::Static(..) => "static",
|
||||
ItemKind::Const(..) => "const",
|
||||
ItemKind::Fn(..) => "fn",
|
||||
ItemKind::Macro(..) => "macro",
|
||||
ItemKind::Mod(..) => "mod",
|
||||
ItemKind::ForeignMod { .. } => "foreign mod",
|
||||
ItemKind::GlobalAsm(..) => "global asm",
|
||||
|
||||
Reference in New Issue
Block a user