Skip to content

Commit f1c87ea

Browse files
committed
Delegate via a Call instead
1 parent aac57cf commit f1c87ea

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ where
747747
) -> BasicBlock {
748748
debug!("open_drop_for_array({:?}, {:?})", element_ty, opt_size);
749749
let tcx = self.tcx();
750+
let span = self.source_info.span;
750751

751752
if let Some(0) = opt_size {
752753
span_bug!(self.source_info.span, "Opened drop for zero-length array of {element_ty:?}")
@@ -758,6 +759,9 @@ where
758759
let slice_ptr_ty = Ty::new_mut_ptr(tcx, slice_ty);
759760
let slice_ptr = self.new_temp(slice_ptr_ty);
760761

762+
let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, Some(span));
763+
let slice_drop_in_place = Operand::function_handle(tcx, drop_in_place, [slice_ty.into()], span);
764+
761765
let unsize_and_drop_block = BasicBlockData {
762766
statements: vec![
763767
self.assign(Place::from(array_ptr), Rvalue::RawPtr(Mutability::Mut, self.place)),
@@ -776,11 +780,19 @@ where
776780
is_cleanup: self.unwind.is_cleanup(),
777781
terminator: Some(Terminator {
778782
source_info: self.source_info,
779-
kind: TerminatorKind::Drop {
780-
place: Place::from(slice_ptr).project_deeper(&[PlaceElem::Deref], tcx),
781-
target: self.succ,
783+
kind: TerminatorKind::Call {
784+
func: slice_drop_in_place,
785+
args: Box::new([
786+
Spanned {
787+
node: Operand::Move(Place::from(slice_ptr)),
788+
span,
789+
}
790+
]),
791+
destination: Place::from(self.new_temp(tcx.types.unit)),
792+
target: Some(self.succ),
782793
unwind: self.unwind.into_action(),
783-
replace: false,
794+
call_source: CallSource::Misc,
795+
fn_span: span,
784796
},
785797
}),
786798
};

tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn std::ptr::drop_in_place(_1: *mut [String; 42]) -> () {
44
let mut _0: ();
55
let mut _2: *mut [std::string::String; 42];
66
let mut _3: *mut [std::string::String];
7+
let mut _4: ();
78

89
bb0: {
910
goto -> bb3;
@@ -20,6 +21,6 @@ fn std::ptr::drop_in_place(_1: *mut [String; 42]) -> () {
2021
bb3: {
2122
_2 = &raw mut (*_1);
2223
_3 = move _2 as *mut [std::string::String] (PointerCoercion(Unsize, Implicit));
23-
drop((*_3)) -> [return: bb1, unwind: bb2];
24+
_4 = std::ptr::drop_in_place::<[String]>(move _3) -> [return: bb1, unwind: bb2];
2425
}
2526
}

0 commit comments

Comments
 (0)