diff --git a/src/expr.rs b/src/expr.rs index 29edb0a3e3f..bb9e55e4f16 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1673,15 +1673,9 @@ fn rewrite_call_inner(context: &RewriteContext, one_line_width, force_trailing_comma) .ok_or(Ordering::Less)?; - let arg_one_line_budget = min(one_line_width, context.config.fn_call_width()); Ok(format!("{}{}", callee_str, - wrap_args_with_parens(context, - &list_str, - extendable, - arg_one_line_budget, - shape, - nested_shape))) + wrap_args_with_parens(context, &list_str, extendable, shape, nested_shape))) } fn rewrite_call_args(context: &RewriteContext, @@ -1771,12 +1765,16 @@ fn rewrite_call_args(context: &RewriteContext, config: context.config, }; - let args_in_single_line = + let almost_no_newline = item_vec .iter() .rev() .skip(1) .all(|item| item.item.as_ref().map_or(false, |s| !s.contains('\n'))); + let extendable = almost_no_newline && + item_vec.iter().fold(0, |acc, item| { + acc + item.item.as_ref().map_or(0, |s| 2 + first_line_width(s)) + }) <= min(one_line_width, context.config.fn_call_width()) + 2; match write_list(&item_vec, &fmt) { // If arguments do not fit in a single line and do not contain newline, @@ -1791,7 +1789,15 @@ fn rewrite_call_args(context: &RewriteContext, fmt.tactic = DefinitiveListTactic::Vertical; write_list(&item_vec, &fmt).map(|rw| (false, rw)) } - rewrite @ _ => rewrite.map(|rw| (args_in_single_line && is_extendable(args), rw)), + rewrite @ _ => { + rewrite.map(|rw| { + (extendable && + rw.chars() + .last() + .map_or(true, |c| force_trailing_comma || c != ','), + rw) + }) + } } } @@ -1841,14 +1847,11 @@ fn is_extendable(args: &[ptr::P]) -> bool { fn wrap_args_with_parens(context: &RewriteContext, args_str: &str, is_extendable: bool, - one_line_budget: usize, shape: Shape, nested_shape: Shape) -> String { if context.config.fn_call_style() == IndentStyle::Visual || - (context.inside_macro && !args_str.contains('\n')) || - ((is_extendable || !args_str.contains('\n')) && - first_line_width(&args_str) <= one_line_budget) { + (context.inside_macro && !args_str.contains('\n')) || is_extendable { if context.config.spaces_within_parens() && args_str.len() > 0 { format!("( {} )", args_str) } else { diff --git a/tests/source/configs-fn_call_style-block.rs b/tests/source/configs-fn_call_style-block.rs index 6708966fa69..6b5f00a9241 100644 --- a/tests/source/configs-fn_call_style-block.rs +++ b/tests/source/configs-fn_call_style-block.rs @@ -96,3 +96,17 @@ impl Cursor { }); } } + +fn issue1581() { + bootstrap.checks.register( + "PERSISTED_LOCATIONS", + move || if locations2.0.inner_mut.lock().poisoned { + Check::new( + State::Error, + "Persisted location storage is poisoned due to a write failure", + ) + } else { + Check::new(State::Healthy, "Persisted location storage is healthy") + }, + ); +} diff --git a/tests/target/configs-fn_call_style-block.rs b/tests/target/configs-fn_call_style-block.rs index 8149269158c..c50eb5bc8da 100644 --- a/tests/target/configs-fn_call_style-block.rs +++ b/tests/target/configs-fn_call_style-block.rs @@ -106,3 +106,17 @@ impl Cursor { }); } } + +fn issue1581() { + bootstrap.checks.register( + "PERSISTED_LOCATIONS", + move || if locations2.0.inner_mut.lock().poisoned { + Check::new( + State::Error, + "Persisted location storage is poisoned due to a write failure", + ) + } else { + Check::new(State::Healthy, "Persisted location storage is healthy") + }, + ); +}