Skip to content

Struct destructuring allows repeated bindings of a moved variable #9725

Closed
@alexcrichton

Description

@alexcrichton

This code will segfault when run:

struct A {
    a: ~int,
    b: bool,
}

fn main() {
    let a = A { a: ~2, b: true };
    let A { a, a, _ } = a;
    println!("{:?}", a);
}

I'm not entirely sure why it segfaults, but I shouldn't be able to bind the name a twice. Turns out if you have long variable names and you accidentally forget the colon (to make it a: a, then this is will come back to bite you!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationP-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions