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