about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRune Tynan <runetynan@gmail.com>2020-11-28 20:46:17 -0500
committerRune Tynan <runetynan@gmail.com>2020-11-28 20:51:48 -0500
commitff690931b7aeff7c1b0f5bf6a33ce2b1b980ab70 (patch)
treedc27072a25166c109daee0c77cfe00de08fe0c87
parenta61c09a897e671814ea104ace21a40eaac1d9a9c (diff)
downloadrust-ff690931b7aeff7c1b0f5bf6a33ce2b1b980ab70.tar.gz
rust-ff690931b7aeff7c1b0f5bf6a33ce2b1b980ab70.zip
Add support for multi-argument decl macros
-rw-r--r--src/librustdoc/clean/mod.rs28
-rw-r--r--src/test/rustdoc/decl_macro.rs17
2 files changed, 37 insertions, 8 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index f16ad40d6e2..54719e4d6a2 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2330,14 +2330,26 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
                     .collect::<String>(),
             )
         } else {
-            // This code currently assumes that there will only be one or zero matchers, as syntax
-            // for multiple is not currently defined.
-            format!(
-                "{}macro {}{} {{\n\t...\n}}",
-                item.vis.clean(cx).print_with_space(),
-                name,
-                matchers.iter().map(|span| span.to_src(cx)).collect::<String>(),
-            )
+            let vis = item.vis.clean(cx);
+
+            if matchers.len() <= 1 {
+                format!(
+                    "{}macro {}{} {{\n    ...\n}}",
+                    vis.print_with_space(),
+                    name,
+                    matchers.iter().map(|span| span.to_src(cx)).collect::<String>(),
+                )
+            } else {
+                format!(
+                    "{}macro {} {{\n{}}}",
+                    vis.print_with_space(),
+                    name,
+                    matchers
+                        .iter()
+                        .map(|span| { format!("    {} => {{ ... }},\n", span.to_src(cx)) })
+                        .collect::<String>(),
+                )
+            }
         };
 
         Item::from_hir_id_and_parts(
diff --git a/src/test/rustdoc/decl_macro.rs b/src/test/rustdoc/decl_macro.rs
index 45b4a3fac21..42a29799483 100644
--- a/src/test/rustdoc/decl_macro.rs
+++ b/src/test/rustdoc/decl_macro.rs
@@ -13,3 +13,20 @@ pub macro my_macro() {
 pub macro my_macro_2($($tok:tt)*) {
 
 }
+
+// @has decl_macro/macro.my_macro_multi.html //pre 'pub macro my_macro_multi {'
+// @has - //pre '(_) => { ... },'
+// @has - //pre '($foo:ident . $bar:expr) => { ... },'
+// @has - //pre '($($foo:literal),+) => { ... }'
+// @has - //pre '}'
+pub macro my_macro_multi {
+    (_) => {
+
+    },
+    ($foo:ident . $bar:expr) => {
+
+    },
+    ($($foo:literal),+) => {
+
+    }
+}