Skip to content

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

Closed
@estebank

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-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