Check we can put the where clause on one line when we think we can

Fixes #1362
This commit is contained in:
Nick Cameron 2017-03-10 09:45:26 +13:00
parent 70085fca84
commit 4b60d94a99
2 changed files with 10 additions and 9 deletions

View File

@ -1636,6 +1636,7 @@ fn rewrite_fn_base(context: &RewriteContext,
} || (put_args_in_block && ret_str.is_empty());
if where_clause.predicates.len() == 1 && should_compress_where {
// TODO hitting this path, but using a newline
let budget = try_opt!(context.config.max_width.checked_sub(last_line_width(&result)));
if let Some(where_clause_str) =
rewrite_where_clause(context,
@ -1647,14 +1648,15 @@ fn rewrite_fn_base(context: &RewriteContext,
!has_body,
put_args_in_block && ret_str.is_empty(),
Some(span.hi)) {
if last_line_width(&result) + where_clause_str.len() > context.config.max_width &&
!where_clause_str.contains('\n') {
result.push('\n');
if !where_clause_str.contains('\n') {
if last_line_width(&result) + where_clause_str.len() > context.config.max_width {
result.push('\n');
}
result.push_str(&where_clause_str);
return Some((result, force_new_line_for_brace));
}
result.push_str(&where_clause_str);
return Some((result, force_new_line_for_brace));
}
}

View File

@ -78,8 +78,7 @@ pub trait Test {
fn very_long_function_name<F>(very_long_argument: F) -> MyVeryLongReturnType
where
F: FnMut(Self::Item)
-> bool
F: FnMut(Self::Item) -> bool
{
}