Skip to content

Hint on missing tuple parens in pattern #63962

Closed
@cramertj

Description

@cramertj

It'd be nice to smartly hint about missing tuple parentheses in patterns, especially in positions where parentheses nesting is required.

Example of incorrect code:

fn main() {
    match Some((1, 2)) {
        Some(x, y) => {}
        None => {}
    }
}

The error:

error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
 --> src/main.rs:3:9
  |
3 |         Some(x, y) => {}
  |         ^^^^^^^^^^ expected 1 field, found 2

This error is confusing, especially since Some is a "tuple pattern" which is confusable with its tuple field. An error that suggests missing tuple parentheses would be helpful.

This issue has been assigned to @sam09 via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions