Use SeperatorTactic::Never for a single argument

This commit is contained in:
topecongiro 2017-04-07 16:53:49 +09:00
parent 8579c1db0e
commit e7c6d34854
3 changed files with 12 additions and 6 deletions

View File

@ -1752,7 +1752,8 @@ fn rewrite_call_inner<R>(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

View File

@ -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<String> {
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)
}

View File

@ -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
{
}
}