Trait alias. by hadronized · Pull Request #1733 · rust-lang/rfcs (original) (raw)

I think I'm generally in favor of adding some kind of shorthand for "trait aliases" (or "where-clause aliases", depending on your POV). @aturon and I talked about it recently and we felt like the syntax ought to be modeled on the syntax for declaring a new trait with supertraits, but with = replacing :. So if you had a declaration like this:

trait SymPartialEq = PartialEq where T: PartialEq;

then you could do:

fn foo<T, U>() where T: SymPartialEq

and it would be equivalent to

fn foo<T, U>() where T: PartialEq, U: PartialEq

I'm not sure what to do about the case where you want just a where-clause though, and no =. I don't like trait Foo<T> where T: Bar<Self>, because it looks too much like a declaration of a new trait. I guess trait Foo<T> = where T: Bar<Self> might be ok.

Not sure if I love the precise syntax here, but there is something nice about the symmetry with supertrait clauses, and the "bias" to always have a Self type, just like regular traits.

It seems good for the more common cases that don't require where clauses, e.g.