@@ -4013,6 +4013,40 @@ match r {
4013
4013
```
4014
4014
"## ,
4015
4015
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
+
4016
4050
E0529 : r##"
4017
4051
An array or slice pattern was matched against some other type.
4018
4052
@@ -4164,6 +4198,5 @@ register_diagnostics! {
4164
4198
E0436 , // functional record update requires a struct
4165
4199
E0513 , // no type for local variable ..
4166
4200
E0521 , // redundant default implementations of trait
4167
- E0528 , // expected at least {} elements, found {}
4168
4201
E0533 , // `{}` does not name a unit variant, unit struct or a constant
4169
4202
}
0 commit comments