forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#117998 - estebank:issue-88404, r=TaKO8Ki
On resolve error of `[rest..]`, suggest `[rest @ ..]` 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 rust-lang#88404.
- Loading branch information
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/ui/pattern/range-pattern-meant-to-be-slice-rest-pattern.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 | ||
_ => {} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/ui/pattern/range-pattern-meant-to-be-slice-rest-pattern.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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:?}"), | ||
| + | ||
|
||
error[E0425]: cannot find value `rest` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:35 | ||
| | ||
LL | [1, rest..] => println!("{rest:?}"), | ||
| ^^^^ not found in this scope | ||
|
||
error[E0658]: `X..` patterns in slices are experimental | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13 | ||
| | ||
LL | [1, rest..] => println!("{rest:?}"), | ||
| ^^^^^^ | ||
| | ||
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information | ||
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0658. | ||
For more information about an error, try `rustc --explain E0425`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters