]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0527.md
4bff39dc770e0ec4c30ec45b7ff4d1703e2c3f18
[rust.git] / src / librustc_error_codes / error_codes / E0527.md
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 ```
20 #![feature(slice_patterns)]
21
22 let r = &[1, 2, 3, 4];
23 match r {
24     &[a, b, ..] => { // ok!
25         println!("a={}, b={}", a, b);
26     }
27 }
28 ```