about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-26 16:35:34 +0900
committertopecongiro <seuchida@gmail.com>2017-05-26 16:35:34 +0900
commit15b988aed3d2d4ec761452840ed96b84080c2abc (patch)
tree01b6ad6b88e4bb5ff0162342ebc4c09788626ca2 /src/expr.rs
parentb748fe8bec300afb4eb6b7923c74152c588a5eb8 (diff)
Allow macro to nested and overflowed like function call
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 808cd06c2d2..0abeafaefc2 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1772,13 +1772,17 @@ fn rewrite_call_args(context: &RewriteContext,
         acc + item.item.as_ref().map_or(0, |s| 2 + first_line_width(s))
     }) <= one_line_budget + 2;
 
-    match write_list(&item_vec, &fmt) {
+    let result = write_list(&item_vec, &fmt);
+    let last_char_is_not_comma = result
+        .as_ref()
+        .map_or(false, |r| r.chars().last().unwrap_or(' ') != ',');
+    match result {
         // If arguments do not fit in a single line and do not contain newline,
         // try to put it on the next line. Try this only when we are in block mode
         // and not rewriting macro.
         Some(ref s) if context.config.fn_call_style() == IndentStyle::Block &&
                        !context.inside_macro &&
-                       ((!can_be_overflowed(context, args) && args.len() == 1 &&
+                       ((!can_be_overflowed(&context, args) && last_char_is_not_comma &&
                          s.contains('\n')) ||
                         first_line_width(s) > one_line_budget) => {
             fmt.trailing_separator = SeparatorTactic::Vertical;
@@ -1786,13 +1790,7 @@ fn rewrite_call_args(context: &RewriteContext,
             write_list(&item_vec, &fmt).map(|rw| (false, rw))
         }
         rewrite @ _ => {
-            rewrite.map(|rw| {
-                            (extendable &&
-                             rw.chars()
-                                 .last()
-                                 .map_or(true, |c| force_trailing_comma || c != ','),
-                             rw)
-                        })
+            rewrite.map(|rw| (extendable && (last_char_is_not_comma || force_trailing_comma), rw))
         }
     }
 }
@@ -1809,6 +1807,7 @@ fn can_be_overflowed(context: &RewriteContext, args: &[ptr::P<ast::Expr>]) -> bo
             context.config.fn_call_style() == IndentStyle::Visual && args.len() > 1
         }
         Some(&ast::ExprKind::Call(..)) |
+        Some(&ast::ExprKind::Mac(..)) |
         Some(&ast::ExprKind::Struct(..)) => {
             context.config.fn_call_style() == IndentStyle::Block && args.len() == 1
         }
@@ -1824,6 +1823,7 @@ fn is_extendable(args: &[ptr::P<ast::Expr>]) -> bool {
             ast::ExprKind::Call(..) |
             ast::ExprKind::Closure(..) |
             ast::ExprKind::Match(..) |
+            ast::ExprKind::Mac(..) |
             ast::ExprKind::Struct(..) |
             ast::ExprKind::Tup(..) => true,
             _ => false,