Skip to content

Commit ce3b2e7

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

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-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::Field(..) => {
1129-
debug!("End-user description not implemented for field of projection {:?}",
1130-
proj);
1131-
format!("<field>{}", field_index)
1132-
},
11331128
ProjectionElem::Index(..) => {
11341129
debug!("End-user description not implemented for field of projection {:?}",
11351130
proj);
@@ -1142,6 +1137,8 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11421137
},
11431138
ProjectionElem::Downcast(def, variant_index) =>
11441139
format!("{}", def.variants[variant_index].fields[field_index].name),
1140+
ProjectionElem::Field(_, field_type) =>
1141+
self.describe_field_from_ty(&field_type, field_index),
11451142
ProjectionElem::Subslice { .. } => {
11461143
debug!("End-user description not implemented for field of projection {:?}",
11471144
proj);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,27 @@ fn main() {
253253
println!("e.bx: {:?}", bx),
254254
}
255255
}
256+
// Field in field
257+
{
258+
struct F { x: u32, y: u32 };
259+
struct S { x: F, y: (u32, u32), };
260+
let mut s = S { x: F { x: 1, y: 2}, y: (999, 998) };
261+
let _s = &mut s;
262+
match s {
263+
S { y: (ref y0, _), .. } =>
264+
//[ast]~^ ERROR cannot borrow `s.y.0` as immutable because `s` is also borrowed as mutable
265+
//[mir]~^^ ERROR cannot borrow `s.y.0` as immutable because `s` is also borrowed as mutable (Ast)
266+
//[mir]~| ERROR cannot borrow `s.y.0` as immutable because it is also borrowed as mutable (Mir)
267+
println!("y0: {:?}", y0),
268+
_ => panic!("other case"),
269+
}
270+
match s {
271+
S { x: F { y: ref x0, .. }, .. } =>
272+
//[ast]~^ ERROR cannot borrow `s.x.y` as immutable because `s` is also borrowed as mutable
273+
//[mir]~^^ ERROR cannot borrow `s.x.y` as immutable because `s` is also borrowed as mutable (Ast)
274+
//[mir]~| ERROR cannot borrow `s.x.y` as immutable because it is also borrowed as mutable (Mir)
275+
println!("x0: {:?}", x0),
276+
_ => panic!("other case"),
277+
}
278+
}
256279
}

0 commit comments

Comments
 (0)