Skip to content

Commit ce97479

Browse files
rustdoc: only show macro arm's lhs
1 parent 1b9a13e commit ce97479

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,15 +2665,18 @@ pub struct Macro {
26652665

26662666
impl Clean<Item> for doctree::Macro {
26672667
fn clean(&self, cx: &DocContext) -> Item {
2668+
let name = format!("{}!", self.name.clean(cx));
26682669
Item {
2669-
name: Some(format!("{}!", self.name.clean(cx))),
2670+
name: Some(name.clone()),
26702671
attrs: self.attrs.clean(cx),
26712672
source: self.whence.clean(cx),
26722673
visibility: hir::Public.clean(cx),
26732674
stability: self.stab.clean(cx),
26742675
def_id: cx.map.local_def_id(self.id),
26752676
inner: MacroItem(Macro {
2676-
source: self.whence.to_src(cx),
2677+
source: format!("macro_rules! {} {{\n{}}}",
2678+
name.trim_right_matches('!'), self.matchers.iter().map(|span|
2679+
format!(" {} => {{ ... }}\n", span.to_src(cx))).collect::<String>()),
26772680
imported_from: self.imported_from.clean(cx),
26782681
}),
26792682
}

src/librustdoc/doctree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub struct Macro {
213213
pub id: ast::NodeId,
214214
pub attrs: Vec<ast::Attribute>,
215215
pub whence: Span,
216+
pub matchers: Vec<Span>,
216217
pub stab: Option<attr::Stability>,
217218
pub imported_from: Option<Name>,
218219
}

src/librustdoc/visit_ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
400400

401401
// convert each exported_macro into a doc item
402402
fn visit_macro(&self, def: &hir::MacroDef) -> Macro {
403+
// Extract the spans of all matchers. They represent the "interface" of the macro.
404+
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
405+
403406
Macro {
404407
id: def.id,
405408
attrs: def.attrs.clone(),
406409
name: def.name,
407410
whence: def.span,
411+
matchers: matchers,
408412
stab: self.stability(def.id),
409413
imported_from: def.imported_from,
410414
}

0 commit comments

Comments
 (0)