diff --git a/src/items.rs b/src/items.rs index ac46c908a01..051fb0617d9 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1622,24 +1622,28 @@ fn rewrite_fn_base(context: &RewriteContext, // Check if vertical layout was forced. if one_line_budget == 0 { if snuggle_angle_bracket { - result.push_str("("); - } else if context.config.fn_args_paren_newline() { - result.push('\n'); - result.push_str(&arg_indent.to_string(context.config)); - arg_indent = arg_indent + 1; // extra space for `(` result.push('('); - if context.config.spaces_within_parens() && fd.inputs.len() > 0 { - result.push(' ') - } } else { - result.push_str("(\n"); - result.push_str(&arg_indent.to_string(context.config)); + if context.config.fn_args_paren_newline() { + result.push('\n'); + result.push_str(&arg_indent.to_string(context.config)); + if context.config.fn_args_layout() == IndentStyle::Visual { + arg_indent = arg_indent + 1; // extra space for `(` + } + result.push('('); + } else { + result.push_str("("); + if context.config.fn_args_layout() == IndentStyle::Visual { + result.push('\n'); + result.push_str(&arg_indent.to_string(context.config)); + } + } } } else { result.push('('); - if context.config.spaces_within_parens() && fd.inputs.len() > 0 { - result.push(' ') - } + } + if context.config.spaces_within_parens() && fd.inputs.len() > 0 && result.ends_with('(') { + result.push(' ') } if multi_line_ret_str { diff --git a/tests/target/issue-1624.rs b/tests/target/issue-1624.rs new file mode 100644 index 00000000000..dcdb18611a6 --- /dev/null +++ b/tests/target/issue-1624.rs @@ -0,0 +1,9 @@ +// rustfmt-fn_args_layout: Block +// rustfmt-fn_args_paren_newline: false + +// #1624 +pub unsafe fn some_long_function_name( + arg1: Type1, + arg2: Type2, +) -> (SomeLongTypeName, AnotherLongTypeName, AnotherLongTypeName) { +}