diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-03-30 11:47:27 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-03-30 14:10:46 +0200 |
| commit | e4340531c2af4b39b5ee7c111fae4f6f27ac8bf7 (patch) | |
| tree | a321a1a48da27fb6466672ea20011e30c1691825 /src | |
| parent | f513380cf51eb5fd977b8815a7acd999e424dc93 (diff) | |
| download | rust-e4340531c2af4b39b5ee7c111fae4f6f27ac8bf7.tar.gz rust-e4340531c2af4b39b5ee7c111fae4f6f27ac8bf7.zip | |
Fallout to test.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/compile-fail/borrowck-issue-14498.rs | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/src/test/compile-fail/borrowck-issue-14498.rs b/src/test/compile-fail/borrowck-issue-14498.rs index 8278b4fb971..64033623fe2 100644 --- a/src/test/compile-fail/borrowck-issue-14498.rs +++ b/src/test/compile-fail/borrowck-issue-14498.rs @@ -9,56 +9,116 @@ // except according to those terms. // This tests that we can't modify Box<&mut T> contents while they -// are borrowed. +// are borrowed (#14498). +// +// Also includes tests of the errors reported when the Box in question +// is immutable (#14270). #![feature(box_syntax)] struct A { a: isize } struct B<'a> { a: Box<&'a mut isize> } +fn indirect_write_to_imm_box() { + let mut x: isize = 1; + let y: Box<_> = box &mut x; + let p = &y; + ***p = 2; //~ ERROR cannot assign to data in an immutable container + drop(p); +} + fn borrow_in_var_from_var() { let mut x: isize = 1; + let mut y: Box<_> = box &mut x; + let p = &y; + let q = &***p; + **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed + drop(p); + drop(q); +} + +fn borrow_in_var_from_var_via_imm_box() { + let mut x: isize = 1; let y: Box<_> = box &mut x; let p = &y; let q = &***p; **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed + //~^ ERROR cannot assign to data in an immutable container drop(p); drop(q); } fn borrow_in_var_from_field() { let mut x = A { a: 1 }; + let mut y: Box<_> = box &mut x.a; + let p = &y; + let q = &***p; + **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed + drop(p); + drop(q); +} + +fn borrow_in_var_from_field_via_imm_box() { + let mut x = A { a: 1 }; let y: Box<_> = box &mut x.a; let p = &y; let q = &***p; **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed + //~^ ERROR cannot assign to data in an immutable container drop(p); drop(q); } fn borrow_in_field_from_var() { let mut x: isize = 1; + let mut y = B { a: box &mut x }; + let p = &y.a; + let q = &***p; + **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed + drop(p); + drop(q); +} + +fn borrow_in_field_from_var_via_imm_box() { + let mut x: isize = 1; let y = B { a: box &mut x }; let p = &y.a; let q = &***p; **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed + //~^ ERROR cannot assign to data in an immutable container drop(p); drop(q); } fn borrow_in_field_from_field() { let mut x = A { a: 1 }; + let mut y = B { a: box &mut x.a }; + let p = &y.a; + let q = &***p; + **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed + drop(p); + drop(q); +} + +fn borrow_in_field_from_field_via_imm_box() { + let mut x = A { a: 1 }; let y = B { a: box &mut x.a }; let p = &y.a; let q = &***p; **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed + //~^ ERROR cannot assign to data in an immutable container drop(p); drop(q); } fn main() { + indirect_write_to_imm_box(); borrow_in_var_from_var(); + borrow_in_var_from_var_via_imm_box(); borrow_in_var_from_field(); + borrow_in_var_from_field_via_imm_box(); borrow_in_field_from_var(); + borrow_in_field_from_var_via_imm_box(); borrow_in_field_from_field(); + borrow_in_field_from_field_via_imm_box(); } |
