From 40ff078abf0206364243fd01dce76a22dff26dca Mon Sep 17 00:00:00 2001 From: rchaser53 Date: Sun, 10 Mar 2019 22:58:34 +0900 Subject: [PATCH] fix 'Ident of macro+ident gets duplicated' error --- src/macros.rs | 3 ++- tests/target/issue-3439.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/target/issue-3439.rs diff --git a/src/macros.rs b/src/macros.rs index 6bc181fc6f9..60fdb9160a7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -432,7 +432,8 @@ pub fn rewrite_macro_inner( // the `macro_name!` and `{ /* macro_body */ }` but skip modifying // anything in between the braces (for now). let snippet = context.snippet(mac.span); - let macro_raw = snippet.split_at(snippet.find('!')? + 1).1.trim_start(); + // 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) { Some(macro_body) => Some(format!("{} {}", macro_name, macro_body)), None => Some(format!("{} {}", macro_name, macro_raw)), diff --git a/tests/target/issue-3439.rs b/tests/target/issue-3439.rs new file mode 100644 index 00000000000..835fae243ce --- /dev/null +++ b/tests/target/issue-3439.rs @@ -0,0 +1,6 @@ +use repro::my_macro; + +#[my_macro] +xyz! abc { + let a = 1; +}