Skip to content

Cannot move out of destructured fixed length vectors in let and match #16418

Closed
@brendanzab

Description

@brendanzab
struct Vector3<S>(S, S, S);

// passes type checking
fn into_vec3_arg<S>([x, y, z]: [S, ..3]) -> Vector3<S> {
    Vector3(x, y, z)
}

fn into_vec3_let<S>(v: [S, ..3]) -> Vector3<S> {
    let [x, y, z] = v; // error: use of moved value: `v[..]`
    Vector3(x, y, z)
}

fn into_vec3_match<S>(v: [S, ..3]) -> Vector3<S> {
    match v {
        // error: use of moved value: `v[..]`
        [x, y, z] => Vector3(x, y, z),
    }
}

http://is.gd/bc1U2v

Note that it is impossible to work around this using transmute, because:

struct Vector3<S>(S, S, S);

fn into_vec3_transmute<S>(v: [S, ..3]) -> Vector3<S> {
    // error: cannot transmute from a type that contains type parameters
    unsafe { mem::transmute(v) }
}

http://is.gd/BeSWOs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions