Skip to content

Match matches in strange dependence of surrounding patterns #16975

Closed
@nwin

Description

@nwin

The following code

fn main() {
    let a = vec![16u8];
    match (a.as_slice(), "a") {
        ([8], "a")
        |([8, _], "a") => {},
        ([16], "a")
        |([16, _], "a") => { println!("matched") },
        // (_, _) => fail!(), // Fails if this line is used
        _ => fail!() // prints matched if this line is used

    }
}

fails, if the comment is swapped between the two last lines.

But (_, _) only matches when I use |([8, _], "a") in the first pattern and if I use a [16] instead of [8] as a value for a. I don't think this behaves as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions