rust/src/librustc_error_codes/error_codes/E0730.md
2020-07-25 18:57:42 +02:00

593 B

An array without a fixed length was pattern-matched.

Erroneous code example:

#![feature(const_generics)]

fn is_123<const N: usize>(x: [u32; N]) -> bool {
    match x {
        [1, 2, ..] => true, // error: cannot pattern-match on an
                            //        array without a fixed length
        _ => false
    }
}

Ensure that the pattern is consistent with the size of the matched array. Additional elements can be matched with ..:

let r = &[1, 2, 3, 4];
match r {
    &[a, b, ..] => { // ok!
        println!("a={}, b={}", a, b);
    }
}