@@ -16,11 +16,9 @@ use rustc_target::spec::abi::Abi;
16
16
17
17
use rustc:: mir:: interpret:: { EvalResult , Scalar } ;
18
18
use super :: {
19
- EvalContext , Machine , Value , OpTy , Place , PlaceTy , ValTy , Operand , StackPopCleanup
19
+ EvalContext , Machine , Value , OpTy , Place , PlaceTy , PlaceExtra , ValTy , Operand , StackPopCleanup
20
20
} ;
21
21
22
- mod drop;
23
-
24
22
impl < ' a , ' mir , ' tcx , M : Machine < ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
25
23
#[ inline]
26
24
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> {
442
440
}
443
441
}
444
442
}
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
+ }
445
488
}
0 commit comments