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

Slice patterns complain about move if type is not Copy #50639

Closed
ZoeyR opened this issue May 10, 2018 · 1 comment
Closed

Slice patterns complain about move if type is not Copy #50639

ZoeyR opened this issue May 10, 2018 · 1 comment

Comments

@ZoeyR
Copy link

ZoeyR commented May 10, 2018

Compiler Version: 1.26

Consider the following code:

struct Foo;

fn main() {
    let arr=[Foo,Foo];
    let [a,b]=arr;
}

Compiling will produce the following error:

error[E0382]: use of moved value: `arr[..]`
 --> src/main.rs:8:12
  |
8 |     let [a,b]=arr;
  |          - ^ value used here after move
  |          |
  |          value moved here
  |
  = note: move occurs because `arr[..]` has type `Foo`, which does not implement the `Copy` trait

The odd part is this works with tuple patterns:

struct Foo;

fn main() {
    let arr=(Foo,Foo);
    let (a,b)=arr;
}
@goodmanjonathan
Copy link
Contributor

duplicate of #26736

@oli-obk oli-obk closed this as completed May 11, 2018
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

3 participants