]> git.lizzy.rs Git - rust.git/commitdiff
Preserve possibly one whitespace for brace macros
authorKevin Stenerson <kstenerson@developers.wyyerd.com>
Tue, 6 Nov 2018 05:48:49 +0000 (22:48 -0700)
committerKevin Stenerson <kstenerson@developers.wyyerd.com>
Fri, 16 Nov 2018 21:57:43 +0000 (14:57 -0700)
src/macros.rs
tests/source/macros.rs
tests/target/macros.rs

index a2c1f2438792d4dc4ceb23b6270d8c89b33182d1..ca0de8fbb237ef7abe0014492a4d15d84ea2eb81 100644 (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!(),
         };
     }
index c828ffb881a7c31e9a7cef34daf1f7efc019720e..383fc723b5b66d92fc1c9209c2b84b1870805afd 100644 (file)
@@ -106,6 +106,9 @@ fn main() {
 
 impl X {
     empty_invoc!{}
+
+    // Don't format empty either!
+    empty_invoc! {}
 }
 
 fn issue_1279() {
index e16159ced1016c46e9580c677d2cd48af99b0326..70ed0b042fe16c4325b772927d6f18ec779097cf 100644 (file)
@@ -132,6 +132,9 @@ fn main() {
 
 impl X {
     empty_invoc!{}
+
+    // Don't format empty either!
+    empty_invoc! {}
 }
 
 fn issue_1279() {