Skip to content

Commit

Permalink
Delegate via a Call instead
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Dec 15, 2024
1 parent aac57cf commit a5f9505
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions compiler/rustc_mir_dataflow/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")
Expand All @@ -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)),
Expand All @@ -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,
},
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
}
}

0 comments on commit a5f9505

Please sign in to comment.