diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2016-06-17 00:03:36 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2016-07-31 15:09:25 -0700 |
| commit | e960021d30faff871f98c9c463b43c4359af280d (patch) | |
| tree | 57ec8633309d163c98c9f8872e4df513fa39c229 /src | |
| parent | 7093d1de8455556640578ad3d493bc9bff79b8e5 (diff) | |
| download | rust-e960021d30faff871f98c9c463b43c4359af280d.tar.gz rust-e960021d30faff871f98c9c463b43c4359af280d.zip | |
extended info for E0528, expected at least this-and-such many elements
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index cf8fd3da1f5..4b0b616c5f6 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4013,6 +4013,40 @@ match r { ``` "##, +E0528: r##" +An array or slice pattern required more elements than were present in the +matched array. + +Example of erroneous code: + +```compile_fail,E0528 +#![feature(slice_patterns)] + +let r = &[1, 2]; +match r { + &[a, b, c, rest..] => { // error: pattern requires at least 3 + // elements but array has 2 + println!("a={}, b={}, c={} rest={:?}", a, b, c, rest); + } +} +``` + +Ensure that the matched array has at least as many elements as the pattern +requires. You can match an arbitrary number of remaining elements with `..`: + +``` +#![feature(slice_patterns)] + +let r = &[1, 2, 3, 4, 5]; +match r { + &[a, b, c, rest..] => { // ok! + // prints `a=1, b=2, c=3 rest=[4, 5]` + println!("a={}, b={}, c={} rest={:?}", a, b, c, rest); + } +} +``` +"##, + E0529: r##" An array or slice pattern was matched against some other type. @@ -4164,6 +4198,5 @@ register_diagnostics! { E0436, // functional record update requires a struct E0513, // no type for local variable .. E0521, // redundant default implementations of trait - E0528, // expected at least {} elements, found {} E0533, // `{}` does not name a unit variant, unit struct or a constant } |
