Skip to content

Commit

Permalink
Don't try get local DefId of imported macro in rustdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Dec 19, 2016
1 parent 77e659a commit 3a82b0d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2801,7 +2801,7 @@ impl Clean<Item> for doctree::Macro {
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,
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ast::Attribute>,
pub whence: Span,
pub matchers: hir::HirVec<Span>,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
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;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// FIXME(jseyfried) merge with `self.visit_macro()`
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
om.macros.push(Macro {
id: def.id,
def_id: def_id,
attrs: def.attrs.clone().into(),
name: def.ident.name,
whence: def.span,
Expand Down Expand Up @@ -513,12 +513,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}

// convert each exported_macro into a doc item
fn visit_macro(&self, def: &hir::MacroDef) -> 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,
Expand Down

0 comments on commit 3a82b0d

Please sign in to comment.