Bounds on associated types not propagated correctly

[Cross-post from the users forum]

I am trying to write some code like this:

Link to the Playground

pub trait A<T> {
}

pub trait B {
    type X;
    type Y: A<Self::X>;
}

pub trait C {
    type X;
    type Y: B<X = Self::X>;
    // ^^^ This complains that <Self:Y as B>::Y does not implement A<Self::X>
    //     although Self::Y wouldn't be implementing B otherwise, now would it,
    //     given that Self::X == <Self::Y as B>::X.
}

I suspect it has to do with the type equality Self::X == <Self::Y as B>::X. However, I wish Rust evaluated these requirements on impl rather than on trait declaration, since there it would be more obvious what the types are.

On the #beginners forum, stephaneyfx provided this brilliant workaround Link to Playground:

pub trait C {
    type X;
    type BY: A<Self::X>;
    type Y: B<X = Self::X, Y = Self::BY>;
}

By adding BY with the same bound as B::Y has, rustc was appeased. The question still remains: whyyy :cry:?

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