Skip to content

Typoing "." instead of "," in a match produces confusing error messages #140991

@ssbr

Description

@ssbr

Code

pub enum Foo {
    X, Y
}

pub fn invert(foo: Foo) -> Foo {
    use Foo::*;
    match foo {
        X => Y.
        Y => X,
    }
}

Current output

error: expected one of `(`, `,`, `.`, `::`, `?`, `}`, or an operator, found `=>`
  --> src/lib.rs:12:11
   |
12 |         Y => X,
   |           ^^ expected one of 7 possible tokens

warning: unused import: `Foo::*`

Desired output

I wish it would have tried error recovery by substituting "," where it saw a ".", which is a reasonable enough typo, so that it could give some kind of hint that maybe the previous line had been intended to be Y, not Y..

Rationale and extra context

No response

Other cases

Rust Version

I don't have rust installed locally, this was 1.86 in the rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1eb7427edcf893496f899d59f78ec1ff

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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