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

Can't destructure a boxed struct without an intermediate let binding #47376

Closed
haileys opened this issue Jan 12, 2018 · 3 comments
Closed

Can't destructure a boxed struct without an intermediate let binding #47376

haileys opened this issue Jan 12, 2018 · 3 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@haileys
Copy link
Contributor

haileys commented Jan 12, 2018

This code fails to compile:

struct Foo;

struct Bar {
    a: Foo,
    b: Foo,
}

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let Bar { a, b } = *bar;
}
error[E0382]: use of moved value: `bar`
  --> x.rs:11:18
   |
11 |     let Bar { a, b } = *bar;
   |               -  ^ value used here after move
   |               |
   |               value moved here
   |
   = note: move occurs because `bar.a` has type `Foo`, which does not implement the `Copy` trait

However inserting an intermediate let binding in between the box deref and the destructure fixes it:

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let Bar { a, b } = { let intermediate = *bar; intermediate };
}

This feels like a bug.

Affected versions:

  • rustc 1.23.0 (766bd11c8 2018-01-01)

  • rustc 1.25.0-nightly (73ac5d6a8 2018-01-11)

@nagisa
Copy link
Member

nagisa commented Jan 12, 2018

Also happens with box patterns.

#![feature(box_patterns)]

struct Foo;

struct Bar {
    a: Foo,
    b: Foo,
}

fn main() {
    let bar = Box::new(Bar { a: Foo, b: Foo });

    let box Bar { a, b } = bar;
}

@nagisa nagisa added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 12, 2018
@goffrie
Copy link
Contributor

goffrie commented Jan 20, 2018

This is a dupe of #16223.

@steveklabnik
Copy link
Member

Triage: this is fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants