diff options
| author | bors <bors@rust-lang.org> | 2014-06-07 10:17:38 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-06-07 10:17:38 -0700 |
| commit | ffdb881337911e65f25dba2dc6e67aed29ffa4cc (patch) | |
| tree | 85207b4a0f0104200e195a794ef3c0f7f0307596 /src | |
| parent | 8e9e484d7089590ce63bfe21723d7ee0c50be8f4 (diff) | |
| parent | 4666792ac600f4e4e1c09a37b88f40f6125b57b8 (diff) | |
| download | rust-ffdb881337911e65f25dba2dc6e67aed29ffa4cc.tar.gz rust-ffdb881337911e65f25dba2dc6e67aed29ffa4cc.zip | |
auto merge of #14717 : zwarich/rust/borrowck-tests, r=cmr
After sitting down to build on the work merged in #14318, I realized that some of the test names were not clear, others probably weren't testing the right thing, and they were also not as exhaustive as they could have been.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/compile-fail/borrowck-field-sensitivity.rs | 58 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-field-sensitivity.rs | 159 |
2 files changed, 133 insertions, 84 deletions
diff --git a/src/test/compile-fail/borrowck-field-sensitivity.rs b/src/test/compile-fail/borrowck-field-sensitivity.rs index 4363f85048f..2fa9067af54 100644 --- a/src/test/compile-fail/borrowck-field-sensitivity.rs +++ b/src/test/compile-fail/borrowck-field-sensitivity.rs @@ -10,15 +10,13 @@ struct A { a: int, b: Box<int> } -fn borrow<T>(_: &T) { } - -fn use_after_move() { +fn deref_after_move() { let x = A { a: 1, b: box 2 }; drop(x.b); drop(*x.b); //~ ERROR use of partially moved value: `*x.b` } -fn use_after_fu_move() { +fn deref_after_fu_move() { let x = A { a: 1, b: box 2 }; let y = A { a: 3, .. x }; drop(*x.b); //~ ERROR use of partially moved value: `*x.b` @@ -27,35 +25,37 @@ fn use_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() { @@ -84,7 +84,21 @@ fn fu_move_after_fu_move() { // The following functions aren't yet accepted, but they should be. -fn use_after_field_assign_after_uninit() { +fn move_after_borrow_correct() { + let x = A { a: 1, b: box 2 }; + let p = &x.a; + drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed + drop(*p); +} + +fn fu_move_after_borrow_correct() { + let x = A { a: 1, b: box 2 }; + let p = &x.a; + let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed + drop(*p); +} + +fn copy_after_field_assign_after_uninit() { let mut x: A; x.a = 1; drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a` @@ -93,7 +107,8 @@ fn use_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() { @@ -103,8 +118,8 @@ fn move_after_field_assign_after_uninit() { } fn main() { - use_after_move(); - use_after_fu_move(); + deref_after_move(); + deref_after_fu_move(); borrow_after_move(); borrow_after_fu_move(); @@ -117,7 +132,10 @@ fn main() { fu_move_after_move(); fu_move_after_fu_move(); - use_after_field_assign_after_uninit(); + move_after_borrow_correct(); + fu_move_after_borrow_correct(); + + copy_after_field_assign_after_uninit(); borrow_after_field_assign_after_uninit(); 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 3b82f51123f..a297300daf1 100644 --- a/src/test/run-pass/borrowck-field-sensitivity.rs +++ b/src/test/run-pass/borrowck-field-sensitivity.rs @@ -11,92 +11,74 @@ struct A { a: int, b: Box<int> } struct B { a: Box<int>, b: Box<int> } -fn borrow<T>(_: &T) { } - -fn move_after_use() { +fn move_after_copy() { let x = A { a: 1, b: box 2 }; drop(x.a); drop(x.b); } -fn move_after_fu_use() { +fn move_after_fu_copy() { let x = A { a: 1, b: box 2 }; let _y = A { b: box 3, .. x }; drop(x.b); } -fn fu_move_after_use() { +fn fu_move_after_copy() { let x = A { a: 1, b: box 2 }; drop(x.a); - let y = A { a: 3, .. x }; - drop(y.b); + let _y = A { a: 3, .. x }; } -fn fu_move_after_fu_use() { +fn fu_move_after_fu_copy() { let x = A { a: 1, b: box 2 }; let _y = A { b: box 3, .. x }; - let z = A { a: 4, .. x }; - drop(z.b); + let _z = A { a: 4, .. x }; } -fn use_after_move() { +fn copy_after_move() { let x = A { a: 1, b: box 2 }; drop(x.b); drop(x.a); } -fn use_after_fu_move() { +fn copy_after_fu_move() { let x = A { a: 1, b: box 2 }; let y = A { a: 3, .. x }; drop(x.a); - drop(y.b); } -fn fu_use_after_move() { +fn fu_copy_after_move() { let x = A { a: 1, b: box 2 }; drop(x.b); let _y = A { b: box 3, .. x }; } -fn fu_use_after_fu_move() { +fn fu_copy_after_fu_move() { let x = A { a: 1, b: box 2 }; - let y = A { a: 3, .. x }; + let _y = A { a: 3, .. x }; let _z = A { b: box 3, .. x }; - drop(y.b); } 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); - drop(y.b); -} - -fn move_after_borrow() { - let x = A { a: 1, b: box 2 }; - borrow(&x.a); - drop(x.b); -} - -fn fu_move_after_borrow() { - let x = A { a: 1, b: box 2 }; - borrow(&x.a); - let y = A { a: 3, .. x }; - drop(y.b); + let _y = A { a: 3, .. x }; + 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() { @@ -109,7 +91,6 @@ fn move_after_fu_move() { let x = B { a: box 1, b: box 2 }; let y = B { a: box 3, .. x }; drop(x.a); - drop(y.b); } fn fu_move_after_move() { @@ -121,46 +102,82 @@ fn fu_move_after_move() { fn fu_move_after_fu_move() { let x = B { a: box 1, b: box 2 }; - let y = B { b: box 3, .. x }; - let z = B { a: box 4, .. x }; - drop(y.a); - drop(z.b); + let _y = B { b: box 3, .. x }; + let _z = B { a: box 4, .. x }; } -fn use_after_assign_after_move() { +fn copy_after_assign_after_move() { let mut x = A { a: 1, b: box 2 }; drop(x.b); x = A { a: 3, b: box 4 }; drop(*x.b); } -fn use_after_field_assign_after_move() { +fn copy_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 }; + drop(*x.b); +} + +fn copy_after_field_assign_after_move() { let mut x = A { a: 1, b: box 2 }; drop(x.b); x.b = box 3; drop(*x.b); } +fn copy_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; + drop(*x.b); +} + 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 }; + 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; + let p = &x.b; + drop(**p); } fn move_after_assign_after_move() { let mut x = A { a: 1, b: box 2 }; - let y = x.b; + let _y = x.b; + x = A { a: 3, b: box 4 }; + drop(x.b); +} + +fn move_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 }; drop(x.b); - drop(y); } fn move_after_field_assign_after_move() { @@ -170,7 +187,14 @@ fn move_after_field_assign_after_move() { drop(x.b); } -fn use_after_assign_after_uninit() { +fn move_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; + drop(x.b); +} + +fn copy_after_assign_after_uninit() { let mut x: A; x = A { a: 1, b: box 2 }; drop(x.a); @@ -179,7 +203,8 @@ fn use_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() { @@ -189,19 +214,17 @@ fn move_after_assign_after_uninit() { } fn main() { - move_after_use(); - move_after_fu_use(); - fu_move_after_use(); - fu_move_after_fu_use(); - use_after_move(); - use_after_fu_move(); - fu_use_after_move(); - fu_use_after_fu_move(); + move_after_copy(); + move_after_fu_copy(); + fu_move_after_copy(); + fu_move_after_fu_copy(); + copy_after_move(); + copy_after_fu_move(); + fu_copy_after_move(); + fu_copy_after_fu_move(); borrow_after_move(); borrow_after_fu_move(); - move_after_borrow(); - fu_move_after_borrow(); mut_borrow_after_mut_borrow(); move_after_move(); @@ -209,14 +232,22 @@ fn main() { fu_move_after_move(); fu_move_after_fu_move(); - use_after_assign_after_move(); - use_after_field_assign_after_move(); + copy_after_assign_after_move(); + copy_after_assign_after_fu_move(); + copy_after_field_assign_after_move(); + copy_after_field_assign_after_fu_move(); + borrow_after_assign_after_move(); + borrow_after_assign_after_fu_move(); borrow_after_field_assign_after_move(); + borrow_after_field_assign_after_fu_move(); + move_after_assign_after_move(); + move_after_assign_after_fu_move(); move_after_field_assign_after_move(); + move_after_field_assign_after_fu_move(); - use_after_assign_after_uninit(); + copy_after_assign_after_uninit(); borrow_after_assign_after_uninit(); move_after_assign_after_uninit(); } |
