Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
estebank opened this issue Sep 28, 2019 · 0 comments · Fixed by #64887
Closed

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

estebank opened this issue Sep 28, 2019 · 0 comments · Fixed by #64887
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. F-or_patterns `#![feature(or_patterns)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

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.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Sep 28, 2019
@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Sep 28, 2019
@Centril Centril self-assigned this Sep 28, 2019
@Centril Centril added the F-or_patterns `#![feature(or_patterns)]` label Sep 29, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
…tebank

syntax: recover trailing `|` in or-patterns

Fixes rust-lang#64879.

For example (this also shows that we are sensitive to the typo `||`):

```
error: a trailing `|` is not allowed in an or-pattern
  --> $DIR/remove-leading-vert.rs:33:11
   |
LL |         A || => {}
   |         - ^^ help: remove the `||`
   |         |
   |         while parsing this or-pattern starting here
   |
   = note: alternatives in or-patterns are separated with `|`, not `||`
```

r? @estebank
@bors bors closed this as completed in f45de9a Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. F-or_patterns `#![feature(or_patterns)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants