]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0528.md
Rollup merge of #66411 - RalfJung:forget, r=sfackler
[rust.git] / src / librustc_error_codes / 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 #![feature(slice_patterns)]
8
9 let r = &[1, 2];
10 match r {
11     &[a, b, c, rest @ ..] => { // error: pattern requires at least 3
12                                //        elements but array has 2
13         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
14     }
15 }
16 ```
17
18 Ensure that the matched array has at least as many elements as the pattern
19 requires. You can match an arbitrary number of remaining elements with `..`:
20
21 ```
22 #![feature(slice_patterns)]
23
24 let r = &[1, 2, 3, 4, 5];
25 match r {
26     &[a, b, c, rest @ ..] => { // ok!
27         // prints `a=1, b=2, c=3 rest=[4, 5]`
28         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
29     }
30 }
31 ```