From 017e491a1770c79ae923300fd7b57008589e3b68 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Thu, 21 Mar 2019 15:58:39 +0900 Subject: [PATCH] Avoid duplication on the presence of spaces between macro name and ! --- src/macros.rs | 8 +++----- tests/source/macros.rs | 4 ++++ tests/target/macros.rs | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 60fdb9160a7..95504a23aba 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -431,12 +431,10 @@ pub fn rewrite_macro_inner( // For macro invocations with braces, always put a space between // the `macro_name!` and `{ /* macro_body */ }` but skip modifying // anything in between the braces (for now). - let snippet = context.snippet(mac.span); - // to remove unnecessary space after macro name - let macro_raw = snippet.trim_start_matches(¯o_name).trim_start(); - match trim_left_preserve_layout(macro_raw, shape.indent, &context.config) { + let snippet = context.snippet(mac.span).trim_start_matches(|c| c != '{'); + match trim_left_preserve_layout(snippet, shape.indent, &context.config) { Some(macro_body) => Some(format!("{} {}", macro_name, macro_body)), - None => Some(format!("{} {}", macro_name, macro_raw)), + None => Some(format!("{} {}", macro_name, snippet)), } } _ => unreachable!(), diff --git a/tests/source/macros.rs b/tests/source/macros.rs index d41a72e52f1..66012e4d69d 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -471,3 +471,7 @@ pub fn fold_abi(_visitor: &mut V, _i: Abi) -> Abi { name: (_i.name).map(|it| _visitor.fold_lit_str(it)), } } + +// #3463 +x ! {()} +x ! y {()} diff --git a/tests/target/macros.rs b/tests/target/macros.rs index d0fe892d91b..8f86b79f922 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -1048,3 +1048,7 @@ pub fn fold_abi(_visitor: &mut V, _i: Abi) -> Abi { name: (_i.name).map(|it| _visitor.fold_lit_str(it)), } } + +// #3463 +x! {()} +x! y {()}