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

Array initialization with repeated enum variant requires the whole enum type to be Copy #30754

Closed
benw opened this issue Jan 7, 2016 · 2 comments

Comments

@benw
Copy link

benw commented Jan 7, 2016

I want to initialize an array of Option<Foo> with [None; 5]. The None variant is constant and has no associated data, so there seems to be no reason that it couldn't be copied into all the entries in the array:

struct Foo;

fn main() {
    let mut array: [Option<Foo>; 5] = [None; 5];
}

Sadly this errors because Foo is not Copy, so Option<Foo> is not Copy.

<anon>:4:35: 4:44 error: the trait `core::marker::Copy` is not implemented for the type `Foo` [E0277]
<anon>:4     let array: [Option<Foo>; 5] = [None; 5];
                                           ^~~~~~~~~

I gather array initialization treats None as an expression in this case? Could it instead notice that None is a constant, and copy it to all the elements in the array?

@huonw
Copy link
Member

huonw commented Jan 7, 2016

This is a dupe of #5244 which (transitively) is a dupe of rust-lang/rfcs#1109. Thanks for filing anyway!

@huonw huonw closed this as completed Jan 7, 2016
@benw
Copy link
Author

benw commented Jan 7, 2016

Thanks! I searched but did not find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants