Skip to content

Cannot use parens for grouping in patterns #19580

Closed
@emberian

Description

@emberian

The fact that

fn main() {
    let x = &4i;

    match x {
        // wanted to type `e @ &1 ... &4`
        e @ &1 ... 4 => println!("Got a small value: {}", e),
        &val => println!("Got a value: {}", val),
    }
}

works but

fn main() {
    let x = &4i;

    match x {
        // wanted to type `e @ &1 ... &4`
        e @ &(1 ... 4) => println!("Got a small value: {}", e),
        &val => println!("Got a value: {}", val),
    }
}

is quite surprising. Presumably the &( is expecting a tuple pattern, should consider investigating and seeing if patterns can be parenthesized in general.

cc #11144

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of Rust

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions