mirror of https://github.com/rust-lang/rust.git
Add support for multi-argument decl macros
This commit is contained in:
parent
a61c09a897
commit
ff690931b7
|
@ -2330,14 +2330,26 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// This code currently assumes that there will only be one or zero matchers, as syntax
|
let vis = item.vis.clean(cx);
|
||||||
// for multiple is not currently defined.
|
|
||||||
format!(
|
if matchers.len() <= 1 {
|
||||||
"{}macro {}{} {{\n\t...\n}}",
|
format!(
|
||||||
item.vis.clean(cx).print_with_space(),
|
"{}macro {}{} {{\n ...\n}}",
|
||||||
name,
|
vis.print_with_space(),
|
||||||
matchers.iter().map(|span| span.to_src(cx)).collect::<String>(),
|
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(
|
Item::from_hir_id_and_parts(
|
||||||
|
|
|
@ -13,3 +13,20 @@ pub macro my_macro() {
|
||||||
pub macro my_macro_2($($tok:tt)*) {
|
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),+) => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue