]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #1811 from topecongiro/rustfmt-skip-on-stmt
authorNick Cameron <nrc@ncameron.org>
Sat, 22 Jul 2017 04:07:25 +0000 (16:07 +1200)
committerGitHub <noreply@github.com>
Sat, 22 Jul 2017 04:07:25 +0000 (16:07 +1200)
Support rustfmt_skip on statements

src/visitor.rs
tests/source/skip.rs
tests/target/skip.rs

index e6e7f038ce7c70bfdc6acd3d09d6aa24560033ab..813f5422f2c46f30d9fc3a761de5d0b9b0ef0fbe 100644 (file)
@@ -26,7 +26,7 @@
 use lists::{itemize_list, write_list, DefinitiveListTactic, ListFormatting, SeparatorTactic};
 use macros::{rewrite_macro, MacroPosition};
 use rewrite::{Rewrite, RewriteContext};
-use utils::{self, mk_sp};
+use utils::{self, contains_skip, mk_sp};
 
 fn is_use_item(item: &ast::Item) -> bool {
     match item.node {
@@ -79,11 +79,15 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
             ast::StmtKind::Item(ref item) => {
                 self.visit_item(item);
             }
-            ast::StmtKind::Local(..) => {
-                let rewrite = stmt.rewrite(
-                    &self.get_context(),
-                    Shape::indented(self.block_indent, self.config),
-                );
+            ast::StmtKind::Local(ref local) => {
+                let rewrite = if contains_skip(&local.attrs) {
+                    None
+                } else {
+                    stmt.rewrite(
+                        &self.get_context(),
+                        Shape::indented(self.block_indent, self.config),
+                    )
+                };
                 self.push_rewrite(stmt.span, rewrite);
             }
             ast::StmtKind::Expr(ref expr) => {
@@ -113,8 +117,12 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
                 self.push_rewrite(span, rewrite)
             }
             ast::StmtKind::Mac(ref mac) => {
-                let (ref mac, _macro_style, _) = **mac;
-                self.visit_mac(mac, None, MacroPosition::Statement);
+                let (ref mac, _macro_style, ref attrs) = **mac;
+                if contains_skip(attrs) {
+                    self.push_rewrite(mac.span, None);
+                } else {
+                    self.visit_mac(mac, None, MacroPosition::Statement);
+                }
                 self.format_missing(stmt.span.hi);
             }
         }
index d13c815903984f9136aaf520de705ba9eb795c77..69c7b53a57b088670b9fd589363540032618f18b 100644 (file)
@@ -29,3 +29,37 @@ fn issue1346() {
         }
     }))
 }
+
+fn skip_on_statements() {
+    // Semi
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    foo(
+        1, 2, 3, 4,
+        1, 2,
+        1, 2, 3,
+    );
+
+    // Local
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    let x = foo(  a,   b  ,  c);
+
+    // Item
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    use   foobar  ;
+
+    // Mac
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    vec![
+        1, 2, 3, 4,
+        1, 2, 3, 4,
+        1, 2, 3, 4,
+        1, 2, 3,
+        1,
+        1, 2,
+        1,
+    ];
+
+    // Expr
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    foo(  a,   b  ,  c)
+}
index d13c815903984f9136aaf520de705ba9eb795c77..69c7b53a57b088670b9fd589363540032618f18b 100644 (file)
@@ -29,3 +29,37 @@ fn issue1346() {
         }
     }))
 }
+
+fn skip_on_statements() {
+    // Semi
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    foo(
+        1, 2, 3, 4,
+        1, 2,
+        1, 2, 3,
+    );
+
+    // Local
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    let x = foo(  a,   b  ,  c);
+
+    // Item
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    use   foobar  ;
+
+    // Mac
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    vec![
+        1, 2, 3, 4,
+        1, 2, 3, 4,
+        1, 2, 3, 4,
+        1, 2, 3,
+        1,
+        1, 2,
+        1,
+    ];
+
+    // Expr
+    #[cfg_attr(rustfmt, rustfmt_skip)]
+    foo(  a,   b  ,  c)
+}