Closed
Description
fn foo(c: &[u32], n: u32) -> u32 {
match *c {
[h, ..] if h > n => 0,
[h, ..] if h == n => 1,
//[h, ref ts @..] => foo(c, n - h) + foo(ts, n), // OK
[h, ref ts..] => foo(c, n - h) + foo(ts, n), // Wrong
[] => 0,
}
}
fn main() {}
Gives:
error: expected one of `,`, `@`, `]`, or `|`, found `..`
--> ...\test.rs:6:19
|
6 | [h, ref ts..] => foo(c, n - h) + foo(ts, n),
| -^
| |
| expected one of `,`, `@`, `]`, or `|`
| help: missing `,`
error[E0308]: mismatched types
--> ...\test.rs:6:46
|
6 | [h, ref ts..] => foo(c, n - h) + foo(ts, n),
| ^^ expected slice `[u32]`, found `u32`
|
= note: expected reference `&[u32]`
found reference `&u32`
error: aborting due to 2 previous errors
I think a better error message should suggest the usage of ref ts @..
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTRelating to patterns and pattern matchingArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121Category: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.