Skip to content

Confusing parse error for missing => after match guard #78585

Closed
@camelid

Description

@camelid

Can you spot the mistake?

fn main() {
    let x = 1;
    let y = 2;
    let value = 3;

    match value {
        Some(x) if x == y {
            self.next_token()?;
            Ok(true)
        },
        _ => {
            Ok(false)
        }
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found keyword `self`
 --> src/main.rs:8:13
  |
7 |         Some(x) if x == y {
  |                         - while parsing this struct
8 |             self.next_token()?;
  |             ^^^^ expected identifier, found keyword

error: expected one of `.`, `=>`, `?`, or an operator, found `,`
  --> src/main.rs:10:10
   |
10 |         },
   |          ^ expected one of `.`, `=>`, `?`, or an operator

error: aborting due to 2 previous errors

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: 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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions