diff options
| author | Basile Desloges <basile.desloges@gmail.com> | 2017-10-06 17:24:23 +0200 |
|---|---|---|
| committer | Basile Desloges <basile.desloges@gmail.com> | 2017-10-06 17:44:50 +0200 |
| commit | f35c4e3aa168e1d5d78753ae1d12e8f25cbec699 (patch) | |
| tree | 4e58c1f912fe00569fd6b6852972159800fa6fef | |
| parent | 0241ea45b2e71e53921627bc09219653f2629c0e (diff) | |
| download | rust-f35c4e3aa168e1d5d78753ae1d12e8f25cbec699.tar.gz rust-f35c4e3aa168e1d5d78753ae1d12e8f25cbec699.zip | |
mir-borrowck: Implement end-user output for field of downcast projection
| -rw-r--r-- | src/librustc_mir/borrow_check.rs | 7 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs | 20 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs index d57bac7c85a..62e73557b25 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::Downcast(..) => { - debug!("End-user description not implemented for field of projection {:?}", - proj); - format!("<downcast>{}", field_index) - }, ProjectionElem::Field(..) => { debug!("End-user description not implemented for field of projection {:?}", proj); @@ -1145,6 +1140,8 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> proj); format!("<constant_index>{}", field_index) }, + ProjectionElem::Downcast(def, variant_index) => + format!("{}", def.variants[variant_index].fields[field_index].name), 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 088b678efb5..7ea965b07be 100644 --- a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs +++ b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs @@ -233,4 +233,24 @@ fn main() { _ => panic!("other case"), } } + // Downcasted field + { + enum E<X> { A(X), B { x: X } } + + let mut e = E::A(3); + let _e = &mut e; + match e { + E::A(ref ax) => + //[ast]~^ ERROR cannot borrow `e.0` as immutable because `e` is also borrowed as mutable + //[mir]~^^ ERROR cannot borrow `e.0` as immutable because `e` is also borrowed as mutable (Ast) + //[mir]~| ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable (Mir) + //[mir]~| ERROR cannot use `e` because it was mutably borrowed (Mir) + println!("e.ax: {:?}", ax), + E::B { x: ref bx } => + //[ast]~^ ERROR cannot borrow `e.x` as immutable because `e` is also borrowed as mutable + //[mir]~^^ ERROR cannot borrow `e.x` as immutable because `e` is also borrowed as mutable (Ast) + //[mir]~| ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable (Mir) + println!("e.bx: {:?}", bx), + } + } } |
