Skip to content

Commit 0c2975b

Browse files
committed
terminator/drop.rs is just one fn... merge it together with the other terminator stuff
1 parent 80b9fc9 commit 0c2975b

File tree

2 files changed

+46
-66
lines changed

2 files changed

+46
-66
lines changed

src/librustc_mir/interpret/terminator/mod.rs renamed to src/librustc_mir/interpret/terminator.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ use rustc_target::spec::abi::Abi;
1616

1717
use rustc::mir::interpret::{EvalResult, Scalar};
1818
use super::{
19-
EvalContext, Machine, Value, OpTy, Place, PlaceTy, ValTy, Operand, StackPopCleanup
19+
EvalContext, Machine, Value, OpTy, Place, PlaceTy, PlaceExtra, ValTy, Operand, StackPopCleanup
2020
};
2121

22-
mod drop;
23-
2422
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
2523
#[inline]
2624
pub fn goto_block(&mut self, target: Option<mir::BasicBlock>) -> EvalResult<'tcx> {
@@ -442,4 +440,49 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
442440
}
443441
}
444442
}
443+
444+
fn drop_in_place(
445+
&mut self,
446+
place: PlaceTy<'tcx>,
447+
instance: ty::Instance<'tcx>,
448+
span: Span,
449+
target: mir::BasicBlock,
450+
) -> EvalResult<'tcx> {
451+
trace!("drop_in_place: {:?},\n {:?}, {:?}", *place, place.layout.ty, instance);
452+
// We take the address of the object. This may well be unaligned, which is fine
453+
// for us here. However, unaligned accesses will probably make the actual drop
454+
// implementation fail -- a problem shared by rustc.
455+
let place = self.force_allocation(place)?;
456+
457+
let (instance, place) = match place.layout.ty.sty {
458+
ty::Dynamic(..) => {
459+
// Dropping a trait object.
460+
let vtable = match place.extra {
461+
PlaceExtra::Vtable(vtable) => vtable,
462+
_ => bug!("Expected vtable when dropping {:#?}", place),
463+
};
464+
let place = self.unpack_unsized_mplace(place)?;
465+
let instance = self.read_drop_type_from_vtable(vtable)?;
466+
(instance, place)
467+
}
468+
_ => (instance, place),
469+
};
470+
471+
let arg = OpTy {
472+
op: Operand::Immediate(place.to_ref(&self)),
473+
layout: self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?,
474+
};
475+
476+
let ty = self.tcx.mk_tup((&[] as &[ty::Ty<'tcx>]).iter()); // return type is ()
477+
let dest = PlaceTy::null(&self, self.layout_of(ty)?);
478+
479+
self.eval_fn_call(
480+
instance,
481+
&[arg],
482+
Some(dest),
483+
Some(target),
484+
span,
485+
None,
486+
)
487+
}
445488
}

src/librustc_mir/interpret/terminator/drop.rs

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)