Skip to content

Detect match arm guard preceded by | in the parser #64879

Closed
@estebank

Description

@estebank

Detect and recover the following incorrect code:

enum E {
    A,
    B,
}

fn main() {
    match E::A {
        E::A |
        E::B | // This pipe or operand shouldn't be here
        if true => {}
        _ => {}
    }
}

which currently emits

error: expected identifier, found keyword `if`
  --> src/main.rs:10:9
   |
10 |         if true => {}
   |         ^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
   |
10 |         r#if true => {}
   |         ^^^^

error: expected one of `=>`, `@`, `if`, or `|`, found `true`
  --> src/main.rs:10:12
   |
10 |         if true => {}
   |            ^^^^ expected one of `=>`, `@`, `if`, or `|` here

The parser should instead detect it is parsing a match arm guard.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-or_patterns`#![feature(or_patterns)]`P-lowLow priorityT-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