Skip to content

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

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

Closed
oli-obk opened this issue Nov 7, 2016 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Nov 7, 2016

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.

bors added a commit that referenced this issue Apr 10, 2017
Explicit help message for binop type mismatch

When trying to do `1 + Some(2)`, or some other binary operation on two
types different types without an appropriate trait implementation, provide
an explicit help message:

```rust
help: `{integer} + std::option::Option<{integer}>` has no implementation
```

Re: #39579, #38564, #37626, #39942, #34698.
@Mark-Simulacrum
Copy link
Member

We don't currently have any suggestion to dereference x... error message is below.

error[E0277]: the trait bound `&Foo: std::cmp::PartialEq<Foo>` is not satisfied
 --> test.rs:6:13
  |
6 |     assert!(x == Foo);
  |             ^^^^^^^^ the trait `std::cmp::PartialEq<Foo>` is not implemented for `&Foo`
  |
  = note: can't compare `&Foo` with `Foo`

error: aborting due to previous error

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label May 16, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of #39942 which is more specific.

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
Projects
None yet
Development

No branches or pull requests

2 participants