Add a BraceStyle parameter to rewrite_where_clause

This allow it to exactly calculate if it needs to break the where clause into multiple lines
This commit is contained in:
Markus Westerlind 2015-12-01 19:51:49 +01:00
parent 052fddd4dd
commit 17fd2d073b

View File

@ -480,6 +480,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
let where_clause_str = try_opt!(rewrite_where_clause(context,
&generics.where_clause,
context.config,
context.config.item_brace_style,
context.block_indent,
where_budget,
context.config.where_density,
@ -695,6 +696,7 @@ fn format_tuple_struct(context: &RewriteContext,
let where_clause_str = try_opt!(rewrite_where_clause(context,
&generics.where_clause,
context.config,
context.config.item_brace_style,
context.block_indent,
where_budget,
Density::Compressed,
@ -1178,6 +1180,7 @@ fn rewrite_fn_base(context: &RewriteContext,
let where_clause_str = try_opt!(rewrite_where_clause(context,
where_clause,
context.config,
context.config.fn_brace_style,
indent,
where_budget,
where_density,
@ -1416,6 +1419,7 @@ fn rewrite_generics(context: &RewriteContext,
fn rewrite_where_clause(context: &RewriteContext,
where_clause: &ast::WhereClause,
config: &Config,
brace_style: BraceStyle,
indent: Indent,
width: usize,
density: Density,
@ -1474,7 +1478,7 @@ fn rewrite_where_clause(context: &RewriteContext,
let end_length = if terminator == "{" {
// If the brace is on the next line we don't need to count it otherwise it needs two
// characters " {"
match context.config.item_brace_style {
match brace_style {
BraceStyle::AlwaysNextLine => 0,
BraceStyle::PreferSameLine => 2,
BraceStyle::SameLineWhere => 0,
@ -1513,6 +1517,7 @@ fn format_generics(context: &RewriteContext,
let where_clause_str = try_opt!(rewrite_where_clause(context,
&generics.where_clause,
context.config,
brace_style,
context.block_indent,
budget,
Density::Tall,