Skip to content
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

No way to default initialize large array of Option<NotCopy> #1740

Closed
Storyyeller opened this issue Sep 5, 2016 · 1 comment
Closed

No way to default initialize large array of Option<NotCopy> #1740

Storyyeller opened this issue Sep 5, 2016 · 1 comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@Storyyeller
Copy link

Storyyeller commented Sep 5, 2016

I want to have an array of 65535 elements of Option<NonCopyType> with everything initialized to None, but I couldn't figure out any way to do it.

The obvious approach of [None; 65535] causes the compiler to complain that the element type isn't Copy. Which is true, but obviously the value None itself should be copyable. (Though to be honest, I'm not sure why the bound is Copy and not Clone in the first place).

I also tried using Default::default(), but unfortunately, default is only implemented for arrays up to size 32, so that didn't work either.

I ended up having to create a Vec and manually push(None) in a loop, even though the size is statically known!

@eddyb
Copy link
Member

eddyb commented Sep 6, 2016

This is #1169 (I've also left a comment there explaining how the issue might be solved with MIR).

@eddyb eddyb closed this as completed Sep 6, 2016
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants