From: Seiichi Uchida Date: Tue, 29 May 2018 23:20:34 +0000 (+0900) Subject: Do not insert spaces around braces with empty body or multiple lines X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2f658529463c631256397011bd53a373a96de790;hp=966fe8d7052238f3c662a4f02d1cb7b96c644293;p=rust.git Do not insert spaces around braces with empty body or multiple lines --- 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);