Skip to content

Incorrect partially moved value error check when pattern matching boxed structures. #16223

Closed
@ghost

Description

The following code worked on 0.11 bu no longer works on master. Last known good nightly was August 1st.

struct Foo {
    a: Vec<u8>,
    b: Vec<u8>
}

fn main() {
    let foo = box Foo{a: Vec::new(), b: Vec::new()};
    let Foo { a: a, b: b } = *foo;
}

This will create the following error message:

<anon>:8:24: 8:25 error: use of partially moved value: `foo.b`
<anon>:8     let Foo { a: a, b: b } = *foo;
                                ^
<anon>:8:18: 8:19 note: `foo.a` moved here because it has type `collections::vec::Vec<u8>`, which is moved by default (use `ref` to override)
<anon>:8     let Foo { a: a, b: b } = *foo;

If Foo is not boxed this will function correctly.

struct Foo {
    a: Vec<u8>,
    b: Vec<u8>
}

fn main() {
    let foo = Foo{a: Vec::new(), b: Vec::new()};
    let Foo { a: a, b: b } = foo;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerA-type-systemArea: Type systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions