Skip to content

Matching fixed-size vectors requires handling vectors of arbitrary size #7045

Closed
@ghost

Description

I'm trying to use pattern matching with fixed-size vectors, like this:

fn main() {
    match [3, 5] {
        [a, b] => println("ok")
    };
}

However, this doesn't compile (I'm using 0.6 on Windows):

error: non-exhaustive patterns: vectors of length 0 not covered

After adding a wildcard the program compiles...

fn main() {
    match [3, 5] {
        [a, b] => println("ok"),
        _ => ()
    };
}

... which I think it shouldn't, since that last pattern is (or should be) unreachable. When replacing the fixed-size vector with a tuple, it certainly is:

fn main() {
    match (3, 5) {
        (a, b) => println("ok"),
        _ => ()
    };
}
error: unreachable pattern

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