Use multiple lines for function calls with 0 arg which exceeds max width

e.g.

foo(
)
This commit is contained in:
topecongiro 2018-02-23 08:12:48 +09:00
parent c5a8878f7e
commit cb0097f7d8

View File

@ -2327,9 +2327,16 @@ pub fn wrap_args_with_parens(
shape: Shape, shape: Shape,
nested_shape: Shape, nested_shape: Shape,
) -> String { ) -> String {
let paren_overhead = paren_overhead(context);
let fits_one_line = args_str.len() + paren_overhead <= shape.width;
let extend_width = if args_str.is_empty() {
paren_overhead
} else {
paren_overhead / 2
};
if !context.use_block_indent() if !context.use_block_indent()
|| (context.inside_macro && !args_str.contains('\n') || (context.inside_macro && !args_str.contains('\n') && fits_one_line)
&& args_str.len() + paren_overhead(context) <= shape.width) || is_extendable || (is_extendable && extend_width <= shape.width)
{ {
let mut result = String::with_capacity(args_str.len() + 4); let mut result = String::with_capacity(args_str.len() + 4);
if context.config.spaces_within_parens_and_brackets() && !args_str.is_empty() { if context.config.spaces_within_parens_and_brackets() && !args_str.is_empty() {
@ -2348,8 +2355,10 @@ pub fn wrap_args_with_parens(
let mut result = let mut result =
String::with_capacity(args_str.len() + 2 + indent_str.len() + nested_indent_str.len()); String::with_capacity(args_str.len() + 2 + indent_str.len() + nested_indent_str.len());
result.push_str("("); result.push_str("(");
result.push_str(&nested_indent_str); if !args_str.is_empty() {
result.push_str(args_str); result.push_str(&nested_indent_str);
result.push_str(args_str);
}
result.push_str(&indent_str); result.push_str(&indent_str);
result.push_str(")"); result.push_str(")");
result result