]> git.lizzy.rs Git - rust.git/commitdiff
Preserve macro formatting if we can't rewrite it
authorPhilip Craig <philipjcraig@gmail.com>
Mon, 3 Oct 2016 04:11:49 +0000 (14:11 +1000)
committerPhilip Craig <philipjcraig@gmail.com>
Mon, 3 Oct 2016 04:14:56 +0000 (14:14 +1000)
src/macros.rs
src/visitor.rs
tests/source/macros.rs
tests/target/macros.rs

index 9c275716ad21d0a7aaa23519973d4de7729ed4a1..dd301ad9de7b6fd115b0de85e069acb2bb9e9c39 100644 (file)
@@ -30,7 +30,6 @@
 use rewrite::{Rewrite, RewriteContext};
 use expr::{rewrite_call, rewrite_array};
 use comment::{FindUncommented, contains_comment};
-use utils::wrap_str;
 
 const FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
 
@@ -141,10 +140,7 @@ pub fn rewrite_macro(mac: &ast::Mac,
         }
         MacroStyle::Braces => {
             // Skip macro invocations with braces, for now.
-            wrap_str(context.snippet(mac.span),
-                     context.config.max_width,
-                     width,
-                     offset)
+            None
         }
     }
 }
index b0d5a91f1d80f9777bcd184d101c8a50fddc3fd1..f05fcefdfe8c4a1711427ee4f005576a77a386e7 100644 (file)
@@ -66,7 +66,6 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
             }
             ast::StmtKind::Mac(ref mac) => {
                 let (ref mac, _macro_style, _) = **mac;
-                self.format_missing_with_indent(source!(self, stmt.span).lo);
                 self.visit_mac(mac, None);
             }
         }
@@ -281,7 +280,6 @@ pub fn visit_item(&mut self, item: &ast::Item) {
                 self.format_mod(module, &item.vis, item.span, item.ident);
             }
             ast::ItemKind::Mac(ref mac) => {
-                self.format_missing_with_indent(source!(self, item.span).lo);
                 self.visit_mac(mac, Some(item.ident));
             }
             ast::ItemKind::ForeignMod(ref foreign_mod) => {
@@ -418,7 +416,6 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
                 self.push_rewrite(ii.span, rewrite);
             }
             ast::ImplItemKind::Macro(ref mac) => {
-                self.format_missing_with_indent(source!(self, ii.span).lo);
                 self.visit_mac(mac, Some(ii.ident));
             }
         }
@@ -428,11 +425,7 @@ fn visit_mac(&mut self, mac: &ast::Mac, ident: Option<ast::Ident>) {
         // 1 = ;
         let width = self.config.max_width - self.block_indent.width() - 1;
         let rewrite = rewrite_macro(mac, ident, &self.get_context(), width, self.block_indent);
-
-        if let Some(res) = rewrite {
-            self.buffer.push_str(&res);
-            self.last_pos = source!(self, mac.span).hi;
-        }
+        self.push_rewrite(mac.span, rewrite);
     }
 
     fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
index d04c204186c172de59f7fa6ff16d14a104fc2892..ca28d5c625b5735d5d137fbdcfddc414331fc12a 100644 (file)
@@ -50,6 +50,11 @@ fn main() {
     some_macro!{
         // comment
     };
+
+    some_macro!(
+        // comment
+        not function like
+    );
 }
 
 impl X {
index 902dd2e4d9add7fa97349c37cbade2ff89779329..79a42524939f45678d015d4bc2bf66156c4c086c 100644 (file)
@@ -53,6 +53,11 @@ fn main() {
     some_macro!{
         // comment
     };
+
+    some_macro!(
+        // comment
+        not function like
+    );
 }
 
 impl X {