Skip to content

Commit ff69093

Browse files
committed
Add support for multi-argument decl macros
1 parent a61c09a commit ff69093

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/librustdoc/clean/mod.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -2330,14 +2330,26 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
23302330
.collect::<String>(),
23312331
)
23322332
} else {
2333-
// This code currently assumes that there will only be one or zero matchers, as syntax
2334-
// for multiple is not currently defined.
2335-
format!(
2336-
"{}macro {}{} {{\n\t...\n}}",
2337-
item.vis.clean(cx).print_with_space(),
2338-
name,
2339-
matchers.iter().map(|span| span.to_src(cx)).collect::<String>(),
2340-
)
2333+
let vis = item.vis.clean(cx);
2334+
2335+
if matchers.len() <= 1 {
2336+
format!(
2337+
"{}macro {}{} {{\n ...\n}}",
2338+
vis.print_with_space(),
2339+
name,
2340+
matchers.iter().map(|span| span.to_src(cx)).collect::<String>(),
2341+
)
2342+
} else {
2343+
format!(
2344+
"{}macro {} {{\n{}}}",
2345+
vis.print_with_space(),
2346+
name,
2347+
matchers
2348+
.iter()
2349+
.map(|span| { format!(" {} => {{ ... }},\n", span.to_src(cx)) })
2350+
.collect::<String>(),
2351+
)
2352+
}
23412353
};
23422354

23432355
Item::from_hir_id_and_parts(

src/test/rustdoc/decl_macro.rs

+17
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ pub macro my_macro() {
1313
pub macro my_macro_2($($tok:tt)*) {
1414

1515
}
16+
17+
// @has decl_macro/macro.my_macro_multi.html //pre 'pub macro my_macro_multi {'
18+
// @has - //pre '(_) => { ... },'
19+
// @has - //pre '($foo:ident . $bar:expr) => { ... },'
20+
// @has - //pre '($($foo:literal),+) => { ... }'
21+
// @has - //pre '}'
22+
pub macro my_macro_multi {
23+
(_) => {
24+
25+
},
26+
($foo:ident . $bar:expr) => {
27+
28+
},
29+
($($foo:literal),+) => {
30+
31+
}
32+
}

0 commit comments

Comments
 (0)