mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-07 12:48:30 +00:00
mir-borrowck: Implement end-user output for field of reference, pointer and array
This commit is contained in:
parent
9ce2f3af93
commit
ca5dc86c5a
@ -1160,11 +1160,16 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
|
|||||||
ty::TyTuple(_, _) => {
|
ty::TyTuple(_, _) => {
|
||||||
format!("{}", field_index)
|
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
|
// Might need a revision when the fields in trait RFC is implemented
|
||||||
// (https://github.com/rust-lang/rfcs/pull/1546)
|
// (https://github.com/rust-lang/rfcs/pull/1546)
|
||||||
bug!("Field access unsupported for non-box types that are neither Adt (struct, \
|
bug!("End-user description not implemented for field access on `{:?}`", ty.sty);
|
||||||
enum, union) nor tuples");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,34 @@ fn main() {
|
|||||||
_ => panic!("other case"),
|
_ => 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
|
// Field of index
|
||||||
{
|
{
|
||||||
struct F {x: u32, y: u32};
|
struct F {x: u32, y: u32};
|
||||||
|
Loading…
Reference in New Issue
Block a user