]> git.lizzy.rs Git - rust.git/commitdiff
Do not insert spaces around braces with empty body or multiple lines
authorSeiichi Uchida <seuchida@gmail.com>
Tue, 29 May 2018 23:20:34 +0000 (08:20 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Tue, 29 May 2018 23:44:57 +0000 (08:44 +0900)
src/macros.rs

index 300f95c301d0a626b8e16b34904088e4aa28e405..ae95acaf3016e153534208aa07bebb3472150ee8 100644 (file)
@@ -493,11 +493,18 @@ fn delim_token_to_str(
     delim_token: &DelimToken,
     shape: Shape,
     use_multiple_lines: bool,
+    inner_is_empty: bool,
 ) -> (String, String) {
     let (lhs, rhs) = match *delim_token {
         DelimToken::Paren => ("(", ")"),
         DelimToken::Bracket => ("[", "]"),
-        DelimToken::Brace => ("{ ", " }"),
+        DelimToken::Brace => {
+            if inner_is_empty || use_multiple_lines {
+                ("{", "}")
+            } else {
+                ("{ ", " }")
+            }
+        }
         DelimToken::NoDelim => ("", ""),
     };
     if use_multiple_lines {
@@ -553,13 +560,13 @@ fn rewrite(
         use_multiple_lines: bool,
     ) -> Option<String> {
         let rewrite_delimited_inner = |delim_tok, args| -> Option<(String, String, String)> {
-            let (lhs, rhs) = delim_token_to_str(context, delim_tok, shape, false);
             let inner = wrap_macro_args(context, args, shape)?;
+            let (lhs, rhs) = delim_token_to_str(context, delim_tok, shape, false, inner.is_empty());
             if lhs.len() + inner.len() + rhs.len() <= shape.width {
                 return Some((lhs, inner, rhs));
             }
 
-            let (lhs, rhs) = delim_token_to_str(context, delim_tok, shape, true);
+            let (lhs, rhs) = delim_token_to_str(context, delim_tok, shape, true, false);
             let nested_shape = shape
                 .block_indent(context.config.tab_spaces())
                 .with_max_width(context.config);