From 0e0cf976c9293627ea318eec6211e62326375abe Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Sun, 27 Mar 2016 13:44:08 +0200 Subject: [PATCH] Fix issues with empty macros with curly braces --- src/macros.rs | 12 ++++++------ tests/source/macros.rs | 19 +++++++++++++++++++ tests/target/macros.rs | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 324c68d750a..620dd9d98f6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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)), }; } diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 261f02e756f..cafc4522ef7 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -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!{} } diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 4d99ede9f50..a463947d985 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -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!{} } -- 2.44.0