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

Try different Deref/PartialEq orderings before erroring #49454

Open
djc opened this issue Mar 28, 2018 · 4 comments
Open

Try different Deref/PartialEq orderings before erroring #49454

djc opened this issue Mar 28, 2018 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference 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

@djc
Copy link
Contributor

djc commented Mar 28, 2018

I just got this error:

djc@djc-mbp cargo $ cargo check
   Compiling cargo v0.27.0 (file:///Users/djc/src/cargo)
error[E0308]: mismatched types
   --> src/cargo/core/summary.rs:150:58
    |
150 |                 dependencies.iter().find(|d| d.name() == dep_name)
    |                                                          ^^^^^^^^ expected struct `core::interning::InternedString`, found &str
    |
    = note: expected type `core::interning::InternedString`
               found type `&str`

InternedString implements Deref<Target = str>, so I'd expected that this could somehow be made to work. *d.name() == *dep_name seems to work, but dereferencing explicitly always feels bad. Is there a better way out here? If not, could this solution be suggested?

cc @estebank @ehuss

@frewsxcv
Copy link
Member

somewhat related to dereferencing and PartialEq: #39942

@pietroalbini pietroalbini added 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 Apr 6, 2018
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference labels Apr 10, 2018
@steveklabnik
Copy link
Member

I tried to make a minimal reproduction here https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=be29ae6b6632484edf22da25539d95eb

I am not sure if it is or not. @djc any thoughts on this?

@djc
Copy link
Contributor Author

djc commented May 3, 2020

#39942 has been closed as a duplicate of #40660, so I suppose that's the canonical issue now at least in terms of diagnostics.

@steveklabnik thanks for the minimal reproduction. I've amended it slightly to https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d721a2cdccb159604f5fed06c5726e0f, which has a more concise error now:

error[E0308]: mismatched types
  --> src/main.rs:22:45
   |
22 |     dependencies.into_iter().find(|&d| d == dep_name);
   |                                             ^^^^^^^^ expected struct `InternedString`, found `&str`

@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Jun 12, 2020
@estebank
Copy link
Contributor

estebank commented Aug 3, 2023

Current output:

error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
  --> src/main.rs:22:45
   |
22 |     dependencies.into_iter().find(|&d| d == dep_name);
   |                                        -    ^^^^^^^^ expected `InternedString`, found `&str`
   |                                        |
   |                                        expected because this is `InternedString`
   |
help: try wrapping the expression in `InternedString`
   |
22 |     dependencies.into_iter().find(|&d| d == InternedString(dep_name));
   |                                             +++++++++++++++        +

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-inference Area: Type inference 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

No branches or pull requests

5 participants