Skip to content

Two-phase borrows don't allow mutably splitting an array based on its length #53723

Open
@shepmaster

Description

@shepmaster
#![feature(nll)]
fn main() {
    let mut x = [1, 2];
    x.split_at_mut(x.len() / 2);
}
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
 --> src/main.rs:4:20
  |
4 |     x.split_at_mut(x.len() / 2);
  |     ---------------^-----------
  |     |              |
  |     |              immutable borrow occurs here
  |     mutable borrow occurs here
  |     borrow later used here

1.30.0-nightly (2018-08-24 d41f21f)

/cc @nikomatsakis @pnkfelix

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-arrayArea: `[T; N]`NLL-completeWorking towards the "valid code works" goalP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions