mir-borrowck: Implement end-user output for field of reference, pointer and array

This commit is contained in:
Basile Desloges 2017-10-06 17:26:53 +02:00
parent 9ce2f3af93
commit ca5dc86c5a
2 changed files with 35 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -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};