Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustc misunderstands when an @ is missing in a pattern and the error message is confusing #88404

Closed
Lokathor opened this issue Aug 27, 2021 · 0 comments · Fixed by #117998
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching A-slice-patterns Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Lokathor
Copy link
Contributor

playground

I should have typed rest @ .., and to fix my problem I need to add the @ between rest and ..

Instead rustc tries to tell me three different ways that "rest.." is wrong, none of which are "hey did you forget the @ sign?"

@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching A-slice-patterns Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2023
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.
@bors bors closed this as completed in 5c3e01a Nov 17, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 17, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching A-slice-patterns Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants