Skip to content

Pattern matching on fixed length vectors should not be refutable #7784

Closed
@brendanzab

Description

@brendanzab

The length of fixed length vectors does not change, so a single pattern should be considered exhaustive.

Function argument destructuring:

fn foo<T>([x, y, z]: [T,..3]) -> (T, T, T) { (x, y, z) }
<anon>:7:19: 7:28 error: refutable pattern in function argument
<anon>:7          fn foo<T>([x, y, z]: [T,..3]) -> (T, T, T) { (x, y, z) }
                           ^~~~~~~~~

Let destructuring:

let [x, y, z] = [1, 2, 3]; 
<anon>:7:13: 7:22 error: refutable pattern in local binding
<anon>:7          let [x, y, z] = [1, 2, 3];
                     ^~~~~~~~~

Match patterns:

match [1, 2, 3] { [x, y, z] => (x, y, z) }
<anon>:7:9: 7:51 error: non-exhaustive patterns: vectors of length 0 not covered
<anon>:7          match [1, 2, 3] { [x, y, z] => (x, y, z) }
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions