"unconstrained type parameter" - but it is!

The following code:

trait A<C> {}

trait B {}

impl<T: A<C>, C> B for T {}


error[E0207]: the type parameter `C` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:5:15
5 | impl<T: A<C>, C> B for T {}
  |               ^ unconstrained type parameter

Although it's clear that C is needed for the generic constraint over T.

Moreover, if I use associated types:

trait A {
    type C;

trait B {}

impl<T: A<C = C>, C> B for T {}

The code compiles fine!

Can someone explain this please?

struct Q {}

impl A<i32> for Q {}
impl A<i64> for Q {}

Now, which impl B applies to Q?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.