From 7297bc320fa148773f1615c211429ca7dfe3332e Mon Sep 17 00:00:00 2001 From: Jeremy Wazny Date: Tue, 26 Jan 2016 15:53:04 +1100 Subject: [PATCH] Limit when we emit a trailing where clause comma. --- src/items.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/items.rs b/src/items.rs index f725ccf0153..2ff52148f6a 100644 --- a/src/items.rs +++ b/src/items.rs @@ -491,6 +491,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - where_budget, context.config.where_density, "{", + true, None)); if try_opt!(is_impl_single_line(context, &items, &result, &where_clause_str, &item)) { @@ -737,6 +738,7 @@ fn format_tuple_struct(context: &RewriteContext, where_budget, Density::Compressed, ";", + false, None)) } None => "".to_owned(), @@ -818,6 +820,7 @@ pub fn rewrite_type_alias(context: &RewriteContext, where_budget, context.config.where_density, "=", + false, Some(span.hi))); result.push_str(&where_clause_str); result.push_str(" = "); @@ -1248,6 +1251,7 @@ fn rewrite_fn_base(context: &RewriteContext, where_budget, where_density, "{", + has_body, Some(span.hi))); if last_line_width(&result) + where_clause_str.len() > context.config.max_width && @@ -1487,6 +1491,7 @@ fn rewrite_where_clause(context: &RewriteContext, width: usize, density: Density, terminator: &str, + allow_trailing_comma: bool, span_end: Option) -> Option { if where_clause.predicates.is_empty() { @@ -1526,11 +1531,12 @@ fn rewrite_where_clause(context: &RewriteContext, // FIXME: we don't need to collect here if the where_layout isn't // HorizontalVertical. let tactic = definitive_tactic(&item_vec, context.config.where_layout, budget); + let use_trailing_comma = allow_trailing_comma && context.config.where_trailing_comma; let fmt = ListFormatting { tactic: tactic, separator: ",", - trailing_separator: SeparatorTactic::from_bool(context.config.where_trailing_comma), + trailing_separator: SeparatorTactic::from_bool(use_trailing_comma), indent: offset, width: budget, ends_with_newline: true, @@ -1592,6 +1598,7 @@ fn format_generics(context: &RewriteContext, budget, Density::Tall, terminator, + true, Some(span.hi))); result.push_str(&where_clause_str); if !force_same_line_brace &&