Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove doctree::Macro and distinguish between macro_rules! and pub macro #79455

Merged
merged 7 commits into from
Nov 29, 2020
28 changes: 20 additions & 8 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/decl_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
CraftSpider marked this conversation as resolved.
Show resolved Hide resolved
(_) => {

},
($foo:ident . $bar:expr) => {

},
($($foo:literal),+) => {

}
}