1 use rustc::mir::BasicBlock;
2 use rustc::ty::{self, Ty};
3 use syntax::codemap::Span;
5 use rustc::mir::interpret::{EvalResult, Scalar, Value};
6 use interpret::{Machine, ValTy, EvalContext, Place, PlaceExtra};
8 impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
9 pub(crate) fn drop_place(
12 instance: ty::Instance<'tcx>,
16 ) -> EvalResult<'tcx> {
17 trace!("drop_place: {:#?}", place);
18 // We take the address of the object. This may well be unaligned, which is fine for us here.
19 // However, unaligned accesses will probably make the actual drop implementation fail -- a problem shared
21 let val = match self.force_allocation(place)? {
25 extra: PlaceExtra::Vtable(vtable),
26 } => ptr.to_value_with_vtable(vtable),
30 extra: PlaceExtra::Length(len),
31 } => ptr.to_value_with_len(len, self.tcx.tcx),
35 extra: PlaceExtra::None,
37 _ => bug!("force_allocation broken"),
39 self.drop(val, instance, ty, span, target)
45 instance: ty::Instance<'tcx>,
49 ) -> EvalResult<'tcx> {
50 trace!("drop: {:#?}, {:?}, {:?}", arg, ty.sty, instance.def);
52 let instance = match ty.sty {
53 ty::TyDynamic(..) => {
54 let vtable = match arg {
55 Value::ScalarPair(_, Scalar::Ptr(vtable)) => vtable,
56 _ => bug!("expected fat ptr, got {:?}", arg),
58 match self.read_drop_type_from_vtable(vtable)? {
60 // no drop fn -> bail out
62 self.goto_block(target);
70 // the drop function expects a reference to the value
73 ty: self.tcx.mk_mut_ptr(ty),
76 let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone();
80 Some((Place::undef(), target)),