Skip to content

Ambiguity in the syntax for if and if let #50090

Closed
@yeah-boi

Description

@yeah-boi

There seems to be an ambiguity in the syntax for both if and if let. This is due to the fact that expressions can contain { ... } and this looks like a branches of the if-statement. For example, the rust compiler fails to parse the following two examples:

fn main() {
    struct S { x: i32, y: i32 }
    
    #[derive(PartialEq)]
    struct T {}
    
    // Example 1:
    if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
    // Example 2:
    if T {} == T {} { println!("Ok"); }

    println!("Hello, world!");
}

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 AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions