about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-03-12 13:31:00 -0400
committerEduard Burtescu <edy.burt@gmail.com>2014-03-13 14:21:46 +0200
commita7db0d5d30adbaec2b4ec6e009a0bf9c7850f9be (patch)
treef5e47a47ec83d8a8955a6fcb5c1126f9c57049da /src
parent27c62449db9e752bcab39110aaaad63b2773e68b (diff)
downloadrust-a7db0d5d30adbaec2b4ec6e009a0bf9c7850f9be.tar.gz
rust-a7db0d5d30adbaec2b4ec6e009a0bf9c7850f9be.zip
compile-fail: Beef up borrowck test to include some scenarios where we borrow mutably twice in a row
Diffstat (limited to 'src')
-rw-r--r--src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs
index 9800fd704ac..e43ac98aa98 100644
--- a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs
+++ b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs
@@ -77,6 +77,21 @@ fn deref_extend_mut_field2<'a>(x: &'a mut Own<Point>) -> &'a mut int {
     &mut x.y
 }
 
+fn deref_extend_mut_field3<'a>(x: &'a mut Own<Point>) {
+    // Hmm, this is unfortunate, because with ~ it would work,
+    // but it's presently the expected outcome. See `deref_extend_mut_field4`
+    // for the workaround.
+
+    let _x = &mut x.x;
+    let _y = &mut x.y; //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
+    let p = &mut **x;
+    let _x = &mut p.x;
+    let _y = &mut p.y;
+}
+
 fn assign_field1<'a>(x: Own<Point>) {
     x.y = 3; //~ ERROR cannot borrow
 }
@@ -89,6 +104,11 @@ fn assign_field3<'a>(x: &'a mut Own<Point>) {
     x.y = 3;
 }
 
+fn assign_field4<'a>(x: &'a mut Own<Point>) {
+    let _p: &mut Point = &mut **x;
+    x.y = 3; //~ ERROR cannot borrow
+}
+
 // FIXME(eddyb) #12825 This shouldn't attempt to call deref_mut.
 /*
 fn deref_imm_method(x: Own<Point>) {
@@ -128,4 +148,4 @@ fn assign_method3<'a>(x: &'a mut Own<Point>) {
     *x.y_mut() = 3;
 }
 
-pub fn main() {}
\ No newline at end of file
+pub fn main() {}