Skip to content

Fails to parse boolean expression of nested match expressions #88727

@alexmaco

Description

@alexmaco

I tried this code (reduced to minimal triggering case):

fn main() {
    let (a, b, c) = (3, 4, 5);
    let r: bool = match c {
        _ => match a {
            _ => true
        } && match b {
            _ => true,
        },
    };
}

(Failing in playground)

Fails with the following error:

error: expected identifier, found keyword `match`
 --> src/main.rs:7:14
  |
7 |         } && match b {
  |              ^^^^^ expected identifier, found keyword

error: expected one of `=>`, `@`, `if`, or `|`, found `b`
 --> src/main.rs:7:20
  |
7 |         } && match b {
  |                    ^ expected one of `=>`, `@`, `if`, or `|`

error: aborting due to 2 previous errors

However, the following works as expected:

fn main() {
    let (a, b, c) = (3, 4, 5);
    let r: bool = match a {
        _ => true,
    } && match b {
        _ => true,
    };
}

Given that the second example compiles, we should expect the first one to compile as well.

Meta

I've found this issues on all rust versions 1.54.0 to 1.57 nightly inclusive. It doesn't look like a regression, since the same code is rejected as far back as 1.30, just with a different error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-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