Skip to content

Commit 2454799

Browse files
authored
Rollup merge of rust-lang#47444 - etaoins:dont-include-bang-in-macro-suggestion, r=estebank
Don't include bang in macro replacement suggestion When we suggest the replacement for a macro we include the "!" in the suggested replacement but the span only contains the name of the macro itself. Using that replacement would cause a duplicate "!" in the resulting code. I originally tried to extend the span to be replaced by 1 byte in rust-lang#47424. However, @zackmdavis pointed out that there can be whitespace between the macro name and the bang. Instead, just remove the bang from the suggested replacement. Fixes rust-lang#47418 r? @estebank
2 parents 0a34e94 + ecd47a9 commit 2454799

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

src/librustc_resolve/macros.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ impl<'a> Resolver<'a> {
691691
if let Some(suggestion) = suggestion {
692692
if suggestion != name {
693693
if let MacroKind::Bang = kind {
694-
err.span_suggestion(span, "you could try the macro",
695-
format!("{}!", suggestion));
694+
err.span_suggestion(span, "you could try the macro", suggestion.to_string());
696695
} else {
697696
err.span_suggestion(span, "try", suggestion.to_string());
698697
}

src/test/ui-fulldeps/resolve-error.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ error: cannot find macro `FooWithLongNama!` in this scope
3838
--> $DIR/resolve-error.rs:62:5
3939
|
4040
62 | FooWithLongNama!();
41-
| ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam!`
41+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam`
4242

4343
error: cannot find macro `attr_proc_macra!` in this scope
4444
--> $DIR/resolve-error.rs:65:5
4545
|
4646
65 | attr_proc_macra!();
47-
| ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac!`
47+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac`
4848

4949
error: cannot find macro `Dlona!` in this scope
5050
--> $DIR/resolve-error.rs:68:5
@@ -56,7 +56,7 @@ error: cannot find macro `bang_proc_macrp!` in this scope
5656
--> $DIR/resolve-error.rs:71:5
5757
|
5858
71 | bang_proc_macrp!();
59-
| ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro!`
59+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro`
6060

6161
error: aborting due to 10 previous errors
6262

src/test/ui/macros/macro-name-typo.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: cannot find macro `printlx!` in this scope
22
--> $DIR/macro-name-typo.rs:12:5
33
|
44
12 | printlx!("oh noes!"); //~ ERROR cannot find
5-
| ^^^^^^^ help: you could try the macro: `println!`
5+
| ^^^^^^^ help: you could try the macro: `println`
66

77
error: aborting due to previous error
88

src/test/ui/macros/macro_undefined.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: cannot find macro `k!` in this scope
1010
--> $DIR/macro_undefined.rs:21:5
1111
|
1212
21 | k!(); //~ ERROR cannot find
13-
| ^ help: you could try the macro: `kl!`
13+
| ^ help: you could try the macro: `kl`
1414

1515
error: aborting due to 2 previous errors
1616

0 commit comments

Comments
 (0)