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

diagnostics: mismatched pattern field: suggest ".." instead of "_" #80010

Closed
matthiaskrgr opened this issue Dec 13, 2020 · 1 comment · Fixed by #80017
Closed

diagnostics: mismatched pattern field: suggest ".." instead of "_" #80010

matthiaskrgr opened this issue Dec 13, 2020 · 1 comment · Fixed by #80017
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching 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-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 13, 2020

error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields
   --> clippy_lints/src/needless_borrow.rs:50:20
    |
50  |             if let ty::Ref(_) = cx.typeck_results().expr_ty(inner).kind() {
    |                    ^^^^^^^^^^ expected 3 fields, found 1

trying to ignore the inner fields with ty::Ref(_) does not work because it has 3 fields.
The message could suggest Ref(..) if there are multiple fields and it thinks we don't want to bind any:

error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields
   --> clippy_lints/src/needless_borrow.rs:50:20
    |
50  |             if let ty::Ref(_) = cx.typeck_results().expr_ty(inner).kind() {
    |                    ^^^^^^^^^^ expected 3 fields, found 1
    = help: Use `ty::Ref(..)` to ignore any inner fields
@matthiaskrgr
Copy link
Member Author

@rustbot modify label: +A-diagnostics

@JohnTitor JohnTitor added A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching 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-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 13, 2020
@camelid camelid self-assigned this Dec 13, 2020
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 14, 2021
Suggest `_` and `..` if a pattern has too few fields

Fixes rust-lang#80010.
@bors bors closed this as completed in d3b3106 Jan 14, 2021
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-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-papercut Diagnostics: An error or lint that needs small tweaks. 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.

3 participants