]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0528.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0528.md
1 An array or slice pattern required more elements than were present in the
2 matched array.
3
4 Example of erroneous code:
5
6 ```compile_fail,E0528
7 let r = &[1, 2];
8 match r {
9     &[a, b, c, rest @ ..] => { // error: pattern requires at least 3
10                                //        elements but array has 2
11         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
12     }
13 }
14 ```
15
16 Ensure that the matched array has at least as many elements as the pattern
17 requires. You can match an arbitrary number of remaining elements with `..`:
18
19 ```
20 let r = &[1, 2, 3, 4, 5];
21 match r {
22     &[a, b, c, rest @ ..] => { // ok!
23         // prints `a=1, b=2, c=3 rest=[4, 5]`
24         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
25     }
26 }
27 ```