Confusing "arbitrary expressions aren't allowed in patterns" error #99380
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Take the following code:
Currently it fails with:
If you expanded the macro manually,
Some(3)
would be parsed as a pattern, but the$p:expr
above changes it to be parsed as an expression. So what you need to do here is to change the$p:expr
above to$p:pat
. But this is very non-obvious.Ideally, the compiler would try to check if the input is a valid pattern, and if so, add a note like "
Some(3)
is a valid pattern but the metavariable $p is specified to be an expression", and maybe also point to the metavariable's matcher.@rustbot label A-macros
The text was updated successfully, but these errors were encountered: