-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArrayVec<A> is invariant in A #96
Comments
arrayvec 2.0, which “will” be implemented with const generics, might have to use usize for the index? I don't know. |
Too speculative and not actionable at this point. It's an interesting note, but it's not the main challenge we have in arrayvec (that's the “const generics” part). |
FWIW the problem of using
Note that this would get rid of a potential The only real issue is getting the alignment of |
struct ArrayVec<A>
contains a field of typeA::Index
. This makes it invariant overA
, for reasons described in rust-lang/rust#21726 (comment) andrustc_typeck::variance
.It would be nice for
ArrayVec<A>
to be covariant overA
, so that for example anArrayVec<[&'long T; N]>
could be used where anArrayVec<[&'short T; N]>
is expected, if'long: 'short
. This would make it act more like[T]
andVec<T>
and other standard library containers.Fixing this might require getting rid of
Array::Index
as an associated type, and finding some other way to specify it.The text was updated successfully, but these errors were encountered: