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

Writing Eq::eq produces an unhelpful diagnostic (std::cmp::Eq cannot be made into an object) #49984

Open
ExpHP opened this issue Apr 15, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system 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

@ExpHP
Copy link
Contributor

ExpHP commented Apr 15, 2018

fn hi() -> bool {
    Eq::eq(&(), &())
}
   Compiling playground v0.0.1 (file:///playground)
error[E0038]: the trait `std::cmp::Eq` cannot be made into an object
 --> src/main.rs:3:5
  |
3 |     Eq::eq(&(), &())
  |     ^^^^^^ the trait `std::cmp::Eq` cannot be made into an object
  |
  = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses

error: aborting due to previous error

I stared at this for a moment in pure disbelief... and then once I woke up a bit more, I remembered that eq is actually on the PartialEq trait (and so what I wrote is not interpreted as <_ as Eq>::eq, but rather as <Eq>::eq).

@stokhos stokhos added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 15, 2018
@XAMPPRocky XAMPPRocky 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 Aug 27, 2018
@estebank
Copy link
Contributor

estebank commented Nov 11, 2022

Current output:

error[E0782]: trait objects must include the `dyn` keyword
 --> src/lib.rs:2:5
  |
2 |     Eq::eq(&(), &())
  |     ^^
  |
help: add `dyn` keyword before this trait
  |
2 |     <dyn Eq>::eq(&(), &())
  |     ++++   +

error[E0038]: the trait `Eq` cannot be made into an object
 --> src/lib.rs:2:5
  |
2 |     Eq::eq(&(), &())
  |     ^^ `Eq` cannot be made into an object
  |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>)

The new error gives a hint to what's gonig on, but E0038 maybe should learn how to be clearer, as involving trait objects in fully qualified paths is somewhat uncommon and bound to be confusing every time.

@estebank estebank added A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Nov 11, 2022
@ExpHP
Copy link
Contributor Author

ExpHP commented Nov 16, 2022

I feel like there should maybe be a message specifically targeted to the case where the method belongs to a supertrait. Since I feel like the gotcha here is that Eq::eq looks just like Ord::cmp when it is actually not.

Or put another way, the issue isn't that the compiler mentions trait objects; rather, the issue is that it doesn't mention PartialEq.

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-traits Area: Trait system 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

4 participants