diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 17a81f309898a..c79e4922668ac 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -747,6 +747,7 @@ where ) -> BasicBlock { debug!("open_drop_for_array({:?}, {:?})", element_ty, opt_size); let tcx = self.tcx(); + let span = self.source_info.span; if let Some(0) = opt_size { span_bug!(self.source_info.span, "Opened drop for zero-length array of {element_ty:?}") @@ -758,6 +759,10 @@ where let slice_ptr_ty = Ty::new_mut_ptr(tcx, slice_ty); let slice_ptr = self.new_temp(slice_ptr_ty); + let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, Some(span)); + let slice_drop_in_place = + Operand::function_handle(tcx, drop_in_place, [slice_ty.into()], span); + let unsize_and_drop_block = BasicBlockData { statements: vec![ self.assign(Place::from(array_ptr), Rvalue::RawPtr(Mutability::Mut, self.place)), @@ -776,11 +781,14 @@ where is_cleanup: self.unwind.is_cleanup(), terminator: Some(Terminator { source_info: self.source_info, - kind: TerminatorKind::Drop { - place: Place::from(slice_ptr).project_deeper(&[PlaceElem::Deref], tcx), - target: self.succ, + kind: TerminatorKind::Call { + func: slice_drop_in_place, + args: Box::new([Spanned { node: Operand::Move(Place::from(slice_ptr)), span }]), + destination: Place::from(self.new_temp(tcx.types.unit)), + target: Some(self.succ), unwind: self.unwind.into_action(), - replace: false, + call_source: CallSource::Misc, + fn_span: span, }, }), }; diff --git a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir index 84b4c12fdec2b..26f93b08578a7 100644 --- a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir @@ -4,6 +4,7 @@ fn std::ptr::drop_in_place(_1: *mut [String; 42]) -> () { let mut _0: (); let mut _2: *mut [std::string::String; 42]; let mut _3: *mut [std::string::String]; + let mut _4: (); bb0: { goto -> bb3; @@ -20,6 +21,6 @@ fn std::ptr::drop_in_place(_1: *mut [String; 42]) -> () { bb3: { _2 = &raw mut (*_1); _3 = move _2 as *mut [std::string::String] (PointerCoercion(Unsize, Implicit)); - drop((*_3)) -> [return: bb1, unwind: bb2]; + _4 = std::ptr::drop_in_place::<[String]>(move _3) -> [return: bb1, unwind: bb2]; } }