syn icon indicating copy to clipboard operation
syn copied to clipboard

Parse struct literals in match guards

Open dtolnay opened this issue 2 years ago • 0 comments
trafficstars

Unlike if condition, match guards accept struct literals.

Syn currently fails to parse it.

#![feature(if_let_guard)]

#[derive(PartialEq)]
struct Foo {
    x: isize,
}

fn foo(f: Foo) {
    match () {
        () if f == Foo { x: 42 } => {}
        () if let Foo { x: 0.. } = Foo { x: 42 } => {}
        _ => {}
    }
}
error: expected `=>`
  --> dev/main.rs:11:40
   |
11 |         () if let Foo { x: 0.. } = Foo { x: 42 } => {}
   |                                        ^

Tracking issue: https://github.com/rust-lang/rust/issues/51114

dtolnay avatar Nov 05 '23 21:11 dtolnay