Unintended invariance caused by associated type projections
The Rust Programming Language Forum
Unintended invariance caused by associated type projections
In SmallVec v1, SmallVec<A> is invariant with respect to the generic parameter A. The reason is that its fields use the associated type projection A::Item, and the compiler treats that projection as invariant with respect to A. We can see this directly in the v1 source code. The Array trait defines the associated type, and the implementation for arrays confirms that A::Item is T: pub unsafe trait Array { type Item; fn size() -> usize; } // When A = [T; N] unsafe impl<T, const N: usize>...
0 comments
No comments yet.