Skip to content

Suggest implementing PartialEq for Foo when comparing Option<Foo> with Option<Foo>  #84515

Closed
@MarkDDR

Description

@MarkDDR

Given the following code: Link to Playground

struct Foo;

fn main() {
    let _ = Some(Foo) == Some(Foo);
}

The current output is:

error[E0369]: binary operation `==` cannot be applied to type `Option<Foo>`
 --> src/main.rs:4:23
  |
4 |     let _ = Some(Foo) == Some(Foo);
  |             --------- ^^ --------- Option<Foo>
  |             |
  |             Option<Foo>

Ideally the output should look like:

error[E0369]: binary operation `==` cannot be applied to type `Option<Foo>`
 --> src/main.rs:4:23
  |
4 |     let _ = Some(Foo) == Some(Foo);
  |             --------- ^^ --------- Option<Foo>
  |             |
  |             Option<Foo>
  |
  = note: an implementation of `std::cmp::PartialEq<Option<Foo>>` is found for `Option<Foo>`
          but the trait bounds were not satisfied:
          `Foo: PartialEq<Foo>`
  = note: an implementation of `std::cmp::PartialEq` might be missing for `Foo`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-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