Skip to content

fix 'Ident of macro+ident gets duplicated' error #3440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&macro_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)),
Expand Down
6 changes: 6 additions & 0 deletions tests/target/issue-3439.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use repro::my_macro;

#[my_macro]
xyz! abc {
let a = 1;
}