Skip to content

Commit f35c4e3

Browse files
committed
mir-borrowck: Implement end-user output for field of downcast projection
1 parent 0241ea4 commit f35c4e3

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/librustc_mir/borrow_check.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,6 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11251125
match proj.elem {
11261126
ProjectionElem::Deref =>
11271127
self.describe_field(&proj.base, field_index),
1128-
ProjectionElem::Downcast(..) => {
1129-
debug!("End-user description not implemented for field of projection {:?}",
1130-
proj);
1131-
format!("<downcast>{}", field_index)
1132-
},
11331128
ProjectionElem::Field(..) => {
11341129
debug!("End-user description not implemented for field of projection {:?}",
11351130
proj);
@@ -1145,6 +1140,8 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11451140
proj);
11461141
format!("<constant_index>{}", field_index)
11471142
},
1143+
ProjectionElem::Downcast(def, variant_index) =>
1144+
format!("{}", def.variants[variant_index].fields[field_index].name),
11481145
ProjectionElem::Subslice { .. } => {
11491146
debug!("End-user description not implemented for field of projection {:?}",
11501147
proj);

src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,24 @@ fn main() {
233233
_ => panic!("other case"),
234234
}
235235
}
236+
// Downcasted field
237+
{
238+
enum E<X> { A(X), B { x: X } }
239+
240+
let mut e = E::A(3);
241+
let _e = &mut e;
242+
match e {
243+
E::A(ref ax) =>
244+
//[ast]~^ ERROR cannot borrow `e.0` as immutable because `e` is also borrowed as mutable
245+
//[mir]~^^ ERROR cannot borrow `e.0` as immutable because `e` is also borrowed as mutable (Ast)
246+
//[mir]~| ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable (Mir)
247+
//[mir]~| ERROR cannot use `e` because it was mutably borrowed (Mir)
248+
println!("e.ax: {:?}", ax),
249+
E::B { x: ref bx } =>
250+
//[ast]~^ ERROR cannot borrow `e.x` as immutable because `e` is also borrowed as mutable
251+
//[mir]~^^ ERROR cannot borrow `e.x` as immutable because `e` is also borrowed as mutable (Ast)
252+
//[mir]~| ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable (Mir)
253+
println!("e.bx: {:?}", bx),
254+
}
255+
}
236256
}

0 commit comments

Comments
 (0)