Skip to content

Unhelpful error message when enum does not implement PartialEq #110867

Closed
@andresovela

Description

@andresovela

Code

#[derive(Debug)]
enum Foo {
    Bar,
    Qux,
}

fn test() {
    let vec1 = vec![Foo::Bar, Foo::Qux];
    let vec2 = vec![Foo::Bar, Foo::Qux];
    assert_eq!(vec1, vec2);
}

Current output

error[E0369]: binary operation `==` cannot be applied to type `Vec<Foo>`
  --> src/lib.rs:10:5
   |
10 |     assert_eq!(vec1, vec2);
   |     ^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     Vec<Foo>
   |     Vec<Foo>
   |
   = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0369`.
error: could not compile `playground` due to previous error

In the example code, if #[derive(Debug)] is removed, the compiler is helpful and suggests to add it. In this case suggesting #[derive(PartialEq, Eq)] would be great.

Desired output

error[E0277]: `Foo` doesn't implement `PartialEq`
 --> src/lib.rs:9:5
  |
9 |     assert_eq!(vec1, vec2);
  |     ^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be formatted using `{:?}`
  |
  = help: the trait `PartialEq` is not implemented for `Foo`
  = note: add `#[derive(PartialEq, Eq)]` to `Foo` or manually `impl PartialEq for Foo`
  = help: the trait `PartialEq` is implemented for `Vec<T, A>`
  = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `Foo` with `#[derive(PartialEq, Eq)]`
  |
1 | #[derive(PartialEq, Eq)]
  |

Some errors have detailed explanations: E0277, E0369.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `playground` due to 3 previous errors

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions