-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Confusing "arbitrary expressions aren't allowed in patterns" error #99380
Copy link
Copy link
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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:exprabove changes it to be parsed as an expression. So what you need to do here is to change the$p:exprabove 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