Skip to content

Improve borrow checking #77505

Closed
Closed
@heckad

Description

@heckad

I tried this code:

fn main() {
    let mut v = vec![1, 2, 3];

    let head = {
        std::mem::replace(&mut v, v.split_off(1))
    };
}

I expected to see this happen: all good.

Instead, this happened: error: cannot borrow v as mutable more than once at a time

If I rewrite this code onto

fn main() {
    let mut v = vec![1, 2, 3];

    let head = {
        let t = v.split_off(1);
        std::mem::replace(&mut v, t)
    };
}

then all be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions