]> git.lizzy.rs Git - rust.git/commitdiff
mir-borrowck: Implement end-user output for field of field projection
authorBasile Desloges <basile.desloges@gmail.com>
Fri, 6 Oct 2017 15:25:41 +0000 (17:25 +0200)
committerBasile Desloges <basile.desloges@gmail.com>
Fri, 6 Oct 2017 15:44:50 +0000 (17:44 +0200)
src/librustc_mir/borrow_check.rs
src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs

index 62e73557b2577a41eafee1425f1bd7aec3a465b9..384b1fb418cfd1bccd2d1bbb3cbae043897c7c74 100644 (file)
@@ -1125,11 +1125,6 @@ fn describe_field(&self, base: &Lvalue, field_index: usize) -> String {
                 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 @@ fn describe_field(&self, base: &Lvalue, field_index: usize) -> String {
                     },
                     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);
index 7ea965b07be4be624dbbd45de9158d4dcda1d8d1..103aad693f78279a01f37635dbd7bdacfa99ddb9 100644 (file)
@@ -253,4 +253,27 @@ enum E<X> { A(X), B { x: X } }
                 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"),
+        }
+    }
 }