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