-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
allow slice patterns to match non-fixed/generic length arrays #3675
Comments
@kennytm you reacted with the confused emoji, could you elaborate what confuses you? |
@Skgland do you have any concrete example that actually needing the type of |
I find this feature request not unreasonable. However, this is pretty much blocked on GCE (generic_const_exprs) as such a match introduces values of type |
All of them would have been replaced with workarounds by now, so no I don't. I included it even though I don't have a specific use case because leaving out sub-array patterns seamed to leave the feature incomplete.
Could an initial implementation disallow binding the sub-array i.e. |
I don't think there would ever be a reason to manually write those, but I could see it making writing a macro easier/possible by turning those cases from errors to warnings. Maybe a specialized deny by default lint would make sense. |
Currently slice patterns can match fixed sized arrays and dynamic sized slices. It would be useful in code over generic length array to also be able to match on dynamic sized/non-fixed length/generic length arrays.
play-ground
Currently this results in E7030 and E0308
For arrays behind references one can mostly workaround this by turning the array reference into a slice reference.
But this leaves out the owned case and for arrays I would expect sub-array patterns to be arrays rather than slices, i.e. for input type
&[u8;N]
the type of_rest
for the first example would be&[u8;N - 2]
rather than&[u8]
.For exhaustiveness checking generic arrays would be treated like slices i.e. all lengths (
0..=usize::MAX
) needs to be covered.The text was updated successfully, but these errors were encountered: