Repository navigation
unfriendly error diagnostic when using expressions in pattern #112593
Description
Activity
- addedA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.
on Jun 13, 2023 @rustbot label +A-patterns +C-enhancement
- addedA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
on Jun 13, 2023 - addedA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.
on Jun 17, 2023 Looks like the same issue as #112593 (dot being recovered as a comma)
I have limited experience with parsing but I know where I'd start on this.
This is where the pattern of a match arm is parsed. The idea would be, in the error case, to try to parse an expression and emit a better error message if that succeeds. This code is an example of "try to parse X and emit better error if that works". You want to do something similar, but try to parse an expression instead (I'm guessing with
self.parse_expr_res). You'll also have to define a diagnostic struct (likeMissingCommaAfterMatchArmin the example) with an appropriate message in messages.ftl. (diagnostic structs are documented in the dev-guide).@clubby789 which issue did you mean? You accidentally linked to this one. EDIT: I'm guessing #90121
@TaKO8Ki I'm unassigining you because it's been a few months, feel free to reassign yourself
Reacted by Takayuki Maeda- addedE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.
on Dec 1, 2023 @rustbot claim
Reacted by Nadrieril- added a commit that references this issue
on Jan 28, 2024 - added a commit that references this issue
on Jan 29, 2024 - added a commit that references this issue
on Jan 29, 2024 Great work @ShE3py! Thanks for taking the time to fix this
Reacted by Lieselotte and clubby789
Code
Current output
Desired output
Rationale and extra context
This error occured while I was doing an
assert!(matches!(...))for a struct that doesn't implementEq.Using
String::newgives better messages;Clippy gives the same error messages.
Other cases
rustc output:
Similar errors when using expressions such as
Foo(1 + 2).Anything else?
No response