Preserve possibly one whitespace for brace macros

This commit is contained in:
Kevin Stenerson 2018-11-05 22:48:49 -07:00
parent fa9fd5cd2e
commit 1a3bc79c68
3 changed files with 19 additions and 1 deletions

View file

@ -256,7 +256,19 @@ pub fn rewrite_macro_inner(
}
DelimToken::Paren => Some(format!("{}()", macro_name)),
DelimToken::Bracket => Some(format!("{}[]", macro_name)),
DelimToken::Brace => Some(format!("{}{{}}", macro_name)),
DelimToken::Brace => {
// Preserve at most one space before the braces.
let char_after_bang = context
.snippet(mac.span)
.split('!')
.nth(1)
.and_then(|x| x.chars().next());
if let Some(' ') = char_after_bang {
Some(format!("{} {{}}", macro_name))
} else {
Some(format!("{}{{}}", macro_name))
}
}
_ => unreachable!(),
};
}

View file

@ -106,6 +106,9 @@ fn main() {
impl X {
empty_invoc!{}
// Don't format empty either!
empty_invoc! {}
}
fn issue_1279() {

View file

@ -132,6 +132,9 @@ fn main() {
impl X {
empty_invoc!{}
// Don't format empty either!
empty_invoc! {}
}
fn issue_1279() {