Reduce repetitive generic parameters and struct name in impl syntax

Just two further notes:

As written, your proposal doesn't help for trait impls. It's certainly a simple extension to let it, but you need to spell that out if it's part of it.

Duplication between impl blocks for separate traits is a known issue and one that's desired to make simpler. What's been suggested previously is something along the lines of

for<X, Y>
where
  X: Add<Output=X> + Mul<Output=X> + Neg<Output=X>,
  Y: Add<Output=Y> + Mul<Output=Y> + Neg<Output=Y>,
{
    impl Add for Vec2<X, Y> { ... }
    impl Mul for Vec2<X, Y> { ... }
    impl Neg for Vec2<X, Y> { ... }
}

It's still an informal idea rather than a proposal, but one with a mild positive community opinion.

(IIRC, at last discussion, the consensus was to do implied bounds first, as they service a highly related pain point. Additionally, I believe implied bounds also gets you 90% of what benefit you're looking for, as the only repetition left is the necessary-for-root-level declaration of type parameters' names.)

2 Likes