Skip to content

Commit 94b381f

Browse files
authored
Merge pull request rust-lang#3464 from topecongiro/issue-3463
Avoid duplication on the presence of spaces between macro name and !
2 parents 0732cd6 + 017e491 commit 94b381f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/macros.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,10 @@ pub fn rewrite_macro_inner(
431431
// For macro invocations with braces, always put a space between
432432
// the `macro_name!` and `{ /* macro_body */ }` but skip modifying
433433
// anything in between the braces (for now).
434-
let snippet = context.snippet(mac.span);
435-
// to remove unnecessary space after macro name
436-
let macro_raw = snippet.trim_start_matches(&macro_name).trim_start();
437-
match trim_left_preserve_layout(macro_raw, shape.indent, &context.config) {
434+
let snippet = context.snippet(mac.span).trim_start_matches(|c| c != '{');
435+
match trim_left_preserve_layout(snippet, shape.indent, &context.config) {
438436
Some(macro_body) => Some(format!("{} {}", macro_name, macro_body)),
439-
None => Some(format!("{} {}", macro_name, macro_raw)),
437+
None => Some(format!("{} {}", macro_name, snippet)),
440438
}
441439
}
442440
_ => unreachable!(),

tests/source/macros.rs

+4
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,7 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
471471
name: (_i.name).map(|it| _visitor.fold_lit_str(it)),
472472
}
473473
}
474+
475+
// #3463
476+
x ! {()}
477+
x ! y {()}

tests/target/macros.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,7 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
10481048
name: (_i.name).map(|it| _visitor.fold_lit_str(it)),
10491049
}
10501050
}
1051+
1052+
// #3463
1053+
x! {()}
1054+
x! y {()}

0 commit comments

Comments
 (0)