Clean up borrows in borrowck field-sensitivity tests

Instead of calling a borrow() function that takes a pointer type, just
create a local pointer and dereference it. The dereference is there to
outsmart any future liveness analysis in borrowck.
This commit is contained in:
Cameron Zwarich 2014-06-07 02:55:00 -07:00
parent 653f57af20
commit 4666792ac6
2 changed files with 33 additions and 27 deletions

View File

@ -10,8 +10,6 @@
struct A { a: int, b: Box<int> }
fn borrow<T>(_: &T) { }
fn deref_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
@ -27,35 +25,37 @@ fn deref_after_fu_move() {
fn borrow_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
borrow(&x.b); //~ ERROR use of moved value: `x.b`
let p = &x.b; //~ ERROR use of moved value: `x.b`
drop(**p);
}
fn borrow_after_fu_move() {
let x = A { a: 1, b: box 2 };
let _y = A { a: 3, .. x };
borrow(&x.b); //~ ERROR use of moved value: `x.b`
let p = &x.b; //~ ERROR use of moved value: `x.b`
drop(**p);
}
fn move_after_borrow() {
let x = A { a: 1, b: box 2 };
let y = &x.b;
let p = &x.b;
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
borrow(&*y);
drop(**p);
}
fn fu_move_after_borrow() {
let x = A { a: 1, b: box 2 };
let y = &x.b;
let _z = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
borrow(&*y);
let p = &x.b;
let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
drop(**p);
}
fn mut_borrow_after_mut_borrow() {
let mut x = A { a: 1, b: box 2 };
let y = &mut x.a;
let z = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
drop(*y);
drop(*z);
let p = &mut x.a;
let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
drop(*p);
drop(*q);
}
fn move_after_move() {
@ -107,7 +107,8 @@ fn copy_after_field_assign_after_uninit() {
fn borrow_after_field_assign_after_uninit() {
let mut x: A;
x.a = 1;
borrow(&x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
let p = &x.a; //~ ERROR use of possibly uninitialized variable: `x.a`
drop(*p);
}
fn move_after_field_assign_after_uninit() {

View File

@ -11,8 +11,6 @@
struct A { a: int, b: Box<int> }
struct B { a: Box<int>, b: Box<int> }
fn borrow<T>(_: &T) { }
fn move_after_copy() {
let x = A { a: 1, b: box 2 };
drop(x.a);
@ -64,21 +62,23 @@ fn fu_copy_after_fu_move() {
fn borrow_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
borrow(&x.a);
let p = &x.a;
drop(*p);
}
fn borrow_after_fu_move() {
let x = A { a: 1, b: box 2 };
let _y = A { a: 3, .. x };
borrow(&x.a);
let p = &x.a;
drop(*p);
}
fn mut_borrow_after_mut_borrow() {
let mut x = A { a: 1, b: box 2 };
let y = &mut x.a;
let z = &mut x.b;
drop(*y);
drop(**z);
let p = &mut x.a;
let q = &mut x.b;
drop(*p);
drop(**q);
}
fn move_after_move() {
@ -138,28 +138,32 @@ fn borrow_after_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x = A { a: 3, b: box 4 };
borrow(&x.b);
let p = &x.b;
drop(**p);
}
fn borrow_after_assign_after_fu_move() {
let mut x = A { a: 1, b: box 2 };
let _y = A { a: 3, .. x };
x = A { a: 3, b: box 4 };
borrow(&x.b);
let p = &x.b;
drop(**p);
}
fn borrow_after_field_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x.b = box 3;
borrow(&x.b);
let p = &x.b;
drop(**p);
}
fn borrow_after_field_assign_after_fu_move() {
let mut x = A { a: 1, b: box 2 };
let _y = A { a: 3, .. x };
x.b = box 3;
borrow(&x.b);
let p = &x.b;
drop(**p);
}
fn move_after_assign_after_move() {
@ -199,7 +203,8 @@ fn copy_after_assign_after_uninit() {
fn borrow_after_assign_after_uninit() {
let mut x: A;
x = A { a: 1, b: box 2 };
borrow(&x.a);
let p = &x.a;
drop(*p);
}
fn move_after_assign_after_uninit() {