]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | An array without a fixed length was pattern-matched. |
2 | ||
3 | Example of erroneous code: | |
4 | ||
5 | ```compile_fail,E0730 | |
6 | #![feature(const_generics)] | |
7 | ||
8 | fn is_123<const N: usize>(x: [u32; N]) -> bool { | |
9 | match x { | |
ba9703b0 XL |
10 | [1, 2, ..] => true, // error: cannot pattern-match on an |
11 | // array without a fixed length | |
60c5eb7d XL |
12 | _ => false |
13 | } | |
14 | } | |
15 | ``` | |
16 | ||
17 | Ensure that the pattern is consistent with the size of the matched | |
18 | array. Additional elements can be matched with `..`: | |
19 | ||
20 | ``` | |
60c5eb7d XL |
21 | let r = &[1, 2, 3, 4]; |
22 | match r { | |
23 | &[a, b, ..] => { // ok! | |
24 | println!("a={}, b={}", a, b); | |
25 | } | |
26 | } | |
27 | ``` |