From d14c26f45a84eff6eabddd8c0e0580d851ade217 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 8 Feb 2026 10:24:07 +0100 Subject: [PATCH] Fix help on `AmbiguousMissingKwForItemSub` diagnostic --- compiler/rustc_parse/src/errors.rs | 4 +++- tests/ui/macros/metavar-expressions/usage-errors.rs | 2 ++ tests/ui/macros/metavar-expressions/usage-errors.stderr | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 418d56f632bd..b54782ec592c 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2266,7 +2266,9 @@ pub(crate) enum AmbiguousMissingKwForItemSub { span: Span, snippet: String, }, - #[help("you likely meant to define an item, e.g., `{$vis} fn foo() {\"{}\"}`")] + #[help( + "if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier" + )] HelpMacro, } diff --git a/tests/ui/macros/metavar-expressions/usage-errors.rs b/tests/ui/macros/metavar-expressions/usage-errors.rs index feff02e2ce47..966ffadb32af 100644 --- a/tests/ui/macros/metavar-expressions/usage-errors.rs +++ b/tests/ui/macros/metavar-expressions/usage-errors.rs @@ -27,6 +27,7 @@ curly__rhs_dollar__no_round !(a); macro_rules! no_curly__no_rhs_dollar__round { ( $( $i:ident ),* ) => { count(i) }; //~^ ERROR missing `fn` or `struct` for function or struct definition + //~| HELP if you meant to call a macro, try } no_curly__no_rhs_dollar__round !(a, b, c); @@ -34,6 +35,7 @@ no_curly__no_rhs_dollar__round !(a, b, c); macro_rules! no_curly__no_rhs_dollar__no_round { ( $i:ident ) => { count(i) }; //~^ ERROR missing `fn` or `struct` for function or struct definition + //~| HELP if you meant to call a macro, try } no_curly__no_rhs_dollar__no_round !(a); diff --git a/tests/ui/macros/metavar-expressions/usage-errors.stderr b/tests/ui/macros/metavar-expressions/usage-errors.stderr index f66f522e23b9..3d22e3ac4b30 100644 --- a/tests/ui/macros/metavar-expressions/usage-errors.stderr +++ b/tests/ui/macros/metavar-expressions/usage-errors.stderr @@ -26,7 +26,7 @@ LL | ( $( $i:ident ),* ) => { count!(i) }; | + error: missing `fn` or `struct` for function or struct definition - --> $DIR/usage-errors.rs:35:23 + --> $DIR/usage-errors.rs:36:23 | LL | ( $i:ident ) => { count(i) }; | ^^^^^ @@ -41,13 +41,13 @@ LL | ( $i:ident ) => { count!(i) }; | + error: variable `i` is still repeating at this depth - --> $DIR/usage-errors.rs:42:36 + --> $DIR/usage-errors.rs:44:36 | LL | ( $( $i:ident ),* ) => { count($i) }; | ^^ error[E0425]: cannot find value `a` in this scope - --> $DIR/usage-errors.rs:52:49 + --> $DIR/usage-errors.rs:54:49 | LL | ( $i:ident ) => { count($i) }; | -- due to this macro variable @@ -56,7 +56,7 @@ LL | const _: u32 = no_curly__rhs_dollar__no_round! (a); | ^ not found in this scope error[E0425]: cannot find function `count` in this scope - --> $DIR/usage-errors.rs:49:23 + --> $DIR/usage-errors.rs:51:23 | LL | ( $i:ident ) => { count($i) }; | ^^^^^ not found in this scope