]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: only show macro arm's lhs
authorJonas Schievink <jonas@schievink.net>
Thu, 26 Nov 2015 18:14:36 +0000 (19:14 +0100)
committerJonas Schievink <jonas@schievink.net>
Thu, 26 Nov 2015 18:14:36 +0000 (19:14 +0100)
src/librustdoc/clean/mod.rs
src/librustdoc/doctree.rs
src/librustdoc/visit_ast.rs

index c88b2dcdb748b5458747ad3971d3c64e6f5a7bf8..2bab56791872811912267df3411b09023ac6a436 100644 (file)
@@ -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),
             }),
         }
index 9550109fe9ff8279558b067ddcd4650f10c8927a..91da906f56df92519ca6ad35a4123b89e396ed11 100644 (file)
@@ -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>,
 }
index 150464404a22f860b88a7e1921f32c37cbf35e0b..17291233e114aa3ceedb60551fdc80b5cc27e3af 100644 (file)
@@ -400,11 +400,15 @@ pub fn visit_item(&mut self, item: &hir::Item,
 
     // 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,
         }