Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 70177a0

Browse files
committed
Format a macro call with multile item-like arguments
1 parent baa20df commit 70177a0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/macros.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ pub enum MacroArg {
6464
Item(ptr::P<ast::Item>),
6565
}
6666

67+
impl MacroArg {
68+
fn is_item(&self) -> bool {
69+
match self {
70+
MacroArg::Item(..) => true,
71+
_ => false,
72+
}
73+
}
74+
}
75+
6776
impl Rewrite for ast::Item {
6877
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
6978
let mut visitor = ::visitor::FmtVisitor::from_context(context);
@@ -260,6 +269,7 @@ pub fn rewrite_macro_inner(
260269
}
261270
return return_original_snippet_with_failure_marked(context, mac.span);
262271
}
272+
_ if arg_vec.last().map_or(false, MacroArg::is_item) => continue,
263273
_ => return return_original_snippet_with_failure_marked(context, mac.span),
264274
}
265275

@@ -272,13 +282,7 @@ pub fn rewrite_macro_inner(
272282
}
273283
}
274284

275-
if !arg_vec.is_empty() && arg_vec.iter().all(|arg| {
276-
if let MacroArg::Item(..) = arg {
277-
true
278-
} else {
279-
false
280-
}
281-
}) {
285+
if !arg_vec.is_empty() && arg_vec.iter().all(MacroArg::is_item) {
282286
return rewrite_macro_with_items(
283287
context,
284288
&arg_vec,

0 commit comments

Comments
 (0)