]> git.lizzy.rs Git - rust.git/commitdiff
Add Comment to ChainItemKind
authorSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 05:27:47 +0000 (14:27 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 05:27:47 +0000 (14:27 +0900)
src/chains.rs

index f6b1384b6b45bc601fb6748b1689b58396943e9a..8b7ca2fa93ae40314d57ac3097966ccdc0f3e9f5 100644 (file)
@@ -66,6 +66,7 @@
 //! ```
 
 use codemap::SpanUtils;
+use comment::rewrite_comment;
 use config::IndentStyle;
 use expr::rewrite_call;
 use macros::convert_try_mac;
@@ -117,6 +118,7 @@ enum ChainItemKind {
     ),
     StructField(ast::Ident),
     TupleField(ast::Ident, bool),
+    Comment,
 }
 
 impl ChainItemKind {
@@ -124,7 +126,9 @@ fn is_block_like(&self, context: &RewriteContext, reps: &str) -> bool {
         match self {
             ChainItemKind::Parent(ref expr) => is_block_expr(context, expr, reps),
             ChainItemKind::MethodCall(..) => reps.contains('\n'),
-            ChainItemKind::StructField(..) | ChainItemKind::TupleField(..) => false,
+            ChainItemKind::StructField(..)
+            | ChainItemKind::TupleField(..)
+            | ChainItemKind::Comment => false,
         }
     }
 
@@ -183,6 +187,9 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
             ChainItemKind::TupleField(ident, nested) => {
                 format!("{}.{}", if nested { " " } else { "" }, ident.name)
             }
+            ChainItemKind::Comment => {
+                rewrite_comment(context.snippet(self.span).trim(), false, shape, context.config)?
+            }
         };
         Some(format!("{}{}", rewrite, "?".repeat(self.tries)))
     }