From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Thu, 31 May 2018 10:33:45 +0000 (+0800) Subject: snuggle where X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=0468c134f4d1fd72452a55a8a09eeaf93b70e557;p=rust.git snuggle where --- diff --git a/src/items.rs b/src/items.rs index 2aa53a1632b..872d736f15f 100644 --- a/src/items.rs +++ b/src/items.rs @@ -651,9 +651,15 @@ pub fn format_impl( }; let mut option = WhereClauseOption::snuggled(&ref_and_type); - if items.is_empty() && generics.where_clause.predicates.len() == 1 { - option.compress_where(); + let snippet = context.snippet(item.span); + let open_pos = snippet.find_uncommented("{")? + 1; + if !contains_comment(&snippet[open_pos..]) + && items.is_empty() + && generics.where_clause.predicates.len() == 1 + { option.suppress_comma(); + option.snuggle(); + option.compress_where(); } let mut where_clause_str = rewrite_where_clause( @@ -1386,9 +1392,9 @@ fn format_tuple_struct( // We need to put the where clause on a new line, but we didn't // know that earlier, so the where clause will not be indented properly. result.push('\n'); - result - .push_str(&(offset.block_only() + (context.config.tab_spaces() - 1)) - .to_string(context.config)); + result.push_str( + &(offset.block_only() + (context.config.tab_spaces() - 1)).to_string(context.config), + ); } result.push_str(&where_clause_str); @@ -2147,6 +2153,10 @@ pub fn suppress_comma(&mut self) { pub fn compress_where(&mut self) { self.compress_where = true } + + pub fn snuggle(&mut self) { + self.snuggle = true + } } fn rewrite_args(