Open scottmcm opened 6 years ago
Special casing array length 0 here might become an issue when we want to generalize these impls with const generics. This wouldn't be an issue if we had specialization for const generics or some kind of where N > 0
that is actually understood by overlap checks, that's pretty tricky in general and I don't expect it to happen in the first implementation.
@rkruppe if specialization is extended to consider const generics then the impls for [T; const N]
could be defaulted and then specialized for [T; 0]
. If specialization moves forward via Aaron Turon's proposal then this would be a straightforward extension of that logic, e.g. specialize(const N = 0)
.
I could be wrong about how easy it is to extend specialization to const values, but I'm a bit pessimistic about anything regarding specialization being straightforward. And in any case, it would suck to have basic const generics available (enough to write impls for all arrays) but not be able to apply them to core APIs because we fixed this minor issue before.
So I think it might be prudent to hold off lifting the restrictions on impls for empty arrays until we have both const generic and some way to special case N = 0. Relatedly, I think libs team policy so far has been to not add any (stable?) APIs that can't be implemented without specialization.
Triage: not aware of any changes
All of the following have
where T: Trait
on their impls for[T; 0]
, but don't need it:A demo of those not in rustdoc:
Kudos to whomever did the
Default
impls for getting this right: https://doc.rust-lang.org/std/primitive.array.html#impl-Default-29