Skip to content

Commit 7c37cd6

Browse files
Fix help on AmbiguousMissingKwForItemSub diagnostic
1 parent ce271d3 commit 7c37cd6

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

compiler/rustc_parse/src/errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,9 @@ pub(crate) enum AmbiguousMissingKwForItemSub {
22662266
span: Span,
22672267
snippet: String,
22682268
},
2269-
#[help("you likely meant to define an item, e.g., `{$vis} fn foo() {\"{}\"}`")]
2269+
#[help(
2270+
"if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier"
2271+
)]
22702272
HelpMacro,
22712273
}
22722274

tests/ui/macros/metavar-expressions/usage-errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ curly__rhs_dollar__no_round !(a);
2727
macro_rules! no_curly__no_rhs_dollar__round {
2828
( $( $i:ident ),* ) => { count(i) };
2929
//~^ ERROR missing `fn` or `struct` for function or struct definition
30+
//~| HELP if you meant to call a macro, try
3031
}
3132
no_curly__no_rhs_dollar__round !(a, b, c);
3233

3334
#[rustfmt::skip] // autoformatters can break a few of the error traces
3435
macro_rules! no_curly__no_rhs_dollar__no_round {
3536
( $i:ident ) => { count(i) };
3637
//~^ ERROR missing `fn` or `struct` for function or struct definition
38+
//~| HELP if you meant to call a macro, try
3739
}
3840
no_curly__no_rhs_dollar__no_round !(a);
3941

tests/ui/macros/metavar-expressions/usage-errors.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LL | ( $( $i:ident ),* ) => { count!(i) };
2626
| +
2727

2828
error: missing `fn` or `struct` for function or struct definition
29-
--> $DIR/usage-errors.rs:35:23
29+
--> $DIR/usage-errors.rs:36:23
3030
|
3131
LL | ( $i:ident ) => { count(i) };
3232
| ^^^^^
@@ -41,13 +41,13 @@ LL | ( $i:ident ) => { count!(i) };
4141
| +
4242

4343
error: variable `i` is still repeating at this depth
44-
--> $DIR/usage-errors.rs:42:36
44+
--> $DIR/usage-errors.rs:44:36
4545
|
4646
LL | ( $( $i:ident ),* ) => { count($i) };
4747
| ^^
4848

4949
error[E0425]: cannot find value `a` in this scope
50-
--> $DIR/usage-errors.rs:52:49
50+
--> $DIR/usage-errors.rs:54:49
5151
|
5252
LL | ( $i:ident ) => { count($i) };
5353
| -- due to this macro variable
@@ -56,7 +56,7 @@ LL | const _: u32 = no_curly__rhs_dollar__no_round! (a);
5656
| ^ not found in this scope
5757

5858
error[E0425]: cannot find function `count` in this scope
59-
--> $DIR/usage-errors.rs:49:23
59+
--> $DIR/usage-errors.rs:51:23
6060
|
6161
LL | ( $i:ident ) => { count($i) };
6262
| ^^^^^ not found in this scope

0 commit comments

Comments
 (0)