Skip to content

Commit 3a82b0d

Browse files
Don't try get local DefId of imported macro in rustdoc.
1 parent 77e659a commit 3a82b0d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ impl Clean<Item> for doctree::Macro {
28012801
visibility: Some(Public),
28022802
stability: self.stab.clean(cx),
28032803
deprecation: self.depr.clean(cx),
2804-
def_id: cx.tcx.map.local_def_id(self.id),
2804+
def_id: self.def_id,
28052805
inner: MacroItem(Macro {
28062806
source: format!("macro_rules! {} {{\n{}}}",
28072807
name,

src/librustdoc/doctree.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,11 @@ pub struct DefaultImpl {
233233
pub whence: Span,
234234
}
235235

236+
// For Macro we store the DefId instead of the NodeId, since we also create
237+
// these imported macro_rules (which only have a DUMMY_NODE_ID).
236238
pub struct Macro {
237239
pub name: Name,
238-
pub id: ast::NodeId,
240+
pub def_id: hir::def_id::DefId,
239241
pub attrs: hir::HirVec<ast::Attribute>,
240242
pub whence: Span,
241243
pub matchers: hir::HirVec<Span>,

src/librustdoc/visit_ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8585
None);
8686
// attach the crate's exported macros to the top-level module:
8787
let macro_exports: Vec<_> =
88-
krate.exported_macros.iter().map(|def| self.visit_macro(def)).collect();
88+
krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect();
8989
self.module.macros.extend(macro_exports);
9090
self.module.is_crate = true;
9191
}
@@ -210,7 +210,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
210210
// FIXME(jseyfried) merge with `self.visit_macro()`
211211
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
212212
om.macros.push(Macro {
213-
id: def.id,
213+
def_id: def_id,
214214
attrs: def.attrs.clone().into(),
215215
name: def.ident.name,
216216
whence: def.span,
@@ -513,12 +513,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
513513
}
514514

515515
// convert each exported_macro into a doc item
516-
fn visit_macro(&self, def: &hir::MacroDef) -> Macro {
516+
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
517517
// Extract the spans of all matchers. They represent the "interface" of the macro.
518518
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
519519

520520
Macro {
521-
id: def.id,
521+
def_id: self.cx.tcx.map.local_def_id(def.id),
522522
attrs: def.attrs.clone(),
523523
name: def.name,
524524
whence: def.span,

0 commit comments

Comments
 (0)