Skip to content

Commit 7093d1d

Browse files
committed
add extended info for E0527, slice pattern element count expectations
1 parent 65e3ff4 commit 7093d1d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,6 +3980,39 @@ impl SpaceLlama for i32 {
39803980
```
39813981
"##,
39823982

3983+
E0527: r##"
3984+
The number of elements in an array or slice pattern differed from the number of
3985+
elements in the array being matched.
3986+
3987+
Example of erroneous code:
3988+
3989+
```compile_fail,E0527
3990+
#![feature(slice_patterns)]
3991+
3992+
let r = &[1, 2, 3, 4];
3993+
match r {
3994+
&[a, b] => { // error: pattern requires 2 elements but array
3995+
// has 4
3996+
println!("a={}, b={}", a, b);
3997+
}
3998+
}
3999+
```
4000+
4001+
Ensure that the pattern is consistent with the size of the matched
4002+
array. Additional elements can be matched with `..`:
4003+
4004+
```
4005+
#![feature(slice_patterns)]
4006+
4007+
let r = &[1, 2, 3, 4];
4008+
match r {
4009+
&[a, b, ..] => { // ok!
4010+
println!("a={}, b={}", a, b);
4011+
}
4012+
}
4013+
```
4014+
"##,
4015+
39834016
E0529: r##"
39844017
An array or slice pattern was matched against some other type.
39854018
@@ -4131,7 +4164,6 @@ register_diagnostics! {
41314164
E0436, // functional record update requires a struct
41324165
E0513, // no type for local variable ..
41334166
E0521, // redundant default implementations of trait
4134-
E0527, // expected {} elements, found {}
41354167
E0528, // expected at least {} elements, found {}
41364168
E0533, // `{}` does not name a unit variant, unit struct or a constant
41374169
}

0 commit comments

Comments
 (0)