Skip to content

Confusing error when referencing associated types inside trait bounds in trait implementations #116925

Closed
@basil-cow

Description

@basil-cow

Code

trait A<T> {}

trait B {
    type Type;
}

impl<T> B for T
where
    T: A<Self::Type>,
{
    type Type = bool;
}

Current output

error[E0275]: overflow evaluating the requirement `<T as B>::Type == <T as B>::Type`
 --> src/lib.rs:7:1
  |
7 | / impl<T> B for T
8 | | where
9 | |     T: A<Self::Type>,
  | |_____________________^
  |
note: required for `T` to implement `B`
 --> src/lib.rs:7:9
  |
7 | impl<T> B for T
  |         ^     ^
8 | where
9 |     T: A<Self::Type>,
  |        ------------- unsatisfied trait bound introduced here

For more information about this error, try `rustc --explain E0275`.

Desired output

an explanation that `Self::Type` does not reference `bool` but tries to figure out whether T already implements B

Rationale and extra context

spawned from #116914

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.D-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