Skip to content

It's not possible to destructure and move from boxes without introducing an additional binding #22205

Closed
@renato-zannon

Description

@renato-zannon

This program compiles:

struct NonCopy;

fn main() {
    let x = Box::new((NonCopy, NonCopy));

    let pair = *x;
    let (_a, _b) = pair;
}

But this one does not:

struct NonCopy;

fn main() {
    let x = Box::new((NonCopy, NonCopy));
    let (_a, _b) = *x;
}

It fails with:

destr.rs:6:14: 6:16 error: use of moved value: `x`
destr.rs:6     let (_a, _b) = *x;
                        ^~
destr.rs:6:10: 6:12 note: `x` moved here (through moving `x.0`) because it has type `NonCopy`, which is moved by default
destr.rs:6     let (_a, _b) = *x;
                    ^~
destr.rs:6:10: 6:12 help: use `ref` to override
destr.rs:6     let (_a, _b) = *x;
                    ^~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions