about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBasile Desloges <basile.desloges@gmail.com>2017-10-06 17:26:53 +0200
committerBasile Desloges <basile.desloges@gmail.com>2017-10-06 17:44:50 +0200
commitca5dc86c5a2e92f35c94e7a1f4592bb7fd0b271c (patch)
tree3120ddc533b0245d62b61d21cc2781796b9a134f
parent9ce2f3af9379246909d3e0151b956ad428bbc175 (diff)
downloadrust-ca5dc86c5a2e92f35c94e7a1f4592bb7fd0b271c.tar.gz
rust-ca5dc86c5a2e92f35c94e7a1f4592bb7fd0b271c.zip
mir-borrowck: Implement end-user output for field of reference, pointer and array
-rw-r--r--src/librustc_mir/borrow_check.rs9
-rw-r--r--src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs28
2 files changed, 35 insertions, 2 deletions
diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs
index 0d9dbfab1e8..eb05a815c73 100644
--- a/src/librustc_mir/borrow_check.rs
+++ b/src/librustc_mir/borrow_check.rs
@@ -1160,11 +1160,16 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
                 ty::TyTuple(_, _) => {
                     format!("{}", field_index)
                 },
+                ty::TyRef(_, tnm) | ty::TyRawPtr(tnm) => {
+                    self.describe_field_from_ty(&tnm.ty, field_index)
+                },
+                ty::TyArray(ty, _) => {
+                    self.describe_field_from_ty(&ty, field_index)
+                }
                 _ => {
                     // Might need a revision when the fields in trait RFC is implemented
                     // (https://github.com/rust-lang/rfcs/pull/1546)
-                    bug!("Field access unsupported for non-box types that are neither Adt (struct, \
-                         enum, union) nor tuples");
+                    bug!("End-user description not implemented for field access on `{:?}`", ty.sty);
                 }
             }
         }
diff --git a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
index 7ead9032c13..cff913b17be 100644
--- a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
+++ b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs
@@ -276,6 +276,34 @@ fn main() {
             _ => panic!("other case"),
         }
     }
+    // Field of ref
+    {
+        struct Block<'a> {
+            current: &'a u8,
+            unrelated: &'a u8,
+        };
+
+        fn bump<'a>(mut block: &mut Block<'a>) {
+            let x = &mut block;
+            let p: &'a u8 = &*block.current;
+            //[mir]~^ ERROR cannot borrow `(*block.current)` as immutable because it is also borrowed as mutable (Mir)
+            // No errors in AST because of issue rust#38899
+        }
+    }
+    // Field of ptr
+    {
+        struct Block2 {
+            current: *const u8,
+            unrelated: *const u8,
+        }
+
+        unsafe fn bump2(mut block: *mut Block2) {
+            let x = &mut block;
+            let p : *const u8 = &*(*block).current;
+            //[mir]~^ ERROR cannot borrow `(*block.current)` as immutable because it is also borrowed as mutable (Mir)
+            // No errors in AST because of issue rust#38899
+        }
+    }
     // Field of index
     {
         struct F {x: u32, y: u32};