Skip to content

MIR Borrowck does not handle borrows of array elements #45537

New issue

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

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

Already on GitHub? # to your account

Closed
nikomatsakis opened this issue Oct 25, 2017 · 2 comments
Closed

MIR Borrowck does not handle borrows of array elements #45537

nikomatsakis opened this issue Oct 25, 2017 · 2 comments
Assignees
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@nikomatsakis
Copy link
Contributor

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

@nikomatsakis nikomatsakis added E-needs-mentor T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 25, 2017
@nikomatsakis
Copy link
Contributor Author

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

@oli-obk
Copy link
Contributor

oli-obk commented Oct 26, 2017

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

@TimNN TimNN added the C-bug Category: This is a bug. label Oct 31, 2017
@arielb1 arielb1 added this to the NLL prototype milestone Nov 15, 2017
arielb1 added a commit to arielb1/rust that referenced this issue Dec 6, 2017
Fixes rust-lang#44831.
Fixes rust-lang#44834.
Fixes rust-lang#45537.
Fixes rust-lang#45696 (by implementing DerefPure semantics, which is what we want
going forward).
bors added a commit that referenced this issue Dec 6, 2017
MIR borrowck: implement union-and-array-compatible semantics

Fixes #44831.
Fixes #44834.
Fixes #45537.
Fixes #45696 (by implementing DerefPure semantics, which is what we want going forward).

r? @nikomatsakis
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants