Skip to content

MIR Borrowck does not handle borrows of array elements #45537

Closed

Description

@nikomatsakis

This example only shows 1 error, from the AST borrow checker:

#![allow(warnings)]
#![feature(rustc_attrs)]

fn use_x(_: usize) -> bool { true }

#[rustc_mir_borrowck]
fn main() {
    let mut v = [1, 2, 3];
    let p = &v[0];
    if true {
        use_x(*p);
    } else {
        use_x(22);
    }
    v[0] += 1;
}

cc @arielb1

Activity

  1. nikomatsakis commented on Oct 25, 2017

    @nikomatsakis
    ContributorAuthor

    I get:

    Mr-Darcy. rustc +nightly -Zborrowck-mir region-liveness-basic.rs
    error[E0506]: cannot assign to `v[..]` because it is borrowed (Ast)
      --> region-liveness-basic.rs:32:5
       |
    26 |     let p = &v[0];
       |              ---- borrow of `v[..]` occurs here
    ...
    32 |     v[0] += 1;
       |     ^^^^^^^^^ assignment to borrowed `v[..]` occurs here
    
    error: aborting due to previous error
    
  2. oli-obk commented on Oct 26, 2017

    @oli-obk
    Contributor

    Not sure what is going on, but if -Zborrowck-mir is not passed, the error output is

    error[E0506]: cannot assign to `v[..]` because it is borrowed
      --> foo.rs:15:5
       |
    9  |     let p = &v[0];
       |              ---- borrow of `v[..]` occurs here
    ...
    15 |     v[0] += 1;
       |     ^^^^^^^^^ assignment to borrowed `v[..]` occurs here
    
    error[E0506]: cannot assign to `v` because it is borrowed (Mir)
      --> foo.rs:16:2
       |
    9  |     let p = &v[0];
       |             ----- borrow of `v` occurs here
    ...
    16 | }
       |  ^ assignment to borrowed `v` occurs here
    
    error: aborting due to 2 previous errors
    
  3. added this to the NLL prototype milestone on Nov 15, 2017
  4. added a commit that references this issue on Dec 6, 2017
    cf30759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions