Generic struct with where, why does it need the where on impls?

If I have a generic struct:

pub struct AStruct<T>
where
    T: MyTrait
{
    field: T
}

And I implement some OtherTrait on it, why does the impl also require a where T: MyTrait?

Ex. this won't work:

impl OtherTrait for AStruct<T> {}

Has to be:

impl OtherTrait for AStruct<T> 
where T: MyTrait 
{}

If the struct can only be made with a type that implements MyTrait, why do I need to put a bunch of extra where clauses on all the impl?

RFC 2089 proposes no longer requiring those bounds on the impl. The RFC was accepted and the implementation is being tracked in rust-lang/rust#44491.

2 Likes

Ah, well then yay. :slight_smile: