Skip to content

Better diagnostic message when hitting 32 element limit on array trait impl #67728

@squeaky-pl

Description

@squeaky-pl

So in #rustlang trait implementations on arrays are only implemented to maximum hardcoded 32 elements. I was bitten by this today, and I couldn't figure this out for a while. This would compile if you remove 5 since it would fit in 32 elems but the real solution is to call .iter() and not rely on IntoIter. This of course was reduced to simple case and my original problem appeared in a more complex expression with a lot extra clutter.

Screenshot_588

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2a5cc5675e9ddc92d45d5978edd658d1

I realize this is probably gonna be solved with advent of const generics but I'm not sure how far or close they are. This is also mentioned in array docs., but in the meantime maybe #rustlang rustc compiler could give better diagnostic message for this particular case. I was banging my head really hard on this one.

Maybe it could detect hard coded 32 and point to the passage in array docs that mentions these limitations and offer some hints like calling .iter() in this case. Not sure what could be detected and done here exactly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions