]> git.lizzy.rs Git - rust.git/commitdiff
Fix issues with empty macros with curly braces
authorMarcus Klaas <mail@marcusklaas.nl>
Sun, 27 Mar 2016 11:44:08 +0000 (13:44 +0200)
committerMarcus Klaas <mail@marcusklaas.nl>
Sun, 27 Mar 2016 11:44:40 +0000 (13:44 +0200)
src/macros.rs
tests/source/macros.rs
tests/target/macros.rs

index 324c68d750af5e345c4457dd236b2a2e4758fb2f..620dd9d98f6e11e09785694c27bc4baebcec06e5 100644 (file)
@@ -27,7 +27,7 @@
 use Indent;
 use rewrite::RewriteContext;
 use expr::{rewrite_call, rewrite_array};
-use comment::FindUncommented;
+use comment::{FindUncommented, contains_comment};
 use utils::{CodeMapSpanUtils, wrap_str};
 
 const FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
@@ -63,11 +63,11 @@ pub fn rewrite_macro(mac: &ast::Mac,
         original_style
     };
 
-    if mac.node.tts.is_empty() {
-        return if let MacroStyle::Parens = style {
-            Some(format!("{}()", macro_name))
-        } else {
-            Some(format!("{}[]", macro_name))
+    if mac.node.tts.is_empty() && !contains_comment(&context.snippet(mac.span)) {
+        return match style {
+            MacroStyle::Parens => Some(format!("{}()", macro_name)),
+            MacroStyle::Brackets => Some(format!("{}[]", macro_name)),
+            MacroStyle::Braces => Some(format!("{}{{}}", macro_name)),
         };
     }
 
index 261f02e756f57540b74983953fba5c81b0997faf..cafc4522ef7cfcc626c301d3f828e118ea567cf8 100644 (file)
@@ -33,4 +33,23 @@ fn main() {
     macrowithbraces! {dont,    format, me}
 
     x!(fn);
+
+    some_macro!(
+        
+    );
+
+    some_macro![
+    ];
+
+    some_macro!{
+        // comment
+    };
+
+    some_macro!{
+        // comment
+    };
+}
+
+impl X {
+    empty_invoc!{}
 }
index 4d99ede9f5054a91377fa2e03462000fe67b205f..a463947d985ea2709c9673ef40e0f2a04d499964 100644 (file)
@@ -39,4 +39,20 @@ fn main() {
     macrowithbraces! {dont,    format, me}
 
     x!(fn);
+
+    some_macro!();
+
+    some_macro![];
+
+    some_macro!{
+        // comment
+    };
+
+    some_macro!{
+        // comment
+    };
+}
+
+impl X {
+    empty_invoc!{}
 }