From 4c4f70957bc40f9aae377ec67af62f6f3c4aa9f9 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Mon, 3 Apr 2017 17:39:14 -0600 Subject: [PATCH] fix bug by adding boolean argument Signed-off-by: Ryan1729 --- src/chains.rs | 2 +- src/expr.rs | 29 +++++++++++++++++++++-------- src/macros.rs | 5 +++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 23085bb66e2..2c2b4ef63ea 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -441,5 +441,5 @@ fn rewrite_method_call(method_name: ast::Ident, let callee_str = format!(".{}{}", method_name, type_str); let span = mk_sp(lo, span.hi); - rewrite_call(context, &callee_str, &args[1..], span, shape) + rewrite_call(context, &callee_str, &args[1..], span, shape, false) } diff --git a/src/expr.rs b/src/expr.rs index 91b17db5d23..6561d3faf62 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -71,7 +71,7 @@ fn format_expr(expr: &ast::Expr, } ast::ExprKind::Call(ref callee, ref args) => { let inner_span = mk_sp(callee.span.hi, expr.span.hi); - rewrite_call(context, &**callee, args, inner_span, shape) + rewrite_call(context, &**callee, args, inner_span, shape, false) } ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape), ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => { @@ -1597,12 +1597,20 @@ pub fn rewrite_call(context: &RewriteContext, callee: &R, args: &[ptr::P], span: Span, - shape: Shape) + shape: Shape, + force_no_trailing_comma: bool) -> Option where R: Rewrite { - let closure = - |callee_max_width| rewrite_call_inner(context, callee, callee_max_width, args, span, shape); + let closure = |callee_max_width| { + rewrite_call_inner(context, + callee, + callee_max_width, + args, + span, + shape, + force_no_trailing_comma) + }; // 2 is for parens let max_width = try_opt!(shape.width.checked_sub(2)); @@ -1614,7 +1622,8 @@ fn rewrite_call_inner(context: &RewriteContext, max_callee_width: usize, args: &[ptr::P], span: Span, - shape: Shape) + shape: Shape, + force_no_trailing_comma: bool) -> Result where R: Rewrite { @@ -1721,9 +1730,13 @@ fn rewrite_call_inner(context: &RewriteContext, let fmt = ListFormatting { tactic: tactic, separator: ",", - trailing_separator: match context.config.fn_call_style { - IndentStyle::Visual => SeparatorTactic::Never, - IndentStyle::Block => context.config.trailing_comma, + trailing_separator: if force_no_trailing_comma { + SeparatorTactic::Never + } else { + match context.config.fn_call_style { + IndentStyle::Visual => SeparatorTactic::Never, + IndentStyle::Block => context.config.trailing_comma, + } }, shape: nested_shape, ends_with_newline: false, diff --git a/src/macros.rs b/src/macros.rs index 9d1367ebadc..fd5578e7f00 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -144,8 +144,9 @@ pub fn rewrite_macro(mac: &ast::Mac, match style { MacroStyle::Parens => { - // Format macro invocation as function call. - rewrite_call(context, ¯o_name, &expr_vec, mac.span, shape).map(|rw| { + // Format macro invocation as function call, forcing no trailing + // comma because not all macros support them. + rewrite_call(context, ¯o_name, &expr_vec, mac.span, shape, true).map(|rw| { match position { MacroPosition::Item => format!("{};", rw), _ => rw,