mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
5c3e01a340
When writing a pattern to collect multiple entries of a slice in a single binding, it is easy to misremember or typo the appropriate syntax to do so, instead writing the experimental `X..` pattern syntax. When we encounter a resolve error because `X` isn't available, we suggest `X @ ..` as an alternative. ``` error[E0425]: cannot find value `rest` in this scope --> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13 | LL | [1, rest..] => println!("{rest:?}"), | ^^^^ not found in this scope | help: if you meant to collect the rest of the slice in `rest`, use the at operator | LL | [1, rest @ ..] => println!("{rest:?}"), | + ``` Fix #88404.
10 lines
285 B
Rust
10 lines
285 B
Rust
fn main() {
|
|
match &[1, 2, 3][..] {
|
|
[1, rest..] => println!("{rest:?}"),
|
|
//~^ ERROR cannot find value `rest` in this scope
|
|
//~| ERROR cannot find value `rest` in this scope
|
|
//~| ERROR `X..` patterns in slices are experimental
|
|
_ => {}
|
|
}
|
|
}
|