]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | The number of elements in an array or slice pattern differed from the number of |
2 | elements in the array being matched. | |
3 | ||
4 | Example of erroneous code: | |
5 | ||
6 | ```compile_fail,E0527 | |
7 | let r = &[1, 2, 3, 4]; | |
8 | match r { | |
9 | &[a, b] => { // error: pattern requires 2 elements but array | |
10 | // has 4 | |
11 | println!("a={}, b={}", a, b); | |
12 | } | |
13 | } | |
14 | ``` | |
15 | ||
16 | Ensure that the pattern is consistent with the size of the matched | |
17 | array. Additional elements can be matched with `..`: | |
18 | ||
19 | ``` | |
60c5eb7d XL |
20 | let r = &[1, 2, 3, 4]; |
21 | match r { | |
22 | &[a, b, ..] => { // ok! | |
23 | println!("a={}, b={}", a, b); | |
24 | } | |
25 | } | |
26 | ``` |