Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1a3bc79

Browse files
committed
Preserve possibly one whitespace for brace macros
1 parent fa9fd5c commit 1a3bc79

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/macros.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,19 @@ pub fn rewrite_macro_inner(
256256
}
257257
DelimToken::Paren => Some(format!("{}()", macro_name)),
258258
DelimToken::Bracket => Some(format!("{}[]", macro_name)),
259-
DelimToken::Brace => Some(format!("{}{{}}", macro_name)),
259+
DelimToken::Brace => {
260+
// Preserve at most one space before the braces.
261+
let char_after_bang = context
262+
.snippet(mac.span)
263+
.split('!')
264+
.nth(1)
265+
.and_then(|x| x.chars().next());
266+
if let Some(' ') = char_after_bang {
267+
Some(format!("{} {{}}", macro_name))
268+
} else {
269+
Some(format!("{}{{}}", macro_name))
270+
}
271+
}
260272
_ => unreachable!(),
261273
};
262274
}

tests/source/macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ fn main() {
106106

107107
impl X {
108108
empty_invoc!{}
109+
110+
// Don't format empty either!
111+
empty_invoc! {}
109112
}
110113

111114
fn issue_1279() {

tests/target/macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ fn main() {
132132

133133
impl X {
134134
empty_invoc!{}
135+
136+
// Don't format empty either!
137+
empty_invoc! {}
135138
}
136139

137140
fn issue_1279() {

0 commit comments

Comments
 (0)