From 4666792ac600f4e4e1c09a37b88f40f6125b57b8 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Sat, 7 Jun 2014 02:55:00 -0700 Subject: [PATCH] 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. --- .../borrowck-field-sensitivity.rs | 29 ++++++++--------- .../run-pass/borrowck-field-sensitivity.rs | 31 +++++++++++-------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/test/compile-fail/borrowck-field-sensitivity.rs b/src/test/compile-fail/borrowck-field-sensitivity.rs index 9a0d81e73320..2fa9067af549 100644 --- a/src/test/compile-fail/borrowck-field-sensitivity.rs +++ b/src/test/compile-fail/borrowck-field-sensitivity.rs @@ -10,8 +10,6 @@ struct A { a: int, b: Box } -fn borrow(_: &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() { diff --git a/src/test/run-pass/borrowck-field-sensitivity.rs b/src/test/run-pass/borrowck-field-sensitivity.rs index 2500ec764eba..a297300daf1b 100644 --- a/src/test/run-pass/borrowck-field-sensitivity.rs +++ b/src/test/run-pass/borrowck-field-sensitivity.rs @@ -11,8 +11,6 @@ struct A { a: int, b: Box } struct B { a: Box, b: Box } -fn borrow(_: &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() {