@@ -4013,6 +4013,40 @@ match r {
40134013```
40144014"## ,
40154015
4016+ E0528 : r##"
4017+ An array or slice pattern required more elements than were present in the
4018+ matched array.
4019+
4020+ Example of erroneous code:
4021+
4022+ ```compile_fail,E0528
4023+ #![feature(slice_patterns)]
4024+
4025+ let r = &[1, 2];
4026+ match r {
4027+ &[a, b, c, rest..] => { // error: pattern requires at least 3
4028+ // elements but array has 2
4029+ println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
4030+ }
4031+ }
4032+ ```
4033+
4034+ Ensure that the matched array has at least as many elements as the pattern
4035+ requires. You can match an arbitrary number of remaining elements with `..`:
4036+
4037+ ```
4038+ #![feature(slice_patterns)]
4039+
4040+ let r = &[1, 2, 3, 4, 5];
4041+ match r {
4042+ &[a, b, c, rest..] => { // ok!
4043+ // prints `a=1, b=2, c=3 rest=[4, 5]`
4044+ println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
4045+ }
4046+ }
4047+ ```
4048+ "## ,
4049+
40164050E0529 : r##"
40174051An array or slice pattern was matched against some other type.
40184052
@@ -4164,6 +4198,5 @@ register_diagnostics! {
41644198 E0436 , // functional record update requires a struct
41654199 E0513 , // no type for local variable ..
41664200 E0521 , // redundant default implementations of trait
4167- E0528 , // expected at least {} elements, found {}
41684201 E0533 , // `{}` does not name a unit variant, unit struct or a constant
41694202}
0 commit comments