about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBasile Desloges <basile.desloges@gmail.com>2017-10-06 17:25:41 +0200
committerBasile Desloges <basile.desloges@gmail.com>2017-10-06 17:44:50 +0200
commitce3b2e779e56b99a682086d7d9575260158f1ad1 (patch)
tree4de390536ee606ff808557279de56a40139899a8
parentf35c4e3aa168e1d5d78753ae1d12e8f25cbec699 (diff)
downloadrust-ce3b2e779e56b99a682086d7d9575260158f1ad1.tar.gz
rust-ce3b2e779e56b99a682086d7d9575260158f1ad1.zip
mir-borrowck: Implement end-user output for field of field projection
-rw-r--r--src/librustc_mir/borrow_check.rs7
-rw-r--r--src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs23
2 files changed, 25 insertions, 5 deletions
diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs
index 62e73557b25..384b1fb418c 100644
--- a/src/librustc_mir/borrow_check.rs
+++ b/src/librustc_mir/borrow_check.rs
@@ -1125,11 +1125,6 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
                 match proj.elem {
                     ProjectionElem::Deref =>
                         self.describe_field(&proj.base, field_index),
-                    ProjectionElem::Field(..) => {
-                        debug!("End-user description not implemented for field of projection {:?}",
-                               proj);
-                        format!("<field>{}", field_index)
-                    },
                     ProjectionElem::Index(..) => {
                         debug!("End-user description not implemented for field of projection {:?}",
                                proj);
@@ -1142,6 +1137,8 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
                     },
                     ProjectionElem::Downcast(def, variant_index) =>
                         format!("{}", def.variants[variant_index].fields[field_index].name),
+                    ProjectionElem::Field(_, field_type) =>
+                        self.describe_field_from_ty(&field_type, field_index),
                     ProjectionElem::Subslice { .. } => {
                         debug!("End-user description not implemented for field of projection {:?}",
                                proj);
diff --git a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
index 7ea965b07be..103aad693f7 100644
--- a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
+++ b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
@@ -253,4 +253,27 @@ fn main() {
                 println!("e.bx: {:?}", bx),
         }
     }
+    // Field in field
+    {
+        struct F { x: u32, y: u32 };
+        struct S { x: F, y: (u32, u32), };
+        let mut s = S { x: F { x: 1, y: 2}, y: (999, 998) };
+        let _s = &mut s;
+        match s {
+            S  { y: (ref y0, _), .. } =>
+                //[ast]~^ ERROR cannot borrow `s.y.0` as immutable because `s` is also borrowed as mutable
+                //[mir]~^^ ERROR cannot borrow `s.y.0` as immutable because `s` is also borrowed as mutable (Ast)
+                //[mir]~| ERROR cannot borrow `s.y.0` as immutable because it is also borrowed as mutable (Mir)
+                println!("y0: {:?}", y0),
+            _ => panic!("other case"),
+        }
+        match s {
+            S  { x: F { y: ref x0, .. }, .. } =>
+                //[ast]~^ ERROR cannot borrow `s.x.y` as immutable because `s` is also borrowed as mutable
+                //[mir]~^^ ERROR cannot borrow `s.x.y` as immutable because `s` is also borrowed as mutable (Ast)
+                //[mir]~| ERROR cannot borrow `s.x.y` as immutable because it is also borrowed as mutable (Mir)
+                println!("x0: {:?}", x0),
+            _ => panic!("other case"),
+        }
+    }
 }