From 052fddd4ddd64d3b1a54aa50cb57e95b7d6cbdcc Mon Sep 17 00:00:00 2001 From: Markus Westerlind <marwes91@gmail.com> Date: Sat, 28 Nov 2015 13:59:14 +0100 Subject: [PATCH] Use the BraceStyle config to calculate the width for braces in where clasues --- src/items.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/items.rs b/src/items.rs index f1be0ed76a1..a3eb7f7a4c9 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1471,12 +1471,16 @@ fn rewrite_where_clause(context: &RewriteContext, }; let preds_str = try_opt!(write_list(&item_vec, &fmt)); - // When '{' is the terminator just assume that it is put on the next line for single line where - // clauses - let end_length = if terminator == ";" { - 1 + 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 { + BraceStyle::AlwaysNextLine => 0, + BraceStyle::PreferSameLine => 2, + BraceStyle::SameLineWhere => 0, + } } else { - 0 + terminator.len() }; if density == Density::Tall || preds_str.contains('\n') || indent.width() + " where ".len() + preds_str.len() + end_length > width {