Skip to content

Commit ccb9cc1

Browse files
committed
Remove doctree::Macro
1 parent fd6b537 commit ccb9cc1

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,21 +2313,28 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
23132313
}
23142314
}
23152315

2316-
impl Clean<Item> for doctree::Macro {
2316+
impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
23172317
fn clean(&self, cx: &DocContext<'_>) -> Item {
2318+
let (item, renamed) = self;
2319+
let name = renamed.unwrap_or(item.ident).name;
2320+
let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
2321+
// Extract the spans of all matchers. They represent the "interface" of the macro.
2322+
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect::<Vec<_>>();
2323+
23182324
Item::from_def_id_and_parts(
2319-
self.def_id,
2320-
Some(self.name.clean(cx)),
2325+
cx.tcx.hir().local_def_id(item.hir_id).to_def_id(),
2326+
Some(name.clean(cx)),
23212327
MacroItem(Macro {
2328+
// FIXME(#76761): Make this respect `macro_rules!` vs `pub macro`
23222329
source: format!(
23232330
"macro_rules! {} {{\n{}}}",
2324-
self.name,
2325-
self.matchers
2331+
name,
2332+
matchers
23262333
.iter()
23272334
.map(|span| { format!(" {} => {{ ... }};\n", span.to_src(cx)) })
2328-
.collect::<String>()
2335+
.collect::<String>(),
23292336
),
2330-
imported_from: self.imported_from.clean(cx),
2337+
imported_from: None,
23312338
}),
23322339
cx,
23332340
)

src/librustdoc/doctree.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ crate struct Module<'hir> {
1818
// (item, renamed)
1919
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
2020
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
21-
crate macros: Vec<Macro>,
21+
crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Ident>)>,
2222
crate is_crate: bool,
2323
}
2424

@@ -56,15 +56,6 @@ crate struct Variant<'hir> {
5656
crate def: &'hir hir::VariantData<'hir>,
5757
}
5858

59-
// For Macro we store the DefId instead of the NodeId, since we also create
60-
// these imported macro_rules (which only have a DUMMY_NODE_ID).
61-
crate struct Macro {
62-
crate name: Symbol,
63-
crate def_id: hir::def_id::DefId,
64-
crate matchers: Vec<Span>,
65-
crate imported_from: Option<Symbol>,
66-
}
67-
6859
#[derive(Debug)]
6960
crate struct Import<'hir> {
7061
crate name: Symbol,

src/librustdoc/visit_ast.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
7171
None,
7272
);
7373
// Attach the crate's exported macros to the top-level module:
74-
module
75-
.macros
76-
.extend(krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)));
74+
module.macros.extend(krate.exported_macros.iter().map(|def| (def, None)));
7775
module.is_crate = true;
7876

7977
self.cx.renderinfo.get_mut().exact_paths = self.exact_paths;
@@ -216,7 +214,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
216214
true
217215
}
218216
Node::MacroDef(def) if !glob => {
219-
om.macros.push(self.visit_local_macro(def, renamed.map(|i| i.name)));
217+
om.macros.push((def, renamed));
220218
true
221219
}
222220
_ => false,
@@ -339,19 +337,4 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
339337
om.foreigns.push((item, renamed));
340338
}
341339
}
342-
343-
// Convert each `exported_macro` into a doc item.
344-
fn visit_local_macro(&self, def: &'tcx hir::MacroDef<'_>, renamed: Option<Symbol>) -> Macro {
345-
debug!("visit_local_macro: {}", def.ident);
346-
let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>();
347-
// Extract the spans of all matchers. They represent the "interface" of the macro.
348-
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
349-
350-
Macro {
351-
def_id: self.cx.tcx.hir().local_def_id(def.hir_id).to_def_id(),
352-
name: renamed.unwrap_or(def.ident.name),
353-
matchers,
354-
imported_from: None,
355-
}
356-
}
357340
}

0 commit comments

Comments
 (0)