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

Point at bound introducing obligation of call parameter for where clause bounds #89038

Closed
estebank opened this issue Sep 17, 2021 · 3 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Sep 17, 2021

The following code

impl<T> Foo<T> {
fn equals(&self, u: &Foo<T>) -> bool where T : Eq {
self.value == u.value
}
}
fn main() {
let x = Foo { value: Bar };
x.equals(&x);
//~^ ERROR `Bar: Eq` is not satisfied
}

emits

error[E0277]: the trait bound `Bar: Eq` is not satisfied
--> $DIR/where-clauses-method-unsatisfied.rs:18:14
|
LL | x.equals(&x);
| ------ ^^ the trait `Eq` is not implemented for `Bar`
| |
| required by a bound introduced by this call
error: aborting due to previous error

It should point at the where T : Eq bound as well.

Noticed in https://github.com/rust-lang/rust/pull/88719/files#r708156543:

This case has a MiscObligation, so for some where clauses we need to do better, but at least we point at the relevant argument. The new span pointing at the call at least hints at the user that they should look at the equals implementation to figure out why the bound was added.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Sep 17, 2021
@compiler-errors
Copy link
Member

Was this fixed by #89580?

@compiler-errors
Copy link
Member

For the record, we now error with:

error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `Bar: Eq` is not satisfied
  --> src/main.rs:13:15
   |
13 |      x.equals(&x); 
   |        ------ ^^ the trait `Eq` is not implemented for `Bar`
   |        |
   |        required by a bound introduced by this call
   |
note: required by a bound in `Foo::<T>::equals`
  --> src/main.rs:6:53
   |
6  |      fn equals(&self, u: &Foo<T>) -> bool where T : Eq { 
   |                                                     ^^ required by this bound in `Foo::<T>::equals`
help: consider annotating `Bar` with `#[derive(Eq)]`
   |
1  | #[derive(Eq)]
   |

Note the "note"

@estebank
Copy link
Contributor Author

Yeah, that seems good to me.

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-trait-system Area: Trait system D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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

2 participants