What's the point of LengthAtMost32?

I was reading the PR of adding proper into_iter on arrays (see Add by-value iterator for arrays by LukasKalbertodt · Pull Request #62959 · rust-lang/rust · GitHub ), but then I found that for some reason they implement it only for arrays <= 32.

My question is why? What would break if we implement it for any arrays? I don't see any harm here.

Is there any hardcoded limit in the compiler which will break in this case?

Before the compiler had const generics at all, array implementations were all duplicated for [T; 0], [T; 1], ... [T; 32] using macros.

Now that we do have const generics, those have been consolidated with const type parameters for the length. However, as that feature is still unstable, we want to have an easy way to go back, so we keep the former limit using LengthAtMost32. If we need to rip out const generics for some reason, we still can.

Eventually, this should be opened up to all array lengths.

5 Likes

Cool. I actually thought something similar but didn't touch the truth anyway.

Thanks for quick reply.

The PR that added it links the the tracking issue discussing why it's done this way:

https://github.com/rust-lang/rust/pull/62435

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.