Skip to content

Commit

Permalink
Preserve possibly one whitespace for brace macros
Browse files Browse the repository at this point in the history
  • Loading branch information
kestred committed Nov 16, 2018
1 parent fa9fd5c commit 1a3bc79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/macros.rs
Expand Up @@ -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!(),
};
}
Expand Down
3 changes: 3 additions & 0 deletions tests/source/macros.rs
Expand Up @@ -106,6 +106,9 @@ fn main() {

impl X {
empty_invoc!{}

// Don't format empty either!
empty_invoc! {}
}

fn issue_1279() {
Expand Down
3 changes: 3 additions & 0 deletions tests/target/macros.rs
Expand Up @@ -132,6 +132,9 @@ fn main() {

impl X {
empty_invoc!{}

// Don't format empty either!
empty_invoc! {}
}

fn issue_1279() {
Expand Down

0 comments on commit 1a3bc79

Please sign in to comment.