Skip to content

Incorrect "moving prohibited due to outstanding loan" error when destructuring vector with owned contents #4886

Closed
@bstrie

Description

@bstrie
fn main() {
    let split = [~1, ~2];

    match split {
        [] => die!(),
        [_head, ..tail] => tail
    };
}

I'm not 100% sure if this should be legal, but the error message it gives is baffling:

$ rustc split2.rs
split2.rs:4:10: 4:15 error: moving out of immutable local variable prohibited due to outstanding loan
split2.rs:4     match split {
                      ^~~~~
split2.rs:4:10: 4:15 note: loan of immutable local variable granted here
split2.rs:4     match split {
                      ^~~~~
error: aborting due to previous error

Note that the error only occurs if you create a head binding. Replacing _head with _ causes this error to go away.

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