From: Michael Woerister Date: Mon, 19 Dec 2016 19:24:33 +0000 (-0500) Subject: Don't try get local DefId of imported macro in rustdoc. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=3a82b0da3d501f5b7f532e26b4738ac0e53fab13;p=rust.git Don't try get local DefId of imported macro in rustdoc. --- diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 28ca92f5db6..123516dc89d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2801,7 +2801,7 @@ fn clean(&self, cx: &DocContext) -> Item { visibility: Some(Public), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.map.local_def_id(self.id), + def_id: self.def_id, inner: MacroItem(Macro { source: format!("macro_rules! {} {{\n{}}}", name, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 21fc135eaad..31e10fbd3b7 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -233,9 +233,11 @@ pub struct DefaultImpl { pub whence: Span, } +// For Macro we store the DefId instead of the NodeId, since we also create +// these imported macro_rules (which only have a DUMMY_NODE_ID). pub struct Macro { pub name: Name, - pub id: ast::NodeId, + pub def_id: hir::def_id::DefId, pub attrs: hir::HirVec, pub whence: Span, pub matchers: hir::HirVec, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 4087b9a761f..29e874c5ab5 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -85,7 +85,7 @@ pub fn visit(&mut self, krate: &hir::Crate) { None); // attach the crate's exported macros to the top-level module: let macro_exports: Vec<_> = - krate.exported_macros.iter().map(|def| self.visit_macro(def)).collect(); + krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect(); self.module.macros.extend(macro_exports); self.module.is_crate = true; } @@ -210,7 +210,7 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec Macro { + fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro { // Extract the spans of all matchers. They represent the "interface" of the macro. let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect(); Macro { - id: def.id, + def_id: self.cx.tcx.map.local_def_id(def.id), attrs: def.attrs.clone(), name: def.name, whence: def.span,