Skip to content

binop trait bound failures due to references should produce nicer message #37626

Closed
@oli-obk

Description

@oli-obk

Let's start off with an example:

#[derive(PartialEq)]
struct Foo;

fn main() {
    let x = &Foo;
    assert!(x == Foo);
}

yields

error[E0277]: the trait bound `&Foo: std::cmp::PartialEq<Foo>` is not satisfied
 --> <anon>:6:13
  |
6 |     assert!(x == Foo);
  |             ^^^^^^^^
  |
  = help: the following implementations were found:
  = help:   <Foo as std::cmp::PartialEq>

Which is either fixed by adding an ampersand before the second argument or a deref before the first

The error message should suggest to insert one or multiple derefs before the argument that has more references than the other. This is a regular issue I get from Rust newcomers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions