SE-0346: Lightweight same-type requirements for primary associated types

The primary reason why AnyIterator<Element> et al is necessary to manually write as a generic struct is because you cannot write an existential type any IteratorProtocol<Element> where the Element associated type is constrained and known statically. Extending this exact feature of primary associated type constraints to existential types, which is a future direction of this proposal, would allow that to be expressed without manually writing a type-erasing wrapper type that preserves the primary associated type. There is still an issue that the existential type any IteratorProtocol<Element> does not itself conform to IteratorProtocol, but existential opening solves many use cases that would otherwise need conformances for existential types.

6 Likes