I tend to be curious about language design topics that have some discussion around them, like variadics, keyword generics, or undroppable types, but I never came across discussion about trait generics.
Has there been any proposals for it? Are there clear downsides I'm missing? Is this just an irrelevant feature for most users?
I ask because recently I caught myself searching if the Either type, from the either crate, implemented Iterator when both the Left and Right parameters implemented it too. And then I thought about a "super" Either enum, that would implement any trait T similarly
It isn't possible to forward implementations in general. For example, Either couldn't implement Ord automatically because there's no (automatically) defined relationship between L and R - you can compare L with L and R with R, but the trait interface allows mixed comparisons that couldn't be forwarded.
A restricted version of this might be able to exist? But it would indeed be restricted.
This comment made me realise that Iterator doesn't work for Either either, unless you constrain the associated types to be the same (i.e. you would have to define it as impl<T: Iterator, U: Iterator<Item = T::Item>> Iterator for Either<T, U>).
That suggests something of a solution: a trait generic would probably have to constrain all the types used in the trait implementation, including associated types and non-receiver uses of the Self type.
These rules seem to be the same as the rules for dyn compatibility, and I suspect that that isn't a coincidence.
impl<L, R> Iterator<Item = Either<L::Item, R::Item>> for Either<L, R>
where
L: Iterator,
R: Iterator,
is also a sensible implementation. And, I think, that's a more fundamental issue. That's just not the sort of a choice you can make for autoimplementing every possible trait.