From e7c6d348541d19fc93350aef71e5bcbb4bb5ae23 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 7 Apr 2017 16:53:49 +0900 Subject: [PATCH] Use SeperatorTactic::Never for a single argument --- src/expr.rs | 3 ++- src/items.rs | 9 +++++++-- tests/target/fn-custom-7.rs | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 5876409a9fa..f50b383b943 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1752,7 +1752,8 @@ fn rewrite_call_inner(context: &RewriteContext, tactic: tactic, separator: ",", trailing_separator: if force_no_trailing_comma || - context.config.fn_call_style == IndentStyle::Visual { + context.config.fn_call_style == IndentStyle::Visual || + args.len() <= 1 { SeparatorTactic::Never } else { context.config.trailing_comma diff --git a/src/items.rs b/src/items.rs index 0b2ca5a52cb..6e5f4b0802a 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1628,7 +1628,8 @@ fn rewrite_fn_base(context: &RewriteContext, indent, arg_indent, args_span, - fd.variadic)); + fd.variadic, + generics_str.contains('\n'))); let multi_line_arg_str = arg_str.contains('\n'); @@ -1783,7 +1784,8 @@ fn rewrite_args(context: &RewriteContext, indent: Indent, arg_indent: Indent, span: Span, - variadic: bool) + variadic: bool, + generics_str_contains_newline: bool) -> Option { let mut arg_item_strs = try_opt!(args.iter() @@ -1868,6 +1870,9 @@ enum ArgumentKind<'a> { } let (indent, trailing_comma, end_with_newline) = match context.config.fn_args_layout { + IndentStyle::Block if !generics_str_contains_newline && arg_items.len() <= 1 => { + (indent.block_indent(context.config), SeparatorTactic::Never, true) + } IndentStyle::Block => { (indent.block_indent(context.config), SeparatorTactic::Vertical, true) } diff --git a/tests/target/fn-custom-7.rs b/tests/target/fn-custom-7.rs index 0f5297e33ed..1a134128d2b 100644 --- a/tests/target/fn-custom-7.rs +++ b/tests/target/fn-custom-7.rs @@ -4,7 +4,7 @@ // rustfmt-fn_brace_style: AlwaysNextLine // Case with only one variable. -fn foo(a: u8,) -> u8 +fn foo(a: u8) -> u8 { bar() } @@ -30,11 +30,11 @@ fn foo( } trait Test { - fn foo(a: u8,) + fn foo(a: u8) { } - fn bar(a: u8,) -> String + fn bar(a: u8) -> String { } }