From 70177a08a47eb6e3a84cee4d92c0eb4ccbd125c4 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Mon, 8 Oct 2018 13:49:24 +0900 Subject: [PATCH] Format a macro call with multile item-like arguments --- src/macros.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 7348e7a0315..dab27d8a073 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -64,6 +64,15 @@ pub enum MacroArg { Item(ptr::P), } +impl MacroArg { + fn is_item(&self) -> bool { + match self { + MacroArg::Item(..) => true, + _ => false, + } + } +} + impl Rewrite for ast::Item { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { let mut visitor = ::visitor::FmtVisitor::from_context(context); @@ -260,6 +269,7 @@ pub fn rewrite_macro_inner( } return return_original_snippet_with_failure_marked(context, mac.span); } + _ if arg_vec.last().map_or(false, MacroArg::is_item) => continue, _ => return return_original_snippet_with_failure_marked(context, mac.span), } @@ -272,13 +282,7 @@ pub fn rewrite_macro_inner( } } - if !arg_vec.is_empty() && arg_vec.iter().all(|arg| { - if let MacroArg::Item(..) = arg { - true - } else { - false - } - }) { + if !arg_vec.is_empty() && arg_vec.iter().all(MacroArg::is_item) { return rewrite_macro_with_items( context, &arg_vec,