Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve borrow checking #77505

Closed
heckad opened this issue Oct 3, 2020 · 1 comment
Closed

Improve borrow checking #77505

heckad opened this issue Oct 3, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@heckad
Copy link
Contributor

heckad commented Oct 3, 2020

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.

@heckad heckad added the C-bug Category: This is a bug. label Oct 3, 2020
@jonas-schievink
Copy link
Contributor

This is covered by the work on generalized two-phase borrows, which is tracked in #49434. Possibly an RFC amendment would be required to make this case work, since I'm not sure if that is covered by the existing design work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants