]> git.lizzy.rs Git - rust.git/commitdiff
Veto putting a chain with comment in a single line
authorSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 05:34:34 +0000 (14:34 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 05:34:34 +0000 (14:34 +0900)
src/chains.rs

index a6bffd8f2fbd3f2d2342c231fb2043f270e186d2..25c3a8bbdd7cb7e6b3825a48fa6f1b1c10dda11c 100644 (file)
@@ -209,6 +209,13 @@ fn comment(span: Span) -> ChainItem {
         }
     }
 
+    fn is_comment(&self) -> bool {
+        match self.kind {
+            ChainItemKind::Comment => true,
+            _ => false,
+        }
+    }
+
     fn rewrite_method_call(
         method_name: ast::Ident,
         types: &[ast::GenericArg],
@@ -458,7 +465,9 @@ fn format_last_child(
         }.saturating_sub(almost_total);
 
         let all_in_one_line =
-            self.rewrites.iter().all(|s| !s.contains('\n')) && one_line_budget > 0;
+            !self.children.iter().any(ChainItem::is_comment)
+            && self.rewrites.iter().all(|s| !s.contains('\n'))
+            && one_line_budget > 0;
         let last_shape = if all_in_one_line {
             shape.sub_width(last.tries)?
         } else if extendable {