Fix issues with empty macros with curly braces
This commit is contained in:
parent
8fd95df54a
commit
0e0cf976c9
@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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!{}
|
||||
}
|
||||
|
@ -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!{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user