]> git.lizzy.rs Git - rust.git/commitdiff
snuggle where
authorcsmoe <35686186+csmoe@users.noreply.github.com>
Thu, 31 May 2018 10:33:45 +0000 (18:33 +0800)
committercsmoe <35686186+csmoe@users.noreply.github.com>
Thu, 31 May 2018 10:33:45 +0000 (18:33 +0800)
src/items.rs

index 2aa53a1632ba26a2b3e6a4d61494f2f5d83d1ce0..872d736f15f070ab03589ddd68653121caa36f04 100644 (file)
@@ -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(