mir-borrowck: Implement end-user output for field of field projection
This commit is contained in:
parent
f35c4e3aa1
commit
ce3b2e779e
2 changed files with 25 additions and 5 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue