cppalliance / safe-cpp

Boost Software License 1.0
152 stars 13 forks source link

Circle misses borrowck conflict #67

Open seanbaxter opened 2 weeks ago

seanbaxter commented 2 weeks ago
fn main() {
  let mut x = 1;

  let r1 = &mut x;
  let r2 = &mut *r1;

  let x = *r1;
  *r2 = 200;
}
error[E0503]: cannot use `*r1` because it was mutably borrowed
 --> foo.rs:7:11
  |
5 |   let r2 = &mut *r1;
  |            -------- `*r1` is borrowed here
6 |
7 |   let x = *r1;
  |           ^^^ use of borrowed `*r1`
8 |   *r2 = 200;
  |   --------- borrow later used here

Rust flags the use of r1 when there's a live reborrow r2. Circle doesn't do that. This compiles:

#feature on safety

int main() {
  int x = 1;

  int^ r1 = ^x;
  int^ r2 = ^*r1;

  *r1 = 100;
  *r2 = 200;
}

It's not clear how to determine that the loan on *r1 is a relevant loan that should raise the conflict.