From 2f658529463c631256397011bd53a373a96de790 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 30 May 2018 08:20:34 +0900 Subject: [PATCH 1/1] Do not insert spaces around braces with empty body or multiple lines --- src/macros.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 300f95c301d..ae95acaf301 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 { 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); -- 2.44.0