Fix issues with empty macros with curly braces

This commit is contained in:
Marcus Klaas 2016-03-27 13:44:08 +02:00
parent 8fd95df54a
commit 0e0cf976c9
3 changed files with 41 additions and 6 deletions

View 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)),
};
}

View 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!{}
}

View 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!{}
}