Preserve possibly one whitespace for brace macros
This commit is contained in:
parent
fa9fd5cd2e
commit
1a3bc79c68
@ -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!(),
|
||||
};
|
||||
}
|
||||
|
@ -106,6 +106,9 @@ fn main() {
|
||||
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
|
||||
// Don't format empty either!
|
||||
empty_invoc! {}
|
||||
}
|
||||
|
||||
fn issue_1279() {
|
||||
|
@ -132,6 +132,9 @@ fn main() {
|
||||
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
|
||||
// Don't format empty either!
|
||||
empty_invoc! {}
|
||||
}
|
||||
|
||||
fn issue_1279() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user