Skip to content

Commit

Permalink
rustdoc: only show macro arm's lhs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Nov 26, 2015
1 parent 1b9a13e commit ce97479
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -2665,15 +2665,18 @@ pub struct Macro {

impl Clean<Item> for doctree::Macro {
fn clean(&self, cx: &DocContext) -> Item {
let name = format!("{}!", self.name.clean(cx));
Item {
name: Some(format!("{}!", self.name.clean(cx))),
name: Some(name.clone()),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
visibility: hir::Public.clean(cx),
stability: self.stab.clean(cx),
def_id: cx.map.local_def_id(self.id),
inner: MacroItem(Macro {
source: self.whence.to_src(cx),
source: format!("macro_rules! {} {{\n{}}}",
name.trim_right_matches('!'), self.matchers.iter().map(|span|
format!(" {} => {{ ... }}\n", span.to_src(cx))).collect::<String>()),
imported_from: self.imported_from.clean(cx),
}),
}
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/doctree.rs
Expand Up @@ -213,6 +213,7 @@ pub struct Macro {
pub id: ast::NodeId,
pub attrs: Vec<ast::Attribute>,
pub whence: Span,
pub matchers: Vec<Span>,
pub stab: Option<attr::Stability>,
pub imported_from: Option<Name>,
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -400,11 +400,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {

// convert each exported_macro into a doc item
fn visit_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,
attrs: def.attrs.clone(),
name: def.name,
whence: def.span,
matchers: matchers,
stab: self.stability(def.id),
imported_from: def.imported_from,
}
Expand Down

0 comments on commit ce97479

Please sign in to comment.