Lifting the constraint wouldn’t indeed help to avoid creating type erased boxes, but it could somewhat simplify it when working with members that don’t use Self/associated types.
e.g. (primary for being able to mock things) I often write such wrappers:
protocol Foo {
associatedtype Bar
var x: Int { get }
var y: Int { get }
}
struct AnyFoo<T>: Foo {
typealias Bar = T
private let _getX: () -> Int
private let _getY: () -> Int
var x: Int { return _getX() }
var y: Int { return _getY() }
init<K: Foo>(_ val: K) where K.Bar == T {
self._getX = { return val.x }
self._getY = { return val.y }
}
}
Being able to use simple type members would decrease memory footprint of such wrapper and simplify the code.