mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 14:10:03 +03:00
Handle trait objects. Only very superficial checking of the vtable for now. (88)
This commit is contained in:
committed by
Oliver Schneider
parent
e5c6637d87
commit
769a2b5c81
@@ -71,7 +71,7 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx:
|
||||
TyBool | TyFloat(_) | TyChar | TyStr |
|
||||
TyRef(..) | TyFnPtr(..) | TyNever => true,
|
||||
TyAdt(adt, _) if adt.is_box() => true,
|
||||
TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) => false,
|
||||
TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) | TyDynamic(..) => false,
|
||||
TyParam(_) | TyInfer(_) => bug!("I got an incomplete type for validation"),
|
||||
_ => return Err(EvalError::Unimplemented(format!("Unimplemented type encountered when checking validity."))),
|
||||
};
|
||||
@@ -178,6 +178,20 @@ pub(super) fn validate(&mut self, lvalue: Lvalue<'tcx>, ty: Ty<'tcx>, mut vctx:
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
TyDynamic(_data, _region) => {
|
||||
// Check that this is a valid vtable
|
||||
let vtable = match lvalue {
|
||||
Lvalue::Ptr { extra: LvalueExtra::Vtable(vtable), .. } => vtable,
|
||||
_ => bug!("acquire_valid of a TyDynamic given non-trait-object lvalue: {:?}", lvalue),
|
||||
};
|
||||
self.read_size_and_align_from_vtable(vtable)?;
|
||||
// TODO: Check that the vtable contains all the function pointers we expect it to have.
|
||||
// TODO: Is there anything we can/should validate here? Trait objects cannot have any operations performed
|
||||
// on them directly. We cannot, in general, even acquire any locks as the trait object *could*
|
||||
// contain an UnsafeCell. If we call functions to get access to data, we will validate
|
||||
// their return values. So, it doesn't seem like there's anything to do.
|
||||
Ok(())
|
||||
}
|
||||
TyAdt(adt, subst) => {
|
||||
if Some(adt.did) == self.tcx.lang_items.unsafe_cell_type() {
|
||||
// No locks for unsafe cells. Also no other validation, the only field is private anyway.
|
||||
|
||||
Reference in New Issue
Block a user