]> git.lizzy.rs Git - rust.git/commitdiff
Do not handle comment when converting try
authorSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 06:03:36 +0000 (15:03 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Sun, 5 Aug 2018 06:03:36 +0000 (15:03 +0900)
As we get faulty span.

src/chains.rs

index 3a2462e8aec7beeb0110c82ea8fddca78a669407..391d8a599724a58e643a28f23164f12e859d9cf5 100644 (file)
@@ -262,13 +262,20 @@ fn from_ast(expr: &ast::Expr, context: &RewriteContext) -> Chain {
             }
         }
 
+        fn is_tries(s: &str) -> bool {
+            s.chars().all(|c| c == '?')
+        }
+
         let parent = rev_children.pop().unwrap();
         let mut children = vec![];
         let mut prev_hi = parent.span.hi();
         for chain_item in rev_children.into_iter().rev() {
             let comment_span = mk_sp(prev_hi, chain_item.span.lo());
             let comment_snippet = context.snippet(comment_span);
-            if !comment_snippet.trim().is_empty() {
+            if !(context.config.use_try_shorthand()
+                || comment_snippet.trim().is_empty()
+                || is_tries(comment_snippet.trim()))
+            {
                 children.push(ChainItem::comment(comment_span));
             }
             prev_hi = chain_item.span.hi();