What is the point with associated types bounds in a trait definition?

An example: Rust Playground

trait FieldLens has the requirement that an implementor is also Lens, and, importantly: where Self::Target: PartialEq.

However, as you can see the compiler is not quite satisfied when we try to make a function that takes a L: FieldLens:

can't compare `<L as Lens>::Target` with `<L as Lens>::Target`

Even though we have asserted previously that any FieldLens must have Self::Target: PartialEq, the compiler seems to have forgotten this and we have to tell it again with a where clause.
Why? What is otherwise the point with associated types bounds?

It would work if that constraint was on the original Target declaration in Lens, but in a less direct situation like yours, I think it's this bug:

https://github.com/rust-lang/rust/issues/20671

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.