From 45a31f243602ae3ce3cdf66f41b1ad8770b47a18 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Tue, 24 Mar 2026 16:18:31 +0100 Subject: [PATCH 01/10] change type argument of `drop_in_place` lang item to `&mut _` --- .../rustc_const_eval/src/interpret/call.rs | 5 ++- .../rustc_mir_transform/src/coroutine/drop.rs | 4 -- compiler/rustc_ty_utils/src/abi.rs | 44 ++----------------- library/core/src/future/async_drop.rs | 1 + library/core/src/ptr/mod.rs | 23 +++++++--- 5 files changed, 26 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index d948b78a0bcf9..534cba7aa66a1 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -891,6 +891,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { place } }; + let instance = { let _trace = enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty); @@ -898,7 +899,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { }; let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?; - let arg = self.mplace_to_imm_ptr(&place, None)?; + let ref_ty = Ty::new_mut_ref(self.tcx.tcx, self.tcx.lifetimes.re_erased, place.layout.ty); + let arg = self.mplace_to_imm_ptr(&place, Some(ref_ty))?; + let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?); self.init_fn_call( diff --git a/compiler/rustc_mir_transform/src/coroutine/drop.rs b/compiler/rustc_mir_transform/src/coroutine/drop.rs index 2699a051a8fea..718d75e875b28 100644 --- a/compiler/rustc_mir_transform/src/coroutine/drop.rs +++ b/compiler/rustc_mir_transform/src/coroutine/drop.rs @@ -596,10 +596,6 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( make_coroutine_state_argument_indirect(tcx, &mut body); - // Change the coroutine argument from &mut to *mut - body.local_decls[SELF_ARG] = - LocalDecl::with_source_info(Ty::new_mut_ptr(tcx, coroutine_ty), source_info); - // Make sure we remove dead blocks to remove // unrelated code from the resume part of the function simplify::remove_dead_blocks(&mut body); diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 5008794bcb191..429209d85f854 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -340,21 +340,12 @@ fn fn_abi_of_instance_raw<'tcx>( } /// Returns argument attributes for a scalar argument. -/// -/// `drop_target_pointee`, if set, causes pointer-typed scalars to be treated like mutable -/// references to the given type. This is used to special-case the argument of `ptr::drop_in_place`, -/// interpreting it as `&mut T` instead of `*mut T`, for the purposes of attributes (which is valid -/// as per its safety contract). If `drop_target_pointee` is set, `offset` must be 0 and `layout.ty` -/// must be a pointer to the given type. Note that for wide pointers this function is called twice -/// -- once for the data pointer and once for the vtable pointer. `drop_target_pointee` must only -/// be set for the data pointer. fn arg_attrs_for_rust_scalar<'tcx>( cx: LayoutCx<'tcx>, scalar: Scalar, layout: TyAndLayout<'tcx>, offset: Size, is_return: bool, - drop_target_pointee: Option>, ) -> ArgAttributes { let mut attrs = ArgAttributes::new(); @@ -374,23 +365,13 @@ fn arg_attrs_for_rust_scalar<'tcx>( // Set `nonnull` if the validity range excludes zero, or for the argument to `drop_in_place`, // which must be nonnull per its documented safety requirements. - if !valid_range.contains(0) || drop_target_pointee.is_some() { + if !valid_range.contains(0) { attrs.set(ArgAttribute::NonNull); } let tcx = cx.tcx(); - let drop_target_pointee_info = drop_target_pointee.and_then(|pointee| { - assert_eq!(pointee, layout.ty.builtin_deref(true).unwrap()); - assert_eq!(offset, Size::ZERO); - // The argument to `drop_in_place` is semantically equivalent to a mutable reference. - let mutref = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, pointee); - let layout = cx.layout_of(mutref).unwrap(); - layout.pointee_info_at(&cx, offset) - }); - - if let Some(pointee) = drop_target_pointee_info.or_else(|| layout.pointee_info_at(&cx, offset)) - { + if let Some(pointee) = layout.pointee_info_at(&cx, offset) { if pointee.align > Align::ONE { attrs.pointee_align = Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment())); @@ -589,20 +570,10 @@ fn fn_abi_new_uncached<'tcx>( extra_args }; - let is_drop_in_place = determined_fn_def_id.is_some_and(|def_id| { - tcx.is_lang_item(def_id, LangItem::DropInPlace) - || tcx.is_lang_item(def_id, LangItem::AsyncDropInPlace) - }); - let arg_of = |ty: Ty<'tcx>, arg_idx: Option| -> Result<_, &'tcx FnAbiError<'tcx>> { let span = tracing::debug_span!("arg_of"); let _entered = span.enter(); let is_return = arg_idx.is_none(); - let is_drop_target = is_drop_in_place && arg_idx == Some(0); - let drop_target_pointee = is_drop_target.then(|| match ty.kind() { - ty::RawPtr(ty, _) => *ty, - _ => bug!("argument to drop_in_place is not a raw ptr: {:?}", ty), - }); let layout = cx.layout_of(ty).map_err(|err| &*tcx.arena.alloc(FnAbiError::Layout(*err)))?; let layout = if is_virtual_call && arg_idx == Some(0) { @@ -615,16 +586,7 @@ fn fn_abi_new_uncached<'tcx>( }; Ok(ArgAbi::new(cx, layout, |scalar, offset| { - arg_attrs_for_rust_scalar( - *cx, - scalar, - layout, - offset, - is_return, - // Only set `drop_target_pointee` for the data part of a wide pointer. - // See `arg_attrs_for_rust_scalar` docs for more information. - drop_target_pointee.filter(|_| offset == Size::ZERO), - ) + arg_attrs_for_rust_scalar(*cx, scalar, layout, offset, is_return) })) }; diff --git a/library/core/src/future/async_drop.rs b/library/core/src/future/async_drop.rs index 106493fd3e815..c11ef1569d01e 100644 --- a/library/core/src/future/async_drop.rs +++ b/library/core/src/future/async_drop.rs @@ -52,6 +52,7 @@ pub trait AsyncDrop { /// [ptr::drop_in_place]: crate::ptr::drop_in_place() #[unstable(feature = "async_drop", issue = "126482")] #[lang = "async_drop_in_place"] +// FIXME: accept a reference here instead pub async unsafe fn async_drop_in_place(_to_drop: *mut T) { // Code here does not matter - this is replaced by the // real implementation by the compiler. diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index ddeb1ccc72af7..b9e93dc89b5f8 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -802,20 +802,33 @@ pub const unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { /// // Ensure that the last item was dropped. /// assert!(weak.upgrade().is_none()); /// ``` +#[inline(always)] #[stable(feature = "drop_in_place", since = "1.8.0")] -#[lang = "drop_in_place"] -#[allow(unconditional_recursion)] #[rustc_diagnostic_item = "ptr_drop_in_place"] #[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")] pub const unsafe fn drop_in_place(to_drop: *mut T) +where + T: [const] Destruct, +{ + // Due to historic reasons, `drop_in_place` takes a pointer rather than a reference, + // which results in worse codegen since we don't apply noalias/dereferenceable llvm + // attributes to pointer arguments. To workaround this without breaking public + // interface, `drop_in_place` calls the lang item, rather than being one directly. + + // SAFETY: + // - compiler glue has the same safety requirements as this function + // - the pointer must be valid as per the safety requirement of this function + unsafe { drop_glue(&mut *to_drop) } +} + +/// Helper function for `drop_in_place`. +#[lang = "drop_in_place"] +const unsafe fn drop_glue(_: &mut T) where T: [const] Destruct, { // Code here does not matter - this is replaced by the // real drop glue by the compiler. - - // SAFETY: see comment above - unsafe { drop_in_place(to_drop) } } /// Creates a null raw pointer. From 2be11ffe760ef2e7e77c4897f4500b98bfe14d58 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Tue, 24 Mar 2026 16:18:31 +0100 Subject: [PATCH 02/10] bless miri/codegen-llvm/ui tests --- .../libc_pthread_mutex_free_while_queued.stderr | 2 +- src/tools/miri/tests/fail/alloc/stack_free.stderr | 2 +- .../both_borrows/newtype_pair_retagging.tree.stderr | 2 +- .../fail/both_borrows/newtype_retagging.tree.stderr | 2 +- .../deallocate_against_protector1.stderr | 2 +- .../stacked_borrows/drop_in_place_protector.stderr | 8 +++++--- .../fail/stacked_borrows/drop_in_place_retag.stderr | 8 +++----- .../fail/tree_borrows/strongly-protected.stderr | 2 +- .../wildcard/strongly_protected_wildcard.stderr | 2 +- .../fail/unaligned_pointers/drop_in_place.stderr | 8 +++----- .../miri/tests/pass/alloc-access-tracking.stderr | 2 +- tests/codegen-llvm/drop.rs | 6 +++--- tests/codegen-llvm/inline-hint.rs | 2 +- ...type-metadata-id-itanium-cxx-abi-drop-in-place.rs | 10 +++++----- tests/codegen-llvm/unwind-landingpad-cold.rs | 2 +- tests/codegen-llvm/vec-into-iter-drops.rs | 3 ++- tests/ui/consts/const-eval/c-variadic-fail.stderr | 6 +++--- tests/ui/consts/miri_unleashed/assoc_const.stderr | 4 ++-- tests/ui/consts/miri_unleashed/drop.rs | 7 ++++--- tests/ui/consts/miri_unleashed/drop.stderr | 2 +- tests/ui/consts/qualif-indirect-mutation-fail.stderr | 12 ++++++------ 21 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.stderr b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.stderr index 96be3f5764a3b..b120a447d8b7e 100644 --- a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.stderr +++ b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_free_while_queued.stderr @@ -10,7 +10,7 @@ LL | self.1.deallocate(From::from(ptr.cast()), layout); = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/alloc/stack_free.stderr b/src/tools/miri/tests/fail/alloc/stack_free.stderr index deb42c0986794..043c4a680f277 100644 --- a/src/tools/miri/tests/fail/alloc/stack_free.stderr +++ b/src/tools/miri/tests/fail/alloc/stack_free.stderr @@ -9,7 +9,7 @@ LL | self.1.deallocate(From::from(ptr.cast()), layout); = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr index 68b9d1c86d1a8..e84fa4281d13b 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.tree.stderr @@ -28,7 +28,7 @@ LL | || drop(Box::from_raw(ptr)), = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr index 5069b1d01cd2b..1151a44410cc3 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.tree.stderr @@ -28,7 +28,7 @@ LL | || drop(Box::from_raw(ptr)), = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr b/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr index 266f9247b98d7..1d9bfe5440685 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/deallocate_against_protector1.stderr @@ -9,7 +9,7 @@ LL | self.1.deallocate(From::from(ptr.cast()), layout); = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.stderr b/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.stderr index 027fe239319a3..4c6829427d8a8 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_protector.stderr @@ -19,11 +19,13 @@ LL | core::ptr::drop_in_place(x); = note: stack backtrace: 0: ::drop at tests/fail/stacked_borrows/drop_in_place_protector.rs:LL:CC - 1: std::ptr::drop_in_place - shim(Some(HasDrop)) + 1: std::ptr::drop_glue - shim(Some(HasDrop)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC - 2: std::ptr::drop_in_place - shim(Some((HasDrop, u8))) + 2: std::ptr::drop_glue - shim(Some((HasDrop, u8))) at RUSTLIB/core/src/ptr/mod.rs:LL:CC - 3: main + 3: std::ptr::drop_in_place + at RUSTLIB/core/src/ptr/mod.rs:LL:CC + 4: main at tests/fail/stacked_borrows/drop_in_place_protector.rs:LL:CC = note: this error originates in the macro `core::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.stderr b/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.stderr index cffa175569506..96e31615c20ed 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/drop_in_place_retag.stderr @@ -1,10 +1,8 @@ error: Undefined Behavior: trying to retag from for Unique permission at ALLOC[0x0], but that tag only grants SharedReadOnly permission for this location --> RUSTLIB/core/src/ptr/mod.rs:LL:CC | -LL | / pub const unsafe fn drop_in_place(to_drop: *mut T) -LL | | where -LL | | T: [const] Destruct, - | |________________________^ this error occurs as part of retag at ALLOC[0x0..0x1] +LL | unsafe { drop_glue(&mut *to_drop) } + | ^^^^^^^^^^^^^ this error occurs as part of retag at ALLOC[0x0..0x1] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -14,7 +12,7 @@ help: was created by a SharedReadOnly retag at offsets [0x0..0x1] LL | let x = core::ptr::addr_of!(x); | ^^^^^^^^^^^^^^^^^^^^^^ = note: stack backtrace: - 0: std::ptr::drop_in_place - shim(None) + 0: std::ptr::drop_in_place at RUSTLIB/core/src/ptr/mod.rs:LL:CC 1: main at tests/fail/stacked_borrows/drop_in_place_retag.rs:LL:CC diff --git a/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr b/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr index 4abaeb66e5272..d2a11659460ef 100644 --- a/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr +++ b/src/tools/miri/tests/fail/tree_borrows/strongly-protected.stderr @@ -21,7 +21,7 @@ LL | fn inner(x: &mut i32, f: fn(*mut i32)) { = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/tree_borrows/wildcard/strongly_protected_wildcard.stderr b/src/tools/miri/tests/fail/tree_borrows/wildcard/strongly_protected_wildcard.stderr index 89d1f8ca556d4..c192c2d00d088 100644 --- a/src/tools/miri/tests/fail/tree_borrows/wildcard/strongly_protected_wildcard.stderr +++ b/src/tools/miri/tests/fail/tree_borrows/wildcard/strongly_protected_wildcard.stderr @@ -21,7 +21,7 @@ LL | fn inner(x: &mut i32, f: fn(usize)) { = note: stack backtrace: 0: as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: std::mem::drop at RUSTLIB/core/src/mem/mod.rs:LL:CC diff --git a/src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.stderr b/src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.stderr index ea4b495926c5e..603d582cde804 100644 --- a/src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.stderr +++ b/src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.stderr @@ -1,15 +1,13 @@ error: Undefined Behavior: constructing invalid value of type &mut PartialDrop: encountered an unaligned reference (required ALIGN byte alignment but found ALIGN) --> RUSTLIB/core/src/ptr/mod.rs:LL:CC | -LL | / pub const unsafe fn drop_in_place(to_drop: *mut T) -LL | | where -LL | | T: [const] Destruct, - | |________________________^ Undefined Behavior occurred here +LL | unsafe { drop_glue(&mut *to_drop) } + | ^^^^^^^^^^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: stack backtrace: - 0: std::ptr::drop_in_place - shim(Some(PartialDrop)) + 0: std::ptr::drop_in_place at RUSTLIB/core/src/ptr/mod.rs:LL:CC 1: main at tests/fail/unaligned_pointers/drop_in_place.rs:LL:CC diff --git a/src/tools/miri/tests/pass/alloc-access-tracking.stderr b/src/tools/miri/tests/pass/alloc-access-tracking.stderr index 6c780e78e91b4..0e25be460cbba 100644 --- a/src/tools/miri/tests/pass/alloc-access-tracking.stderr +++ b/src/tools/miri/tests/pass/alloc-access-tracking.stderr @@ -25,7 +25,7 @@ LL | self.1.deallocate(From::from(ptr.cast()), layout); = note: stack backtrace: 0: > as std::ops::Drop>::drop at RUSTLIB/alloc/src/boxed.rs:LL:CC - 1: std::ptr::drop_in_place)) + 1: std::ptr::drop_glue)) at RUSTLIB/core/src/ptr/mod.rs:LL:CC 2: main at tests/pass/alloc-access-tracking.rs:LL:CC diff --git a/tests/codegen-llvm/drop.rs b/tests/codegen-llvm/drop.rs index b22a8ef27d239..9294e6f549a03 100644 --- a/tests/codegen-llvm/drop.rs +++ b/tests/codegen-llvm/drop.rs @@ -21,10 +21,10 @@ pub fn droppy() { // the regular function exit. We used to have problems with quadratic growths of drop calls in // such functions. // FIXME(eddyb) the `void @` forces a match on the instruction, instead of the - // comment, that's `; call core::ptr::drop_in_place::` + // comment, that's `; call core::ptr::drop_glue::` // for the `v0` mangling, should switch to matching on that once `legacy` is gone. - // CHECK-COUNT-6: {{(call|invoke) void @.*}}drop_in_place{{.*}}SomeUniqueName - // CHECK-NOT: {{(call|invoke) void @.*}}drop_in_place{{.*}}SomeUniqueName + // CHECK-COUNT-6: {{(call|invoke) void @.*}}drop_glue{{.*}}SomeUniqueName + // CHECK-NOT: {{(call|invoke) void @.*}}drop_glue{{.*}}SomeUniqueName // The next line checks for the } that ends the function definition // CHECK-LABEL: {{^[}]}} let _s = SomeUniqueName; diff --git a/tests/codegen-llvm/inline-hint.rs b/tests/codegen-llvm/inline-hint.rs index 3d46885d5a241..69386fc1475c1 100644 --- a/tests/codegen-llvm/inline-hint.rs +++ b/tests/codegen-llvm/inline-hint.rs @@ -16,7 +16,7 @@ pub fn f() { struct A(String, String); -// CHECK: ; core::ptr::drop_in_place:: +// CHECK: ; core::ptr::drop_glue:: // CHECK-NEXT: ; Function Attrs: // CHECK-NOT: inlinehint // CHECK-SAME: {{$}} diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs index a5ec3a9ab7183..c6e7e2771b6b8 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs @@ -9,18 +9,18 @@ #![crate_type = "lib"] -// CHECK-LABEL: define{{.*}}4core3ptr13drop_in_placeDNtNtB4_6marker4Send +// CHECK-LABEL: define{{.*}}4core3ptr9drop_glueDNtNtB4_6marker4Send // CHECK-SAME: {{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -// CHECK: call i1 @llvm.type.test(ptr {{%.+}}, metadata !"_ZTSFvPu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEE") +// CHECK: call i1 @llvm.type.test(ptr {{%.+}}, metadata !"_ZTSFvU3mutu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEEE") struct EmptyDrop; -// CHECK-NOT: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place$LT${{.*}}EmptyDrop$GT${{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +// CHECK-NOT: define{{.*}}4core3ptr{{[0-9]+}}drop_glue$LT${{.*}}EmptyDrop$GT${{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} struct PresentDrop; impl Drop for PresentDrop { fn drop(&mut self) {} - // CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_in_place{{.*}}PresentDrop{{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + // CHECK: define{{.*}}4core3ptr{{[0-9]+}}drop_glue{{.*}}PresentDrop{{.*}}!type ![[TYPE1]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} } pub fn foo() { @@ -28,4 +28,4 @@ pub fn foo() { let _ = Box::new(PresentDrop) as Box; } -// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEE"} +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvU3mutu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops4drop4Dropu6regionEEE"} diff --git a/tests/codegen-llvm/unwind-landingpad-cold.rs b/tests/codegen-llvm/unwind-landingpad-cold.rs index fb095e04650f0..4ddd13cdc8197 100644 --- a/tests/codegen-llvm/unwind-landingpad-cold.rs +++ b/tests/codegen-llvm/unwind-landingpad-cold.rs @@ -6,7 +6,7 @@ // get the `cold` attribute. // CHECK-LABEL: @check_cold -// CHECK: {{(call|invoke) void .+}}drop_in_place{{.+}} [[ATTRIBUTES:#[0-9]+]] +// CHECK: {{(call|invoke) void .+}}drop_glue{{.+}} [[ATTRIBUTES:#[0-9]+]] // CHECK: attributes [[ATTRIBUTES]] = { cold } #[no_mangle] pub fn check_cold(f: fn(), x: Box) { diff --git a/tests/codegen-llvm/vec-into-iter-drops.rs b/tests/codegen-llvm/vec-into-iter-drops.rs index 3b0c89f9679d7..3c3fb7746daa3 100644 --- a/tests/codegen-llvm/vec-into-iter-drops.rs +++ b/tests/codegen-llvm/vec-into-iter-drops.rs @@ -22,6 +22,7 @@ impl Drop for Bomb { pub fn vec_for_each_doesnt_drop(v: vec::Vec<(usize, Option)>) -> usize { // CHECK-NOT: panic // CHECK-NOT: drop_in_place + // CHECK-NOT: drop_glue // CHECK-NOT: Bomb$u20$as$u20$core..ops..drop..Drop let mut last = 0; v.into_iter().for_each(|(x, bomb)| { @@ -41,7 +42,7 @@ pub fn vec_for_each_doesnt_drop(v: vec::Vec<(usize, Option)>) -> usize { // CHECK-LABEL: @vec_for_loop #[no_mangle] pub fn vec_for_loop(v: vec::Vec<(usize, Option)>) -> usize { - // CHECK: drop_in_place + // CHECK: drop_glue let mut last = 0; for (x, bomb) in v { last = x; diff --git a/tests/ui/consts/const-eval/c-variadic-fail.stderr b/tests/ui/consts/const-eval/c-variadic-fail.stderr index 14da5500cb1b6..a5fd0dc04c8e4 100644 --- a/tests/ui/consts/const-eval/c-variadic-fail.stderr +++ b/tests/ui/consts/const-eval/c-variadic-fail.stderr @@ -240,7 +240,7 @@ LL | drop(ap); | ^^^^^^^^ note: inside `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(VaList<'_>))` +note: inside `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL @@ -272,7 +272,7 @@ LL | drop(ap); | ^^^^^^^^ note: inside `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(VaList<'_>))` +note: inside `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL @@ -325,7 +325,7 @@ error[E0080]: pointer not dereferenceable: pointer must point to some allocation LL | } | ^ evaluation of `drop_of_invalid::{constant#0}` failed inside this call | -note: inside `drop_in_place::> - shim(Some(VaList<'_>))` +note: inside `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL diff --git a/tests/ui/consts/miri_unleashed/assoc_const.stderr b/tests/ui/consts/miri_unleashed/assoc_const.stderr index 1ba4f3b2896ef..0b276c8d70705 100644 --- a/tests/ui/consts/miri_unleashed/assoc_const.stderr +++ b/tests/ui/consts/miri_unleashed/assoc_const.stderr @@ -4,9 +4,9 @@ error[E0080]: calling non-const function ` as Drop>::drop` LL | const F: u32 = (U::X, 42).1; | ^ evaluation of `, std::string::String>>::F` failed inside this call | -note: inside `drop_in_place::<(Vec, u32)> - shim(Some((Vec, u32)))` +note: inside `std::ptr::drop_glue::<(Vec, u32)> - shim(Some((Vec, u32)))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `std::ptr::drop_glue::> - shim(Some(Vec))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: erroneous constant encountered diff --git a/tests/ui/consts/miri_unleashed/drop.rs b/tests/ui/consts/miri_unleashed/drop.rs index 46af3388a96ef..0edd3a03c5996 100644 --- a/tests/ui/consts/miri_unleashed/drop.rs +++ b/tests/ui/consts/miri_unleashed/drop.rs @@ -13,8 +13,9 @@ static TEST_OK: () = { // The actual error is tested by the error-pattern above. static TEST_BAD: () = { let _v: Vec = Vec::new(); -}; //~ NOTE failed inside this call - //~| ERROR calling non-const function ` as Drop>::drop` - //~| NOTE inside `drop_in_place::> - shim(Some(Vec))` +}; +//~^ NOTE failed inside this call +//~| ERROR calling non-const function ` as Drop>::drop` +//~| NOTE inside `std::ptr::drop_glue::> - shim(Some(Vec))` //~? WARN skipping const checks diff --git a/tests/ui/consts/miri_unleashed/drop.stderr b/tests/ui/consts/miri_unleashed/drop.stderr index a66422956bee3..2dfe75c468595 100644 --- a/tests/ui/consts/miri_unleashed/drop.stderr +++ b/tests/ui/consts/miri_unleashed/drop.stderr @@ -4,7 +4,7 @@ error[E0080]: calling non-const function ` as Drop>::drop` LL | }; | ^ evaluation of `TEST_BAD` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `std::ptr::drop_glue::> - shim(Some(Vec))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL warning: skipping const checks diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr index 79724ee8d6a17..102bbe03b2efd 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr +++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr @@ -13,11 +13,11 @@ error[E0080]: calling non-const function ` as Drop>::drop` LL | }; | ^ evaluation of `A1` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Option))` +note: inside `std::ptr::drop_glue::> - shim(Some(Option))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place:: - shim(Some(String))` +note: inside `std::ptr::drop_glue:: - shim(Some(String))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `std::ptr::drop_glue::> - shim(Some(Vec))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL error[E0493]: destructor of `Option` cannot be evaluated at compile-time @@ -34,11 +34,11 @@ error[E0080]: calling non-const function ` as Drop>::drop` LL | }; | ^ evaluation of `A2` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Option))` +note: inside `std::ptr::drop_glue::> - shim(Some(Option))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place:: - shim(Some(String))` +note: inside `std::ptr::drop_glue:: - shim(Some(String))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `std::ptr::drop_glue::> - shim(Some(Vec))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time From 18c69ba26b2a0fe86d78f8b14595f653d2b0a660 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 30 Mar 2026 18:08:23 +0200 Subject: [PATCH 03/10] remove retag from drop shim --- compiler/rustc_mir_transform/src/shim.rs | 34 +++++-------------- .../src/shim/async_destructor_ctor.rs | 4 +-- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 4fd0629befecf..1af2d7f230f9f 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -298,35 +298,17 @@ fn local_decls_for_sig<'tcx>( fn dropee_emit_retag<'tcx>( tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, - mut dropee_ptr: Place<'tcx>, + dropee_ptr: Place<'tcx>, span: Span, -) -> Place<'tcx> { +) { if tcx.sess.opts.unstable_opts.mir_emit_retag { let source_info = SourceInfo::outermost(span); - // We want to treat the function argument as if it was passed by `&mut`. As such, we - // generate - // ``` - // temp = &mut *arg; - // Retag(temp, FnEntry) - // ``` - // It's important that we do this first, before anything that depends on `dropee_ptr` - // has been put into the body. - let reborrow = Rvalue::Ref( - tcx.lifetimes.re_erased, - BorrowKind::Mut { kind: MutBorrowKind::Default }, - tcx.mk_place_deref(dropee_ptr), - ); - let ref_ty = reborrow.ty(body.local_decls(), tcx); - dropee_ptr = body.local_decls.push(LocalDecl::new(ref_ty, span)).into(); - let new_statements = [ - StatementKind::Assign(Box::new((dropee_ptr, reborrow))), - StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr)), - ]; - for s in new_statements { - body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, s)); - } + let new_statement = StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr)); + + body.basic_blocks_mut()[START_BLOCK] + .statements + .push(Statement::new(source_info, new_statement)); } - dropee_ptr } fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) -> Body<'tcx> { @@ -359,7 +341,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) // The first argument (index 0), but add 1 for the return value. let dropee_ptr = Place::from(Local::new(1 + 0)); - let dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span); + dropee_emit_retag(tcx, &mut body, dropee_ptr, span); if ty.is_some() { let patch = { diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index a0f1260cd986d..dea6b3d032581 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -124,13 +124,13 @@ pub(super) fn build_async_drop_shim<'tcx>( return body; } - let mut dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span))); + let dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span))); let st_kind = StatementKind::Assign(Box::new(( dropee_ptr, Rvalue::Use(Operand::Move(coroutine_layout_dropee)), ))); body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, st_kind)); - dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span); + dropee_emit_retag(tcx, &mut body, dropee_ptr, span); let dropline = body.basic_blocks.last_index(); From 80592a3f79e8b1f631f7eb1d15d1a928bcffc65d Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Fri, 3 Apr 2026 21:07:17 +0200 Subject: [PATCH 04/10] rename `drop_in_place` lang item to `drop_glue` --- compiler/rustc_codegen_cranelift/example/mini_core.rs | 8 ++------ compiler/rustc_codegen_gcc/example/mini_core.rs | 6 ++---- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 4 ++-- compiler/rustc_hir/src/lang_items.rs | 3 ++- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_mir_transform/src/coroutine/drop.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- .../src/cfi/typeid/itanium_cxx_abi/transform.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_ty_utils/src/instance.rs | 2 +- library/core/src/ptr/mod.rs | 2 +- library/rtstartup/rsbegin.rs | 7 ++----- library/rtstartup/rsend.rs | 7 ++----- tests/assembly-llvm/large_data_threshold.rs | 4 ++-- tests/assembly-llvm/small_data_threshold.rs | 4 ++-- tests/auxiliary/minicore.rs | 4 ++-- tests/run-make/arm64ec-import-export-static/export.rs | 4 ++-- tests/run-make/min-global-align/min_global_align.rs | 4 ++-- tests/ui/lang-items/issue-87573.rs | 6 +++--- tests/ui/lang-items/issue-87573.stderr | 8 ++++---- tests/ui/lang-items/lang-item-generic-requirements.rs | 4 ++-- tests/ui/lang-items/lang-item-generic-requirements.stderr | 6 +++--- 23 files changed, 42 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 218050982e6d3..309c17d24cf84 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -550,14 +550,10 @@ unsafe extern "C" { fn _Unwind_Resume(exc: *mut ()) -> !; } -#[lang = "drop_in_place"] -#[allow(unconditional_recursion)] -pub unsafe fn drop_in_place(to_drop: *mut T) { +#[lang = "drop_glue"] +pub unsafe fn drop_glue(_to_drop: &mut T) { // Code here does not matter - this is replaced by the // real drop glue by the compiler. - unsafe { - drop_in_place(to_drop); - } } #[lang = "unpin"] diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 2e165cc3c129d..7836e0024fcce 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -552,12 +552,10 @@ fn eh_personality() -> ! { loop {} } -#[lang = "drop_in_place"] -#[allow(unconditional_recursion)] -pub unsafe fn drop_in_place(to_drop: *mut T) { +#[lang = "drop_glue"] +pub unsafe fn drop_glue(_to_drop: &mut T) { // Code here does not matter - this is replaced by the // real drop glue by the compiler. - drop_in_place(to_drop); } #[lang = "unpin"] diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 2460bf18b13d1..ca52806f9e8b5 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -403,7 +403,7 @@ fn upstream_monomorphizations_provider( let mut instances: DefIdMap> = Default::default(); - let drop_in_place_fn_def_id = tcx.lang_items().drop_in_place_fn(); + let drop_in_place_fn_def_id = tcx.lang_items().drop_glue_fn(); let async_drop_in_place_fn_def_id = tcx.lang_items().async_drop_in_place_fn(); for &cnum in cnums.iter() { @@ -465,7 +465,7 @@ fn upstream_drop_glue_for_provider<'tcx>( tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>, ) -> Option { - let def_id = tcx.lang_items().drop_in_place_fn()?; + let def_id = tcx.lang_items().drop_glue_fn()?; tcx.upstream_monomorphizations_for(def_id)?.get(&args).cloned() } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index c144f0b7dbc5b..4698e485fbef0 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -320,7 +320,8 @@ language_item_table! { FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None; FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None; - DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); + // Compiler-generated drop glue function, aka `core::ptr::drop_glue` + DropGlue, sym::drop_glue, drop_glue_fn, Target::Fn, GenericRequirement::Exact(1); AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None; /// For all binary crates without `#![no_main]`, Rust will generate a "main" function. diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 9759e376c0586..dc06057ac5cad 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -718,7 +718,7 @@ impl<'tcx> Instance<'tcx> { } pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { - let def_id = tcx.require_lang_item(LangItem::DropInPlace, DUMMY_SP); + let def_id = tcx.require_lang_item(LangItem::DropGlue, DUMMY_SP); let args = tcx.mk_args(&[ty.into()]); Instance::expect_resolve( tcx, diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 969d654941800..e8836416cf241 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1233,7 +1233,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option, abi: ExternAbi) // This is not part of `codegen_fn_attrs` as it can differ between crates // and therefore cannot be computed in core. if !tcx.sess.opts.unstable_opts.panic_in_drop.unwinds() - && tcx.is_lang_item(did, LangItem::DropInPlace) + && tcx.is_lang_item(did, LangItem::DropGlue) { return false; } diff --git a/compiler/rustc_mir_transform/src/coroutine/drop.rs b/compiler/rustc_mir_transform/src/coroutine/drop.rs index 718d75e875b28..64b16196194ce 100644 --- a/compiler/rustc_mir_transform/src/coroutine/drop.rs +++ b/compiler/rustc_mir_transform/src/coroutine/drop.rs @@ -602,7 +602,7 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( // Update the body's def to become the drop glue. let coroutine_instance = body.source.instance; - let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, body.span); + let drop_in_place = tcx.require_lang_item(LangItem::DropGlue, body.span); let drop_instance = InstanceKind::DropGlue(drop_in_place, Some(coroutine_ty)); // Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 5c21ff1464c3d..ccf323b54a089 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -656,7 +656,7 @@ fn check_recursion_limit<'tcx>( let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0); debug!(" => recursion depth={}", recursion_depth); - let adjusted_recursion_depth = if tcx.is_lang_item(def_id, LangItem::DropInPlace) { + let adjusted_recursion_depth = if tcx.is_lang_item(def_id, LangItem::DropGlue) { // HACK: drop_in_place creates tight monomorphization loops. Give // it more margin. recursion_depth / 4 diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index 5691ed1469276..743db929f449a 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -307,7 +307,7 @@ pub(crate) fn transform_instance<'tcx>( ) -> Instance<'tcx> { // FIXME: account for async-drop-glue if (matches!(instance.def, ty::InstanceKind::Virtual(..)) - && tcx.is_lang_item(instance.def_id(), LangItem::DropInPlace)) + && tcx.is_lang_item(instance.def_id(), LangItem::DropGlue)) || matches!(instance.def, ty::InstanceKind::DropGlue(..)) { // Adjust the type ids of DropGlues diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 33bc5a578e8b6..336e936604e58 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -828,6 +828,7 @@ symbols! { dreg_low8, dreg_low16, drop, + drop_glue, drop_in_place, drop_types_in_const, dropck_eyepatch, diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index cf881961b3ce3..fc1bf3c4a5d41 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -34,7 +34,7 @@ fn resolve_instance_raw<'tcx>( let def = if tcx.intrinsic(def_id).is_some() { debug!(" => intrinsic"); ty::InstanceKind::Intrinsic(def_id) - } else if tcx.is_lang_item(def_id, LangItem::DropInPlace) { + } else if tcx.is_lang_item(def_id, LangItem::DropGlue) { let ty = args.type_at(0); if ty.needs_drop(tcx, typing_env) { diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index b9e93dc89b5f8..4e6b952dd727e 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -822,7 +822,7 @@ where } /// Helper function for `drop_in_place`. -#[lang = "drop_in_place"] +#[lang = "drop_glue"] const unsafe fn drop_glue(_: &mut T) where T: [const] Destruct, diff --git a/library/rtstartup/rsbegin.rs b/library/rtstartup/rsbegin.rs index 6ee06cce5c630..d268090fe77ae 100644 --- a/library/rtstartup/rsbegin.rs +++ b/library/rtstartup/rsbegin.rs @@ -39,12 +39,9 @@ auto trait Freeze {} impl Copy for *mut T {} -#[lang = "drop_in_place"] +#[lang = "drop_glue"] #[inline] -#[allow(unconditional_recursion)] -pub unsafe fn drop_in_place(to_drop: *mut T) { - drop_in_place(to_drop); -} +pub unsafe fn drop_glue(_to_drop: &mut T) {} // Frame unwind info registration // diff --git a/library/rtstartup/rsend.rs b/library/rtstartup/rsend.rs index d763971445069..8121135debef3 100644 --- a/library/rtstartup/rsend.rs +++ b/library/rtstartup/rsend.rs @@ -27,12 +27,9 @@ auto trait Freeze {} impl Copy for *mut T {} -#[lang = "drop_in_place"] +#[lang = "drop_glue"] #[inline] -#[allow(unconditional_recursion)] -pub unsafe fn drop_in_place(to_drop: *mut T) { - drop_in_place(to_drop); -} +pub unsafe fn drop_glue(_to_drop: &mut T) {} #[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))] pub mod eh_frames { diff --git a/tests/assembly-llvm/large_data_threshold.rs b/tests/assembly-llvm/large_data_threshold.rs index f3b37eb7f83de..f593a2a924924 100644 --- a/tests/assembly-llvm/large_data_threshold.rs +++ b/tests/assembly-llvm/large_data_threshold.rs @@ -20,8 +20,8 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -#[lang = "drop_in_place"] -fn drop_in_place(_: *mut T) {} +#[lang = "drop_glue"] +fn drop_glue(_: &mut T) {} #[used] #[no_mangle] diff --git a/tests/assembly-llvm/small_data_threshold.rs b/tests/assembly-llvm/small_data_threshold.rs index 2abe8687d8b26..664f36dd1665b 100644 --- a/tests/assembly-llvm/small_data_threshold.rs +++ b/tests/assembly-llvm/small_data_threshold.rs @@ -28,8 +28,8 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -#[lang = "drop_in_place"] -fn drop_in_place(_: *mut T) {} +#[lang = "drop_glue"] +fn drop_glue(_: &mut T) {} #[used] #[no_mangle] diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 5c6eb54832437..b3ed8da5fca26 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -240,8 +240,8 @@ impl Sync for () {} impl Sync for [T; N] {} -#[lang = "drop_in_place"] -fn drop_in_place(_: *mut T) {} +#[lang = "drop_glue"] +fn drop_glue(_: &mut T) {} #[lang = "fn_once"] pub trait FnOnce { diff --git a/tests/run-make/arm64ec-import-export-static/export.rs b/tests/run-make/arm64ec-import-export-static/export.rs index ca6ccf00ca17e..79aedaa08a418 100644 --- a/tests/run-make/arm64ec-import-export-static/export.rs +++ b/tests/run-make/arm64ec-import-export-static/export.rs @@ -17,8 +17,8 @@ impl Sync for i32 {} #[lang = "copy"] pub trait Copy {} impl Copy for i32 {} -#[lang = "drop_in_place"] -pub unsafe fn drop_in_place(_: *mut T) {} +#[lang = "drop_glue"] +pub unsafe fn drop_glue(_: &mut T) {} #[no_mangle] extern "system" fn _DllMainCRTStartup(_: *const u8, _: u32, _: *const u8) -> u32 { 1 diff --git a/tests/run-make/min-global-align/min_global_align.rs b/tests/run-make/min-global-align/min_global_align.rs index fd6f83570300a..ee668e5938db9 100644 --- a/tests/run-make/min-global-align/min_global_align.rs +++ b/tests/run-make/min-global-align/min_global_align.rs @@ -34,5 +34,5 @@ trait Sync {} impl Sync for bool {} impl Sync for &'static bool {} -#[lang = "drop_in_place"] -pub unsafe fn drop_in_place(_: *mut T) {} +#[lang = "drop_glue"] +pub unsafe fn drop_glue(_: &mut T) {} diff --git a/tests/ui/lang-items/issue-87573.rs b/tests/ui/lang-items/issue-87573.rs index 97146df0ba766..e16fc1fd14864 100644 --- a/tests/ui/lang-items/issue-87573.rs +++ b/tests/ui/lang-items/issue-87573.rs @@ -23,12 +23,12 @@ trait Copy {} trait Sync {} impl Sync for bool {} -#[lang = "drop_in_place"] -//~^ ERROR: `drop_in_place` lang item must be applied to a function with at least 1 generic argument +#[lang = "drop_glue"] +//~^ ERROR: `drop_glue` lang item must be applied to a function with 1 generic argument fn drop_fn() { while false {} } #[lang = "start"] //~^ ERROR: `start` lang item must be applied to a function with 1 generic argument -fn start(){} +fn start() {} diff --git a/tests/ui/lang-items/issue-87573.stderr b/tests/ui/lang-items/issue-87573.stderr index 07f4f5d8ac86f..08af3232a3279 100644 --- a/tests/ui/lang-items/issue-87573.stderr +++ b/tests/ui/lang-items/issue-87573.stderr @@ -1,8 +1,8 @@ -error[E0718]: `drop_in_place` lang item must be applied to a function with at least 1 generic argument +error[E0718]: `drop_glue` lang item must be applied to a function with 1 generic argument --> $DIR/issue-87573.rs:26:1 | -LL | #[lang = "drop_in_place"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[lang = "drop_glue"] + | ^^^^^^^^^^^^^^^^^^^^^ LL | LL | fn drop_fn() { | - this function has 0 generic arguments @@ -13,7 +13,7 @@ error[E0718]: `start` lang item must be applied to a function with 1 generic arg LL | #[lang = "start"] | ^^^^^^^^^^^^^^^^^ LL | -LL | fn start(){} +LL | fn start() {} | - this function has 0 generic arguments error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/lang-item-generic-requirements.rs b/tests/ui/lang-items/lang-item-generic-requirements.rs index 2f80567d9e71a..38348c7bf6d0c 100644 --- a/tests/ui/lang-items/lang-item-generic-requirements.rs +++ b/tests/ui/lang-items/lang-item-generic-requirements.rs @@ -17,8 +17,8 @@ trait MySized: MyMetaSized {} trait MyAdd<'a, T> {} //~^^ ERROR: `add` lang item must be applied to a trait with 1 generic argument [E0718] -#[lang = "drop_in_place"] -//~^ ERROR `drop_in_place` lang item must be applied to a function with at least 1 generic +#[lang = "drop_glue"] +//~^ ERROR `drop_glue` lang item must be applied to a function with 1 generic fn my_ptr_drop() {} #[lang = "index"] diff --git a/tests/ui/lang-items/lang-item-generic-requirements.stderr b/tests/ui/lang-items/lang-item-generic-requirements.stderr index 0b3088add61e7..4526722ed5801 100644 --- a/tests/ui/lang-items/lang-item-generic-requirements.stderr +++ b/tests/ui/lang-items/lang-item-generic-requirements.stderr @@ -6,11 +6,11 @@ LL | #[lang = "add"] LL | trait MyAdd<'a, T> {} | ------- this trait has 2 generic arguments -error[E0718]: `drop_in_place` lang item must be applied to a function with at least 1 generic argument +error[E0718]: `drop_glue` lang item must be applied to a function with 1 generic argument --> $DIR/lang-item-generic-requirements.rs:20:1 | -LL | #[lang = "drop_in_place"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[lang = "drop_glue"] + | ^^^^^^^^^^^^^^^^^^^^^ LL | LL | fn my_ptr_drop() {} | - this function has 0 generic arguments From 528bb1bdda1f1e0a19e973afedc8c1dd82a63cd4 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Wed, 8 Apr 2026 14:59:29 +0200 Subject: [PATCH 05/10] finish up renaming `drop_in_place` lang item => `drop_glue` --- compiler/rustc_codegen_cranelift/src/abi/mod.rs | 4 ++-- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 9 ++++----- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 ++-- compiler/rustc_const_eval/src/interpret/call.rs | 7 +++---- compiler/rustc_const_eval/src/interpret/step.rs | 4 ++-- compiler/rustc_middle/src/hir/mod.rs | 4 ++-- compiler/rustc_middle/src/middle/exported_symbols.rs | 2 +- compiler/rustc_middle/src/mir/syntax.rs | 2 +- compiler/rustc_middle/src/mono.rs | 6 +++--- compiler/rustc_middle/src/ty/instance.rs | 9 ++++----- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/vtable.rs | 2 +- .../src/add_moves_for_packed_drops.rs | 6 +++--- compiler/rustc_mir_transform/src/coroutine/drop.rs | 6 +++--- compiler/rustc_monomorphize/src/collector.rs | 6 +++--- compiler/rustc_monomorphize/src/partitioning.rs | 5 ++--- compiler/rustc_passes/src/lang_items.rs | 2 +- compiler/rustc_public_bridge/src/context/impls.rs | 2 +- compiler/rustc_ty_utils/src/abi.rs | 3 +-- 19 files changed, 40 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 13f5ad5157cef..6a27b8172f986 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -701,7 +701,7 @@ pub(crate) fn codegen_drop<'tcx>( unwind: UnwindAction, ) { let ty = drop_place.layout().ty; - let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty); + let drop_instance = Instance::resolve_drop_glue(fx.tcx, ty); let ret_block = fx.get_block(target); // AsyncDropGlueCtorShim can't be here @@ -734,7 +734,7 @@ pub(crate) fn codegen_drop<'tcx>( fx.bcx.switch_to_block(continued); // FIXME(eddyb) perhaps move some of this logic into - // `Instance::resolve_drop_in_place`? + // `Instance::resolve_drop_glue`? let virtual_drop = Instance { def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0), args: drop_instance.args, diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index ca52806f9e8b5..014fd5cf3a0e5 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -403,7 +403,7 @@ fn upstream_monomorphizations_provider( let mut instances: DefIdMap> = Default::default(); - let drop_in_place_fn_def_id = tcx.lang_items().drop_glue_fn(); + let drop_glue_fn_def_id = tcx.lang_items().drop_glue_fn(); let async_drop_in_place_fn_def_id = tcx.lang_items().async_drop_in_place_fn(); for &cnum in cnums.iter() { @@ -411,11 +411,10 @@ fn upstream_monomorphizations_provider( let (def_id, args) = match *exported_symbol { ExportedSymbol::Generic(def_id, args) => (def_id, args), ExportedSymbol::DropGlue(ty) => { - if let Some(drop_in_place_fn_def_id) = drop_in_place_fn_def_id { + if let Some(drop_in_place_fn_def_id) = drop_glue_fn_def_id { (drop_in_place_fn_def_id, tcx.mk_args(&[ty.into()])) } else { - // `drop_in_place` in place does not exist, don't try - // to use it. + // `drop_glue` does not exist, don't try to use it. continue; } } @@ -587,7 +586,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>( } ExportedSymbol::DropGlue(ty) => rustc_symbol_mangling::symbol_name_for_instance_in_crate( tcx, - Instance::resolve_drop_in_place(tcx, ty), + Instance::resolve_drop_glue(tcx, ty), instantiating_crate, ), ExportedSymbol::AsyncDropGlueCtorShim(ty) => { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 1b96be12f71da..2ee3de7a251df 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -604,7 +604,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) -> MergingSucc { let ty = location.ty(self.mir, bx.tcx()).ty; let ty = self.monomorphize(ty); - let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); + let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty); if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def { // we don't actually need to drop anything. @@ -622,7 +622,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() { // FIXME(eddyb) perhaps move some of this logic into - // `Instance::resolve_drop_in_place`? + // `Instance::resolve_drop_glue`? ty::Dynamic(_, _) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn Trait) diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 534cba7aa66a1..67354498c2dc1 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -886,16 +886,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { _ => { debug_assert_eq!( instance, - ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty) + ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty) ); place } }; let instance = { - let _trace = - enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty); - ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty) + let _trace = enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty); + ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty) }; let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?; diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 2dee1157e2a12..734d310f09fdc 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -583,8 +583,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let place = self.eval_place(place)?; let instance = { let _trace = - enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty); - Instance::resolve_drop_in_place(*self.tcx, place.layout.ty) + enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty); + Instance::resolve_drop_glue(*self.tcx, place.layout.ty) }; if let ty::InstanceKind::DropGlue(_, None) = instance.def { // This is the branch we enter if and only if the dropped type has no drop glue diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 814b333cfb0f8..a4ac02ec8c179 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -315,8 +315,8 @@ impl<'tcx> TyCtxt<'tcx> { Node::Expr(parent_expr) => { match parent_expr.kind { // Addr-of, field projections, and LHS of assignment don't constitute reads. - // Assignment does call `drop_in_place`, though, but its safety - // requirements are not the same. + // Assignment does call `drop_glue`, though, but its safety requirements are + // not the same. ExprKind::AddrOf(..) | ExprKind::Field(..) => false, // Place-preserving expressions only constitute reads if their diff --git a/compiler/rustc_middle/src/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index 58fc32078039a..829869ec3fec6 100644 --- a/compiler/rustc_middle/src/middle/exported_symbols.rs +++ b/compiler/rustc_middle/src/middle/exported_symbols.rs @@ -66,7 +66,7 @@ impl<'tcx> ExportedSymbol<'tcx> { tcx.symbol_name(ty::Instance::new_raw(def_id, args)) } ExportedSymbol::DropGlue(ty) => { - tcx.symbol_name(ty::Instance::resolve_drop_in_place(tcx, ty)) + tcx.symbol_name(ty::Instance::resolve_drop_glue(tcx, ty)) } ExportedSymbol::AsyncDropGlueCtorShim(ty) => { tcx.symbol_name(ty::Instance::resolve_async_drop_in_place(tcx, ty)) diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 455089f285d17..e59305e6eb398 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -753,7 +753,7 @@ pub enum TerminatorKind<'tcx> { /// /// After drop elaboration: `Drop` terminators are a complete nop for types that have no drop /// glue. For other types, `Drop` terminators behave exactly like a call to - /// `core::mem::drop_in_place` with a pointer to the given place. + /// `core::mem::drop_glue` with a reference to the given place. /// /// `Drop` before drop elaboration is a *conditional* execution of the drop glue. Specifically, /// the `Drop` will be executed if... diff --git a/compiler/rustc_middle/src/mono.rs b/compiler/rustc_middle/src/mono.rs index 3909db8bfce6e..e2b599c6cd221 100644 --- a/compiler/rustc_middle/src/mono.rs +++ b/compiler/rustc_middle/src/mono.rs @@ -69,7 +69,7 @@ fn opt_incr_drop_glue_mode<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Instantiati let Some(dtor) = adt_def.destructor(tcx) else { // We use LocalCopy for drops of enums only; this code is inherited from // https://github.com/rust-lang/rust/pull/67332 and the theory is that we get to optimize - // out code like drop_in_place(Option::None) before crate-local ThinLTO, which improves + // out code like `drop_glue(&mut Option::None)` before crate-local ThinLTO, which improves // compile time. At the time of writing, simply removing this entire check does seem to // regress incr-opt compile times. But it sure seems like a more sophisticated check could // do better here. @@ -80,8 +80,8 @@ fn opt_incr_drop_glue_mode<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Instantiati } }; - // We've gotten to a drop_in_place for a type that directly implements Drop. - // The drop glue is a wrapper for the Drop::drop impl, and we are an optimized build, so in an + // We've gotten to a `drop_glue` for a type that directly implements Drop. + // The drop glue is a wrapper for the `Drop::drop` impl, and we are an optimized build, so in an // effort to coordinate with the mode that the actual impl will get, we make the glue also // LocalCopy. if tcx.cross_crate_inlinable(dtor.did) { diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index dc06057ac5cad..f58545149cec2 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -147,11 +147,10 @@ pub enum InstanceKind<'tcx> { /// Proxy shim for async drop of future (def_id, proxy_cor_ty, impl_cor_ty) FutureDropPollShim(DefId, Ty<'tcx>, Ty<'tcx>), - /// `core::ptr::drop_in_place::`. + /// `core::ptr::drop_glue::`. /// - /// The `DefId` is for `core::ptr::drop_in_place`. - /// The `Option>` is either `Some(T)`, or `None` for empty drop - /// glue. + /// The `DefId` is for `core::ptr::drop_glue`. + /// The `Option>` is either `Some(T)`, or `None` for empty drop glue. DropGlue(DefId, Option>), /// Compiler-generated `::clone` implementation. @@ -717,7 +716,7 @@ impl<'tcx> Instance<'tcx> { } } - pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { + pub fn resolve_drop_glue(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { let def_id = tcx.require_lang_item(LangItem::DropGlue, DUMMY_SP); let args = tcx.mk_args(&[ty.into()]); Instance::expect_resolve( diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index e8836416cf241..56e9c87dbca36 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1228,7 +1228,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option, abi: ExternAbi) return false; } - // With -Z panic-in-drop=abort, drop_in_place never unwinds. + // With -Z panic-in-drop=abort, `drop_glue` never unwinds. // // This is not part of `codegen_fn_attrs` as it can differ between crates // and therefore cannot be computed in core. diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index 8a376e5429459..ec348cdf4b074 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -122,7 +122,7 @@ pub(super) fn vtable_allocation_provider<'tcx>( let scalar = match *entry { VtblEntry::MetadataDropInPlace => { if ty.needs_drop(tcx, ty::TypingEnv::fully_monomorphized()) { - let instance = ty::Instance::resolve_drop_in_place(tcx, ty); + let instance = ty::Instance::resolve_drop_glue(tcx, ty); let fn_alloc_id = tcx.reserve_and_set_fn_alloc(instance, CTFE_ALLOC_SALT); let fn_ptr = Pointer::from(fn_alloc_id); Scalar::from_pointer(fn_ptr, &tcx) diff --git a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs index 9950a94d722eb..7649d3d4981de 100644 --- a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs +++ b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs @@ -10,6 +10,7 @@ use crate::util; /// they are dropped from an aligned address. /// /// For example, if we have something like +/// /// ```ignore (illustrative) /// #[repr(packed)] /// struct Foo { @@ -20,9 +21,8 @@ use crate::util; /// let foo = ...; /// ``` /// -/// We want to call `drop_in_place::>` on `data` from an aligned -/// address. This means we can't simply drop `foo.data` directly, because -/// its address is not aligned. +/// We want to call `drop_glue::>` with a reference to `data`, which must be aligned. +/// This means we can't simply drop `foo.data` directly, because its address is not aligned. /// /// Instead, we move `foo.data` to a local and drop that: /// ```ignore (illustrative) diff --git a/compiler/rustc_mir_transform/src/coroutine/drop.rs b/compiler/rustc_mir_transform/src/coroutine/drop.rs index 64b16196194ce..788e98b3a99c0 100644 --- a/compiler/rustc_mir_transform/src/coroutine/drop.rs +++ b/compiler/rustc_mir_transform/src/coroutine/drop.rs @@ -569,7 +569,7 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( // not a coroutine body itself; it just has its drop built out of it. let _ = body.coroutine.take(); // Make sure the resume argument is not included here, since we're - // building a body for `drop_in_place`. + // building a body for `drop_glue`. body.arg_count = 1; let source_info = SourceInfo::outermost(body.span); @@ -602,8 +602,8 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( // Update the body's def to become the drop glue. let coroutine_instance = body.source.instance; - let drop_in_place = tcx.require_lang_item(LangItem::DropGlue, body.span); - let drop_instance = InstanceKind::DropGlue(drop_in_place, Some(coroutine_ty)); + let drop_glue = tcx.require_lang_item(LangItem::DropGlue, body.span); + let drop_instance = InstanceKind::DropGlue(drop_glue, Some(coroutine_ty)); // Temporary change MirSource to coroutine's instance so that dump_mir produces more sensible // filename. diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index ccf323b54a089..8949ce1ac6a67 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -657,7 +657,7 @@ fn check_recursion_limit<'tcx>( debug!(" => recursion depth={}", recursion_depth); let adjusted_recursion_depth = if tcx.is_lang_item(def_id, LangItem::DropGlue) { - // HACK: drop_in_place creates tight monomorphization loops. Give + // HACK: `drop_glue` creates tight monomorphization loops. Give // it more margin. recursion_depth / 4 } else { @@ -935,7 +935,7 @@ fn visit_drop_use<'tcx>( source: Span, output: &mut MonoItems<'tcx>, ) { - let instance = Instance::resolve_drop_in_place(tcx, ty); + let instance = Instance::resolve_drop_glue(tcx, ty); visit_instance_use(tcx, instance, is_direct_call, source, output); } @@ -1525,7 +1525,7 @@ impl<'v> RootCollector<'_, 'v> { }); // This type is impossible to instantiate, so we should not try to - // generate a `drop_in_place` instance for it. + // generate a `drop_glue` instance for it. if self.tcx.instantiate_and_check_impossible_predicates(( id.owner_id.to_def_id(), id_args, diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 6f9795fb3bff1..8e967bf06214d 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -662,9 +662,8 @@ fn characteristic_def_id_of_mono_item<'tcx>( && tcx.sess.opts.incremental.is_some() && tcx.is_lang_item(tcx.impl_trait_id(impl_def_id), LangItem::Drop) { - // Put `Drop::drop` into the same cgu as `drop_in_place` - // since `drop_in_place` is the only thing that can - // call it. + // Put `Drop::drop` into the same cgu as `drop_glue` + // since `drop_glue` is the only thing that can call it. return None; } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index b6fb9937dfa45..527c618c7a264 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -193,7 +193,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> { // one (for the RHS/index), unary operations have none, the closure // traits have one for the argument list, coroutines have one for the // resume argument, and ordering/equality relations have one for the RHS - // Some other types like Box and various functions like drop_in_place + // Some other types like Box and various unsizing-related traits // have minimum requirements. // FIXME: This still doesn't count, e.g., elided lifetimes and APITs. diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 359769d4cfe4c..53ff0b3b518ea 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -655,7 +655,7 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { /// Resolve an instance for drop_in_place for the given type. pub fn resolve_drop_in_place(&self, internal_ty: Ty<'tcx>) -> Instance<'tcx> { - let instance = Instance::resolve_drop_in_place(self.tcx, internal_ty); + let instance = Instance::resolve_drop_glue(self.tcx, internal_ty); instance } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 429209d85f854..b4ba4175d7e61 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -363,8 +363,7 @@ fn arg_attrs_for_rust_scalar<'tcx>( // Only pointer types handled below. let Scalar::Initialized { value: Pointer(_), valid_range } = scalar else { return attrs }; - // Set `nonnull` if the validity range excludes zero, or for the argument to `drop_in_place`, - // which must be nonnull per its documented safety requirements. + // Set `nonnull` if the validity range excludes zero. if !valid_range.contains(0) { attrs.set(ArgAttribute::NonNull); } From 5392b637c6006db813374ebd4f19f007c9b8b19b Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Fri, 3 Apr 2026 19:45:56 +0200 Subject: [PATCH 06/10] change type of `async_drop_in_place` to accept `&mut _` --- .../rustc_mir_transform/src/elaborate_drop.rs | 7 +--- .../src/shim/async_destructor_ctor.rs | 35 +++++++++---------- library/core/src/future/async_drop.rs | 3 +- src/tools/miri/tests/pass/async-drop.rs | 4 +-- .../async-drop/async-drop-initial.rs | 27 +++++--------- .../async-await/async-drop/ex-ice-132103.rs | 4 +-- .../async-drop/open-drop-error2.rs | 10 +++--- .../async-drop/open-drop-error2.stderr | 2 +- 8 files changed, 37 insertions(+), 55 deletions(-) diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index 1fe745a5d5197..a8e622a032847 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -354,7 +354,6 @@ where let ty::Adt(adt_def, adt_args) = pin_obj_ty.kind() else { bug!(); }; - let obj_ptr_ty = Ty::new_mut_ptr(tcx, drop_ty); let unwrap_ty = adt_def.non_enum_variant().fields[FieldIdx::ZERO].ty(tcx, adt_args); let obj_ref_place = Place::from(self.new_temp(unwrap_ty)); call_statements.push(self.assign( @@ -366,11 +365,7 @@ where ))), )); - let obj_ptr_place = Place::from(self.new_temp(obj_ptr_ty)); - - let addr = Rvalue::RawPtr(RawPtrKind::Mut, tcx.mk_place_deref(obj_ref_place)); - call_statements.push(self.assign(obj_ptr_place, addr)); - obj_ptr_place + obj_ref_place }; call_statements .push(Statement::new(self.source_info, StatementKind::StorageLive(fut.local))); diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index dea6b3d032581..30b464990f270 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -51,7 +51,7 @@ pub(super) fn build_async_drop_shim<'tcx>( let typing_env = ty::TypingEnv::fully_monomorphized(); let drop_ty = parent_args.first().unwrap().expect_ty(); - let drop_ptr_ty = Ty::new_mut_ptr(tcx, drop_ty); + let drop_ptr_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, drop_ty); assert!(tcx.is_coroutine(def_id)); let coroutine_kind = tcx.coroutine_kind(def_id).unwrap(); @@ -209,7 +209,7 @@ fn build_adrop_for_coroutine_shim<'tcx>( let source_info = SourceInfo::outermost(span); // converting `(_1: Pin<&mut CorLayout>, _2: &mut Context<'_>) -> Poll<()>` // into `(_1: Pin<&mut ProxyLayout>, _2: &mut Context<'_>) -> Poll<()>` - // let mut _x: &mut CorLayout = &*_1.0.0; + // let mut _x: &mut CorLayout = &mut *_1.0.0; // Replace old _1.0 accesses into _x accesses; let body = tcx.optimized_mir(*coroutine_def_id).future_drop_poll().unwrap(); let mut body: Body<'tcx> = EarlyBinder::bind(body.clone()).instantiate(tcx, impl_args); @@ -231,7 +231,7 @@ fn build_adrop_for_coroutine_shim<'tcx>( { let mut idx: usize = 0; - // _proxy = _1.0 : Pin<&ProxyLayout> ==> &ProxyLayout + // _proxy = _1.0 : Pin<&mut ProxyLayout> ==> &mut ProxyLayout let proxy_ref_place = Place::from(pin_proxy_layout_local) .project_deeper(&[PlaceElem::Field(FieldIdx::ZERO, proxy_ref)], tcx); body.basic_blocks_mut()[START_BLOCK].statements.insert( @@ -245,22 +245,23 @@ fn build_adrop_for_coroutine_shim<'tcx>( ), ); idx += 1; - let mut cor_ptr_local = proxy_ref_local; + + // _cor_ref_tmp = (*(*_proxy).0).0... + let mut cor_ref_tmp_local = proxy_ref_local; proxy_ty.find_async_drop_impl_coroutine(tcx, |ty| { if ty != proxy_ty { - let ty_ptr = Ty::new_mut_ptr(tcx, ty); - let impl_ptr_place = Place::from(cor_ptr_local).project_deeper( - &[PlaceElem::Deref, PlaceElem::Field(FieldIdx::ZERO, ty_ptr)], + let ty_ref = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty); + let impl_ptr_place = Place::from(cor_ref_tmp_local).project_deeper( + &[PlaceElem::Deref, PlaceElem::Field(FieldIdx::ZERO, ty_ref)], tcx, ); - cor_ptr_local = body.local_decls.push(LocalDecl::new(ty_ptr, span)); - // _cor_ptr = _proxy.0.0 (... .0) + cor_ref_tmp_local = body.local_decls.push(LocalDecl::new(ty_ref, span)); body.basic_blocks_mut()[START_BLOCK].statements.insert( idx, Statement::new( source_info, StatementKind::Assign(Box::new(( - Place::from(cor_ptr_local), + Place::from(cor_ref_tmp_local), Rvalue::Use(Operand::Copy(impl_ptr_place)), ))), ), @@ -269,17 +270,15 @@ fn build_adrop_for_coroutine_shim<'tcx>( } }); - // _cor_ref = &*cor_ptr - let reborrow = Rvalue::Ref( - tcx.lifetimes.re_erased, - BorrowKind::Mut { kind: MutBorrowKind::Default }, - tcx.mk_place_deref(Place::from(cor_ptr_local)), - ); + // _cor_ref = cor_ref_tmp body.basic_blocks_mut()[START_BLOCK].statements.insert( idx, Statement::new( source_info, - StatementKind::Assign(Box::new((Place::from(cor_ref_local), reborrow))), + StatementKind::Assign(Box::new(( + Place::from(cor_ref_local), + Rvalue::Use(Operand::Move(Place::from(cor_ref_tmp_local))), + ))), ), ); } @@ -341,7 +340,7 @@ fn build_adrop_for_adrop_shim<'tcx>( let mut cor_ptr_local = proxy_ref_local; proxy_ty.find_async_drop_impl_coroutine(tcx, |ty| { if ty != proxy_ty { - let ty_ptr = Ty::new_mut_ptr(tcx, ty); + let ty_ptr = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty); let impl_ptr_place = Place::from(cor_ptr_local) .project_deeper(&[PlaceElem::Deref, PlaceElem::Field(FieldIdx::ZERO, ty_ptr)], tcx); cor_ptr_local = locals.push(LocalDecl::new(ty_ptr, span)); diff --git a/library/core/src/future/async_drop.rs b/library/core/src/future/async_drop.rs index c11ef1569d01e..2f067531f18a4 100644 --- a/library/core/src/future/async_drop.rs +++ b/library/core/src/future/async_drop.rs @@ -52,8 +52,7 @@ pub trait AsyncDrop { /// [ptr::drop_in_place]: crate::ptr::drop_in_place() #[unstable(feature = "async_drop", issue = "126482")] #[lang = "async_drop_in_place"] -// FIXME: accept a reference here instead -pub async unsafe fn async_drop_in_place(_to_drop: *mut T) { +pub async unsafe fn async_drop_in_place(_to_drop: &mut T) { // Code here does not matter - this is replaced by the // real implementation by the compiler. } diff --git a/src/tools/miri/tests/pass/async-drop.rs b/src/tools/miri/tests/pass/async-drop.rs index 4fa84384d9bdd..1226a548b8ca8 100644 --- a/src/tools/miri/tests/pass/async-drop.rs +++ b/src/tools/miri/tests/pass/async-drop.rs @@ -18,7 +18,7 @@ use core::task::{Context, Poll, Waker}; async fn test_async_drop(x: T) { let mut x = mem::MaybeUninit::new(x); - let dtor = pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) }); + let dtor = pin!(unsafe { async_drop_in_place(&mut *x.as_mut_ptr()) }); test_idempotency(dtor).await; } @@ -69,7 +69,7 @@ fn main() { .await; let mut ptr19 = mem::MaybeUninit::new(AsyncInt(19)); - let async_drop_fut = pin!(unsafe { async_drop_in_place(ptr19.as_mut_ptr()) }); + let async_drop_fut = pin!(unsafe { async_drop_in_place(&mut *ptr19.as_mut_ptr()) }); test_idempotency(async_drop_fut).await; let foo = AsyncInt(20); diff --git a/tests/ui/async-await/async-drop/async-drop-initial.rs b/tests/ui/async-await/async-drop/async-drop-initial.rs index 427ed54fa6caa..6234e7fa326b6 100644 --- a/tests/ui/async-await/async-drop/async-drop-initial.rs +++ b/tests/ui/async-await/async-drop/async-drop-initial.rs @@ -11,15 +11,15 @@ //@ edition: 2021 // FIXME(zetanumbers): consider AsyncDestruct::async_drop cleanup tests -use core::future::{async_drop_in_place, AsyncDrop, Future}; +use core::future::{AsyncDrop, Future, async_drop_in_place}; use core::hint::black_box; use core::mem::{self, ManuallyDrop}; -use core::pin::{pin, Pin}; +use core::pin::{Pin, pin}; use core::task::{Context, Poll, Waker}; async fn test_async_drop(x: T, _size: usize) { let mut x = mem::MaybeUninit::new(x); - let dtor = pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) }); + let dtor = pin!(unsafe { async_drop_in_place(&mut *x.as_mut_ptr()) }); // FIXME(zetanumbers): This check fully depends on the layout of // the coroutine state, since async destructor combinators are just @@ -60,10 +60,7 @@ fn main() { let j = 42; test_async_drop(&i, 16).await; test_async_drop(&j, 16).await; - test_async_drop( - AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, - 136, - ).await; + test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, 136).await; test_async_drop(ManuallyDrop::new(AsyncInt(9)), 16).await; let foo = AsyncInt(10); @@ -92,7 +89,7 @@ fn main() { .await; let mut ptr19 = mem::MaybeUninit::new(AsyncInt(19)); - let async_drop_fut = pin!(unsafe { async_drop_in_place(ptr19.as_mut_ptr()) }); + let async_drop_fut = pin!(unsafe { async_drop_in_place(&mut *ptr19.as_mut_ptr()) }); test_idempotency(async_drop_fut).await; let foo = AsyncInt(20); @@ -228,19 +225,13 @@ union AsyncUnion { impl Drop for AsyncUnion { fn drop(&mut self) { - println!( - "AsyncUnion::drop: {}, {}", - unsafe { self.signed }, - unsafe { self.unsigned }, - ); + println!("AsyncUnion::drop: {}, {}", unsafe { self.signed }, unsafe { self.unsigned },); } } impl AsyncDrop for AsyncUnion { async fn drop(self: Pin<&mut Self>) { - println!( - "AsyncUnion::Dropper::poll: {}, {}", - unsafe { self.signed }, - unsafe { self.unsigned }, - ); + println!("AsyncUnion::Dropper::poll: {}, {}", unsafe { self.signed }, unsafe { + self.unsigned + },); } } diff --git a/tests/ui/async-await/async-drop/ex-ice-132103.rs b/tests/ui/async-await/async-drop/ex-ice-132103.rs index 3d32cb14fb061..5becd99d50658 100644 --- a/tests/ui/async-await/async-drop/ex-ice-132103.rs +++ b/tests/ui/async-await/async-drop/ex-ice-132103.rs @@ -6,14 +6,14 @@ #![feature(async_drop)] #![allow(incomplete_features)] -use core::future::{async_drop_in_place, Future}; +use core::future::{Future, async_drop_in_place}; use core::mem::{self}; use core::pin::pin; use core::task::{Context, Waker}; async fn test_async_drop(x: T) { let mut x = mem::MaybeUninit::new(x); - pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) }); + pin!(unsafe { async_drop_in_place(&mut *x.as_mut_ptr()) }); } fn main() { diff --git a/tests/ui/async-await/async-drop/open-drop-error2.rs b/tests/ui/async-await/async-drop/open-drop-error2.rs index b2a7b68190ec1..f54146a2f7aee 100644 --- a/tests/ui/async-await/async-drop/open-drop-error2.rs +++ b/tests/ui/async-await/async-drop/open-drop-error2.rs @@ -3,11 +3,9 @@ #![feature(async_drop)] #![allow(incomplete_features)] -use std::{ - future::{Future, async_drop_in_place}, - pin::pin, - task::Context, -}; +use std::future::{Future, async_drop_in_place}; +use std::pin::pin; +use std::task::Context; fn wrong() -> impl Sized { //~^ ERROR: the size for values of type `str` cannot be known at compilation time @@ -15,7 +13,7 @@ fn wrong() -> impl Sized { } fn weird(context: &mut Context<'_>) { let mut e = wrong(); - let h = unsafe { async_drop_in_place(&raw mut e) }; + let h = unsafe { async_drop_in_place(&mut e) }; let i = pin!(h); i.poll(context); } diff --git a/tests/ui/async-await/async-drop/open-drop-error2.stderr b/tests/ui/async-await/async-drop/open-drop-error2.stderr index e849829b1c78b..2f2a92d33e2c0 100644 --- a/tests/ui/async-await/async-drop/open-drop-error2.stderr +++ b/tests/ui/async-await/async-drop/open-drop-error2.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/open-drop-error2.rs:12:15 + --> $DIR/open-drop-error2.rs:10:15 | LL | fn wrong() -> impl Sized { | ^^^^^^^^^^ doesn't have a size known at compile-time From ca36661da7a608974758c0f4faadc9dc675045b1 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Fri, 3 Apr 2026 19:06:17 +0200 Subject: [PATCH 07/10] bless mir-opt tests --- ...#0}.coroutine_drop_async.0.panic-abort.mir | 53 ++++---- ...0}.coroutine_drop_async.0.panic-unwind.mir | 55 ++++---- ...losure#0}.[Foo;1].MentionedItems.after.mir | 44 +++---- ...losure#0}.coroutine_drop.0.panic-abort.mir | 2 +- ...osure#0}.coroutine_drop.0.panic-unwind.mir | 2 +- ...empty_drop_glue.slice_in_place.Inline.diff | 8 +- .../inline_shims.drop.Inline.panic-abort.diff | 120 ++++++++++-------- ...inline_shims.drop.Inline.panic-unwind.diff | 31 +++-- tests/mir-opt/inline/inline_shims.rs | 3 +- ...rop_bytes.PreCodegen.after.panic-abort.mir | 82 ++++++------ ...op_bytes.PreCodegen.after.panic-unwind.mir | 82 ++++++------ ...p_generic.PreCodegen.after.panic-abort.mir | 84 ++++++------ ..._generic.PreCodegen.after.panic-unwind.mir | 84 ++++++------ ...ace.PreCodegen.after.32bit.panic-abort.mir | 92 +++++++------- ...ce.PreCodegen.after.32bit.panic-unwind.mir | 92 +++++++------- ...ace.PreCodegen.after.64bit.panic-abort.mir | 92 +++++++------- ...ce.PreCodegen.after.64bit.panic-unwind.mir | 92 +++++++------- ...implifyCfg-make_shim.after.panic-abort.mir | 21 +++ ...mplifyCfg-make_shim.after.panic-unwind.mir | 17 +++ ...implifyCfg-make_shim.after.panic-abort.mir | 23 ---- ...mplifyCfg-make_shim.after.panic-unwind.mir | 19 --- tests/mir-opt/retag.rs | 2 +- ...ing;42].AddMovesForPackedDrops.before.mir} | 4 +- ...String].AddMovesForPackedDrops.before.mir} | 4 +- tests/mir-opt/slice_drop_shim.rs | 4 +- ...ec_i32_.AddMovesForPackedDrops.before.mir} | 4 +- tests/mir-opt/unusual_item_types.rs | 2 +- 27 files changed, 581 insertions(+), 537 deletions(-) create mode 100644 tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-abort.mir create mode 100644 tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-unwind.mir delete mode 100644 tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-abort.mir delete mode 100644 tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-unwind.mir rename tests/mir-opt/{slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir => slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir} (91%) rename tests/mir-opt/{slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir => slice_drop_shim.core.ptr-drop_glue.[String].AddMovesForPackedDrops.before.mir} (89%) rename tests/mir-opt/{unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir => unusual_item_types.core.ptr-drop_glue.Vec_i32_.AddMovesForPackedDrops.before.mir} (83%) diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir index 435c1532895ca..0a1cab37427c8 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir @@ -2,34 +2,33 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _2; - debug x => ((*_20).0: T); + debug x => ((*_19).0: T); let mut _0: std::task::Poll<()>; let _3: T; let mut _4: impl std::future::Future; let mut _5: &mut T; let mut _6: std::pin::Pin<&mut T>; let mut _7: &mut T; - let mut _8: *mut T; - let mut _9: std::task::Poll<()>; - let mut _10: &mut std::task::Context<'_>; - let mut _11: &mut impl std::future::Future; - let mut _12: std::pin::Pin<&mut impl std::future::Future>; - let mut _13: isize; - let mut _14: &mut std::task::Context<'_>; - let mut _15: &mut impl std::future::Future; - let mut _16: std::pin::Pin<&mut impl std::future::Future>; - let mut _17: isize; - let mut _18: (); - let mut _19: u32; - let mut _20: &mut {async fn body of a()}; + let mut _8: std::task::Poll<()>; + let mut _9: &mut std::task::Context<'_>; + let mut _10: &mut impl std::future::Future; + let mut _11: std::pin::Pin<&mut impl std::future::Future>; + let mut _12: isize; + let mut _13: &mut std::task::Context<'_>; + let mut _14: &mut impl std::future::Future; + let mut _15: std::pin::Pin<&mut impl std::future::Future>; + let mut _16: isize; + let mut _17: (); + let mut _18: u32; + let mut _19: &mut {async fn body of a()}; scope 1 { - debug x => (((*_20) as variant#4).0: T); + debug x => (((*_19) as variant#4).0: T); } bb0: { - _20 = copy (_1.0: &mut {async fn body of a()}); - _19 = discriminant((*_20)); - switchInt(move _19) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14]; + _19 = copy (_1.0: &mut {async fn body of a()}); + _18 = discriminant((*_19)); + switchInt(move _18) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14]; } bb1: { @@ -45,14 +44,14 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb3: { _0 = Poll::<()>::Pending; - discriminant((*_20)) = 4; + discriminant((*_19)) = 4; return; } bb4: { - StorageLive(_16); - _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); - _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb7, unwind unreachable]; + StorageLive(_15); + _14 = &mut (((*_19) as variant#4).1: impl std::future::Future); + _15 = Pin::<&mut impl Future>::new_unchecked(move _14) -> [return: bb7, unwind unreachable]; } bb5: { @@ -60,13 +59,13 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) } bb6: { - StorageDead(_16); - _17 = discriminant(_9); - switchInt(move _17) -> [0: bb1, 1: bb3, otherwise: bb5]; + StorageDead(_15); + _16 = discriminant(_8); + switchInt(move _16) -> [0: bb1, 1: bb3, otherwise: bb5]; } bb7: { - _9 = as Future>::poll(move _16, move _14) -> [return: bb6, unwind unreachable]; + _8 = as Future>::poll(move _15, move _13) -> [return: bb6, unwind unreachable]; } bb8: { @@ -83,7 +82,7 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) } bb11: { - drop(((*_20).0: T)) -> [return: bb10, unwind unreachable]; + drop(((*_19).0: T)) -> [return: bb10, unwind unreachable]; } bb12: { diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir index 1dc1d08136290..62fbf10356558 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir @@ -2,34 +2,33 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _2; - debug x => ((*_20).0: T); + debug x => ((*_19).0: T); let mut _0: std::task::Poll<()>; let _3: T; let mut _4: impl std::future::Future; let mut _5: &mut T; let mut _6: std::pin::Pin<&mut T>; let mut _7: &mut T; - let mut _8: *mut T; - let mut _9: std::task::Poll<()>; - let mut _10: &mut std::task::Context<'_>; - let mut _11: &mut impl std::future::Future; - let mut _12: std::pin::Pin<&mut impl std::future::Future>; - let mut _13: isize; - let mut _14: &mut std::task::Context<'_>; - let mut _15: &mut impl std::future::Future; - let mut _16: std::pin::Pin<&mut impl std::future::Future>; - let mut _17: isize; - let mut _18: (); - let mut _19: u32; - let mut _20: &mut {async fn body of a()}; + let mut _8: std::task::Poll<()>; + let mut _9: &mut std::task::Context<'_>; + let mut _10: &mut impl std::future::Future; + let mut _11: std::pin::Pin<&mut impl std::future::Future>; + let mut _12: isize; + let mut _13: &mut std::task::Context<'_>; + let mut _14: &mut impl std::future::Future; + let mut _15: std::pin::Pin<&mut impl std::future::Future>; + let mut _16: isize; + let mut _17: (); + let mut _18: u32; + let mut _19: &mut {async fn body of a()}; scope 1 { - debug x => (((*_20) as variant#4).0: T); + debug x => (((*_19) as variant#4).0: T); } bb0: { - _20 = copy (_1.0: &mut {async fn body of a()}); - _19 = discriminant((*_20)); - switchInt(move _19) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19]; + _19 = copy (_1.0: &mut {async fn body of a()}); + _18 = discriminant((*_19)); + switchInt(move _18) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19]; } bb1: { @@ -59,14 +58,14 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb6: { _0 = Poll::<()>::Pending; - discriminant((*_20)) = 4; + discriminant((*_19)) = 4; return; } bb7: { - StorageLive(_16); - _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); - _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb10, unwind: bb15]; + StorageLive(_15); + _14 = &mut (((*_19) as variant#4).1: impl std::future::Future); + _15 = Pin::<&mut impl Future>::new_unchecked(move _14) -> [return: bb10, unwind: bb15]; } bb8: { @@ -74,13 +73,13 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) } bb9: { - StorageDead(_16); - _17 = discriminant(_9); - switchInt(move _17) -> [0: bb1, 1: bb6, otherwise: bb8]; + StorageDead(_15); + _16 = discriminant(_8); + switchInt(move _16) -> [0: bb1, 1: bb6, otherwise: bb8]; } bb10: { - _9 = as Future>::poll(move _16, move _14) -> [return: bb9, unwind: bb3]; + _8 = as Future>::poll(move _15, move _13) -> [return: bb9, unwind: bb3]; } bb11: { @@ -97,11 +96,11 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) } bb14: { - drop(((*_20).0: T)) -> [return: bb13, unwind: bb4]; + drop(((*_19).0: T)) -> [return: bb13, unwind: bb4]; } bb15 (cleanup): { - discriminant((*_20)) = 2; + discriminant((*_19)) = 2; resume; } diff --git a/tests/mir-opt/async_drop_mir_pin.core.future-async_drop-async_drop_in_place-{closure#0}.[Foo;1].MentionedItems.after.mir b/tests/mir-opt/async_drop_mir_pin.core.future-async_drop-async_drop_in_place-{closure#0}.[Foo;1].MentionedItems.after.mir index 062db19216259..d83a51141bd40 100644 --- a/tests/mir-opt/async_drop_mir_pin.core.future-async_drop-async_drop_in_place-{closure#0}.[Foo;1].MentionedItems.after.mir +++ b/tests/mir-opt/async_drop_mir_pin.core.future-async_drop-async_drop_in_place-{closure#0}.[Foo;1].MentionedItems.after.mir @@ -4,7 +4,7 @@ fn async_drop_in_place::{closure#0}(_1: {async fn body of async_drop_in_place<[F yields () { let mut _0: (); - let mut _3: *mut [Foo; 1]; + let mut _3: &mut [Foo; 1]; let mut _4: *mut [Foo; 1]; let mut _5: *mut [Foo]; let mut _6: usize; @@ -18,16 +18,14 @@ yields () let mut _14: std::pin::Pin<&mut Foo>; let mut _15: &mut Foo; let mut _16: *mut Foo; - let mut _17: *mut Foo; - let mut _18: bool; - let mut _19: impl std::future::Future; - let mut _20: &mut Foo; - let mut _21: std::pin::Pin<&mut Foo>; - let mut _22: &mut Foo; - let mut _23: *mut Foo; + let mut _17: bool; + let mut _18: impl std::future::Future; + let mut _19: &mut Foo; + let mut _20: std::pin::Pin<&mut Foo>; + let mut _21: &mut Foo; bb0: { - _3 = move (_1.0: *mut [Foo; 1]); + _3 = move (_1.0: &mut [Foo; 1]); goto -> bb17; } @@ -47,7 +45,7 @@ yields () bb4 (cleanup): { StorageDead(_12); - StorageDead(_19); + StorageDead(_18); _9 = Eq(copy _7, copy _6); switchInt(move _9) -> [0: bb3, otherwise: bb2]; } @@ -60,7 +58,7 @@ yields () } bb6: { - StorageDead(_19); + StorageDead(_18); _11 = Eq(copy _7, copy _6); switchInt(move _11) -> [0: bb5, otherwise: bb1]; } @@ -76,37 +74,35 @@ yields () bb9: { _15 = copy (_14.0: &mut Foo); - _16 = &raw mut (*_15); StorageLive(_12); - _12 = async_drop_in_place::(move _16) -> [return: bb8, unwind: bb4]; + _12 = async_drop_in_place::(move _15) -> [return: bb8, unwind: bb4]; } bb10: { - _17 = &raw mut (*_5)[_7]; + _16 = &raw mut (*_5)[_7]; _7 = Add(move _7, const 1_usize); - _20 = &mut (*_17); - _21 = Pin::<&mut Foo>::new_unchecked(move _20) -> [return: bb14, unwind: bb4]; + _19 = &mut (*_16); + _20 = Pin::<&mut Foo>::new_unchecked(move _19) -> [return: bb14, unwind: bb4]; } bb11: { - _18 = Eq(copy _7, copy _6); - switchInt(move _18) -> [0: bb10, otherwise: bb1]; + _17 = Eq(copy _7, copy _6); + switchInt(move _17) -> [0: bb10, otherwise: bb1]; } bb12: { - StorageDead(_19); + StorageDead(_18); goto -> bb11; } bb13: { - async drop((*_17); poll=_19) -> [return: bb12, unwind: bb4, drop: bb6]; + async drop((*_16); poll=_18) -> [return: bb12, unwind: bb4, drop: bb6]; } bb14: { - _22 = copy (_21.0: &mut Foo); - _23 = &raw mut (*_22); - StorageLive(_19); - _19 = async_drop_in_place::(move _23) -> [return: bb13, unwind: bb4]; + _21 = copy (_20.0: &mut Foo); + StorageLive(_18); + _18 = async_drop_in_place::(move _21) -> [return: bb13, unwind: bb4]; } bb15: { diff --git a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir index 33fbca7f77ed1..f01f48598142c 100644 --- a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}` 0 coroutine_drop -fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12:7}) -> () { +fn main::{closure#0}(_1: &mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12:7}) -> () { let mut _0: (); let mut _2: (); let _3: std::string::String; diff --git a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir index 69e7219af9ff8..64d45346b93c3 100644 --- a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}` 0 coroutine_drop -fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12:7}) -> () { +fn main::{closure#0}(_1: &mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12:7}) -> () { let mut _0: (); let mut _2: (); let _3: std::string::String; diff --git a/tests/mir-opt/inline/inline_empty_drop_glue.slice_in_place.Inline.diff b/tests/mir-opt/inline/inline_empty_drop_glue.slice_in_place.Inline.diff index 68136b0ad2a04..2b5cbe6e44820 100644 --- a/tests/mir-opt/inline/inline_empty_drop_glue.slice_in_place.Inline.diff +++ b/tests/mir-opt/inline/inline_empty_drop_glue.slice_in_place.Inline.diff @@ -5,7 +5,10 @@ debug ptr => _1; let mut _0: (); let mut _2: *mut [char]; -+ scope 1 (inlined drop_in_place::<[char]> - shim(None)) { ++ scope 1 (inlined drop_in_place::<[char]>) { ++ let mut _3: &mut [char]; ++ scope 2 (inlined std::ptr::drop_glue::<[char]> - shim(None)) { ++ } + } bb0: { @@ -15,6 +18,9 @@ - } - - bb1: { ++ StorageLive(_3); ++ _3 = &mut (*_2); ++ StorageDead(_3); StorageDead(_2); return; } diff --git a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff index a74309e16e88b..9c450fd366ffb 100644 --- a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff @@ -8,46 +8,55 @@ let _3: (); let mut _4: *mut std::vec::Vec; let mut _5: *mut std::option::Option; -+ scope 1 (inlined drop_in_place::> - shim(Some(Vec))) { ++ scope 1 (inlined drop_in_place::>) { + let mut _6: &mut std::vec::Vec; -+ let mut _7: (); -+ scope 2 (inlined as Drop>::drop) { -+ let mut _8: *mut [A]; -+ let mut _9: *mut A; -+ let mut _10: usize; -+ scope 3 (inlined Vec::::as_mut_ptr) { -+ scope 4 (inlined alloc::raw_vec::RawVec::::ptr) { -+ scope 5 (inlined alloc::raw_vec::RawVecInner::ptr::) { -+ scope 6 (inlined alloc::raw_vec::RawVecInner::non_null::) { -+ let mut _11: std::ptr::NonNull; -+ scope 7 (inlined std::ptr::Unique::::cast::) { -+ scope 8 (inlined NonNull::::cast::) { -+ scope 9 (inlined NonNull::::as_ptr) { ++ scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Vec))) { ++ let mut _7: &mut std::vec::Vec; ++ let mut _8: (); ++ scope 3 (inlined as Drop>::drop) { ++ let mut _9: *mut [A]; ++ let mut _10: *mut A; ++ let mut _11: usize; ++ scope 4 (inlined Vec::::as_mut_ptr) { ++ scope 5 (inlined alloc::raw_vec::RawVec::::ptr) { ++ scope 6 (inlined alloc::raw_vec::RawVecInner::ptr::) { ++ scope 7 (inlined alloc::raw_vec::RawVecInner::non_null::) { ++ let mut _12: std::ptr::NonNull; ++ scope 8 (inlined std::ptr::Unique::::cast::) { ++ scope 9 (inlined NonNull::::cast::) { ++ scope 10 (inlined NonNull::::as_ptr) { ++ } + } + } ++ scope 11 (inlined std::ptr::Unique::::as_non_null_ptr) { ++ } + } -+ scope 10 (inlined std::ptr::Unique::::as_non_null_ptr) { ++ scope 12 (inlined NonNull::::as_ptr) { + } + } -+ scope 11 (inlined NonNull::::as_ptr) { -+ } + } + } -+ } -+ scope 12 (inlined slice_from_raw_parts_mut::) { -+ scope 13 (inlined std::ptr::from_raw_parts_mut::<[A], A>) { ++ scope 13 (inlined slice_from_raw_parts_mut::) { ++ scope 14 (inlined std::ptr::from_raw_parts_mut::<[A], A>) { ++ } ++ } ++ scope 15 (inlined drop_in_place::<[A]>) { ++ let mut _13: &mut [A]; ++ scope 16 (inlined std::ptr::drop_glue::<[A]> - shim(Some([A]))) { ++ let mut _14: usize; ++ let mut _15: *mut A; ++ let mut _16: bool; ++ } + } -+ } -+ scope 14 (inlined drop_in_place::<[A]> - shim(Some([A]))) { -+ let mut _12: usize; -+ let mut _13: *mut A; -+ let mut _14: bool; + } + } + } -+ scope 15 (inlined drop_in_place::> - shim(Some(Option))) { -+ let mut _15: isize; -+ let mut _16: isize; ++ scope 17 (inlined drop_in_place::>) { ++ let mut _17: &mut std::option::Option; ++ scope 18 (inlined std::ptr::drop_glue::> - shim(Some(Option))) { ++ let mut _18: isize; ++ let mut _19: isize; ++ } + } bb0: { @@ -56,26 +65,31 @@ _4 = copy _1; - _3 = drop_in_place::>(move _4) -> [return: bb1, unwind unreachable]; + StorageLive(_6); -+ StorageLive(_7); + _6 = &mut (*_4); -+ StorageLive(_10); ++ StorageLive(_7); + StorageLive(_8); ++ _7 = copy _6; + StorageLive(_9); + StorageLive(_11); -+ _11 = copy (((((*_6).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); -+ _9 = copy _11 as *mut A (Transmute); -+ StorageDead(_11); -+ _10 = copy ((*_6).1: usize); -+ _8 = *mut [A] from (copy _9, copy _10); -+ StorageDead(_9); ++ StorageLive(_10); + StorageLive(_12); ++ _12 = copy (((((*_7).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); ++ _10 = copy _12 as *mut A (Transmute); ++ StorageDead(_12); ++ _11 = copy ((*_7).1: usize); ++ _9 = *mut [A] from (copy _10, copy _11); ++ StorageDead(_10); + StorageLive(_13); ++ _13 = &mut (*_9); + StorageLive(_14); -+ _12 = const 0_usize; ++ StorageLive(_15); ++ StorageLive(_16); ++ _14 = const 0_usize; + goto -> bb4; } bb1: { ++ StorageDead(_8); + StorageDead(_7); + StorageDead(_6); StorageDead(_4); @@ -83,39 +97,43 @@ StorageLive(_5); _5 = copy _2; - _0 = drop_in_place::>(move _5) -> [return: bb2, unwind unreachable]; -+ StorageLive(_15); -+ _15 = discriminant((*_5)); -+ switchInt(move _15) -> [0: bb5, otherwise: bb6]; ++ StorageLive(_17); ++ _17 = &mut (*_5); ++ StorageLive(_18); ++ _18 = discriminant((*_17)); ++ switchInt(move _18) -> [0: bb5, otherwise: bb6]; } bb2: { ++ StorageDead(_16); ++ StorageDead(_15); + StorageDead(_14); + StorageDead(_13); -+ StorageDead(_12); -+ StorageDead(_8); -+ StorageDead(_10); -+ drop(((*_4).0: alloc::raw_vec::RawVec)) -> [return: bb1, unwind unreachable]; ++ StorageDead(_11); ++ StorageDead(_9); ++ drop(((*_6).0: alloc::raw_vec::RawVec)) -> [return: bb1, unwind unreachable]; + } + + bb3: { -+ _13 = &raw mut (*_8)[_12]; -+ _12 = Add(move _12, const 1_usize); -+ drop((*_13)) -> [return: bb4, unwind unreachable]; ++ _15 = &raw mut (*_13)[_14]; ++ _14 = Add(move _14, const 1_usize); ++ drop((*_15)) -> [return: bb4, unwind unreachable]; + } + + bb4: { -+ _14 = Eq(copy _12, copy _10); -+ switchInt(move _14) -> [0: bb3, otherwise: bb2]; ++ _16 = Eq(copy _14, copy _11); ++ switchInt(move _16) -> [0: bb3, otherwise: bb2]; + } + + bb5: { -+ StorageDead(_15); ++ StorageDead(_18); ++ StorageDead(_17); StorageDead(_5); return; + } + + bb6: { -+ drop((((*_5) as Some).0: B)) -> [return: bb5, unwind unreachable]; ++ drop((((*_17) as Some).0: B)) -> [return: bb5, unwind unreachable]; } } diff --git a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-unwind.diff index 34f89da19f51f..2160cd19652e3 100644 --- a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-unwind.diff @@ -8,37 +8,50 @@ let _3: (); let mut _4: *mut std::vec::Vec; let mut _5: *mut std::option::Option; -+ scope 1 (inlined drop_in_place::> - shim(Some(Option))) { -+ let mut _6: isize; -+ let mut _7: isize; ++ scope 1 (inlined drop_in_place::>) { ++ let mut _6: &mut std::vec::Vec; ++ } ++ scope 2 (inlined drop_in_place::>) { ++ let mut _7: &mut std::option::Option; ++ scope 3 (inlined std::ptr::drop_glue::> - shim(Some(Option))) { ++ let mut _8: isize; ++ let mut _9: isize; ++ } + } bb0: { StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = drop_in_place::>(move _4) -> [return: bb1, unwind continue]; +- _3 = drop_in_place::>(move _4) -> [return: bb1, unwind continue]; ++ StorageLive(_6); ++ _6 = &mut (*_4); ++ _3 = std::ptr::drop_glue::>(move _6) -> [return: bb1, unwind continue]; } bb1: { ++ StorageDead(_6); StorageDead(_4); StorageDead(_3); StorageLive(_5); _5 = copy _2; - _0 = drop_in_place::>(move _5) -> [return: bb2, unwind continue]; -+ StorageLive(_6); -+ _6 = discriminant((*_5)); -+ switchInt(move _6) -> [0: bb2, otherwise: bb3]; ++ StorageLive(_7); ++ _7 = &mut (*_5); ++ StorageLive(_8); ++ _8 = discriminant((*_7)); ++ switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { -+ StorageDead(_6); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_5); return; + } + + bb3: { -+ drop((((*_5) as Some).0: B)) -> [return: bb2, unwind continue]; ++ drop((((*_7) as Some).0: B)) -> [return: bb2, unwind continue]; } } diff --git a/tests/mir-opt/inline/inline_shims.rs b/tests/mir-opt/inline/inline_shims.rs index bd6cdd78157c2..54db4462f8f9a 100644 --- a/tests/mir-opt/inline/inline_shims.rs +++ b/tests/mir-opt/inline/inline_shims.rs @@ -11,7 +11,8 @@ pub fn clone(f: fn(A, B)) -> fn(A, B) { // EMIT_MIR inline_shims.drop.Inline.diff pub fn drop(a: *mut Vec, b: *mut Option) { // CHECK-LABEL: fn drop( - // CHECK: (inlined drop_in_place::> - shim(Some(Option))) + // CHECK: (inlined drop_in_place::>) + // CHECK: (inlined std::ptr::drop_glue::> - shim(Some(Option))) unsafe { std::ptr::drop_in_place(a) } unsafe { std::ptr::drop_in_place(b) } } diff --git a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-abort.mir index 0cd241b4968e2..755bf01cf478a 100644 --- a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-abort.mir @@ -3,61 +3,63 @@ fn drop_bytes(_1: *mut Box<[u8; 1024]>) -> () { debug x => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[u8; 1024]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[u8; 1024]>; - let _4: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[u8; 1024]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[u8; 1024]>; + let _4: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[u8; 1024]>::cast::) { - let mut _3: std::ptr::NonNull; - scope 19 (inlined NonNull::<[u8; 1024]>::cast::) { - scope 20 (inlined NonNull::<[u8; 1024]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[u8; 1024]>::cast::) { + let mut _3: std::ptr::NonNull; + scope 20 (inlined NonNull::<[u8; 1024]>::cast::) { + scope 21 (inlined NonNull::<[u8; 1024]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[u8; 1024]>::as_ptr) { - scope 6 (inlined NonNull::<[u8; 1024]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[u8; 1024]>) { - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[u8; 1024]>::as_ptr) { + scope 7 (inlined NonNull::<[u8; 1024]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[u8; 1024]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[u8; 1024]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[u8; 1024]>) { + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[u8; 1024]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[u8; 1024]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[u8; 1024]>) { + scope 13 (inlined align_of_val_raw::<[u8; 1024]>) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-unwind.mir index 0cd241b4968e2..755bf01cf478a 100644 --- a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_bytes.PreCodegen.after.panic-unwind.mir @@ -3,61 +3,63 @@ fn drop_bytes(_1: *mut Box<[u8; 1024]>) -> () { debug x => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[u8; 1024]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[u8; 1024]>; - let _4: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[u8; 1024]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[u8; 1024]>; + let _4: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[u8; 1024]>::cast::) { - let mut _3: std::ptr::NonNull; - scope 19 (inlined NonNull::<[u8; 1024]>::cast::) { - scope 20 (inlined NonNull::<[u8; 1024]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[u8; 1024]>::cast::) { + let mut _3: std::ptr::NonNull; + scope 20 (inlined NonNull::<[u8; 1024]>::cast::) { + scope 21 (inlined NonNull::<[u8; 1024]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[u8; 1024]>::as_ptr) { - scope 6 (inlined NonNull::<[u8; 1024]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[u8; 1024]>) { - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[u8; 1024]>::as_ptr) { + scope 7 (inlined NonNull::<[u8; 1024]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[u8; 1024]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[u8; 1024]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[u8; 1024]>) { + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[u8; 1024]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[u8; 1024]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[u8; 1024]>) { + scope 13 (inlined align_of_val_raw::<[u8; 1024]>) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-abort.mir index 2b7c334394e07..7f11fbc396bc7 100644 --- a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-abort.mir @@ -3,62 +3,64 @@ fn drop_generic(_1: *mut Box) -> () { debug x => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull; - let _5: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull; + let _5: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::::cast::) { - let mut _4: std::ptr::NonNull; - scope 19 (inlined NonNull::::cast::) { - scope 20 (inlined NonNull::::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::::cast::) { + let mut _4: std::ptr::NonNull; + scope 20 (inlined NonNull::::cast::) { + scope 21 (inlined NonNull::::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::::as_ptr) { - scope 6 (inlined NonNull::::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::) { - let mut _3: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::::as_ptr) { + scope 7 (inlined NonNull::::as_ptr) { } } - scope 9 (inlined size_of_val_raw::) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::) { + let mut _3: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::) { + scope 13 (inlined align_of_val_raw::) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-unwind.mir index 2b7c334394e07..7f11fbc396bc7 100644 --- a/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_box_of_sized.drop_generic.PreCodegen.after.panic-unwind.mir @@ -3,62 +3,64 @@ fn drop_generic(_1: *mut Box) -> () { debug x => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull; - let _5: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull; + let _5: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::::cast::) { - let mut _4: std::ptr::NonNull; - scope 19 (inlined NonNull::::cast::) { - scope 20 (inlined NonNull::::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::::cast::) { + let mut _4: std::ptr::NonNull; + scope 20 (inlined NonNull::::cast::) { + scope 21 (inlined NonNull::::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::::as_ptr) { - scope 6 (inlined NonNull::::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::) { - let mut _3: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::::as_ptr) { + scope 7 (inlined NonNull::::as_ptr) { } } - scope 9 (inlined size_of_val_raw::) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::) { + let mut _3: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::) { + scope 13 (inlined align_of_val_raw::) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir index cb6a7743d578d..bff261b5c5f66 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir @@ -3,66 +3,68 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { debug ptr => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[T]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[T]>; - let mut _3: *mut [T]; - let mut _4: *const [T]; - let _9: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[T]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[T]>; + let mut _3: *mut [T]; + let mut _4: *const [T]; + let _9: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[T]>::cast::) { - let mut _8: std::ptr::NonNull; - scope 19 (inlined NonNull::<[T]>::cast::) { - let mut _7: *mut u8; - scope 20 (inlined NonNull::<[T]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[T]>::cast::) { + let mut _8: std::ptr::NonNull; + scope 20 (inlined NonNull::<[T]>::cast::) { + let mut _7: *mut u8; + scope 21 (inlined NonNull::<[T]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[T]>::as_ptr) { - scope 6 (inlined NonNull::<[T]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[T]>) { - let mut _5: usize; - let mut _6: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[T]>::as_ptr) { + scope 7 (inlined NonNull::<[T]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[T]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[T]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[T]>) { + let mut _5: usize; + let mut _6: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[T]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[T]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[T]>) { + scope 13 (inlined align_of_val_raw::<[T]>) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir index cb6a7743d578d..bff261b5c5f66 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir @@ -3,66 +3,68 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { debug ptr => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[T]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[T]>; - let mut _3: *mut [T]; - let mut _4: *const [T]; - let _9: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[T]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[T]>; + let mut _3: *mut [T]; + let mut _4: *const [T]; + let _9: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[T]>::cast::) { - let mut _8: std::ptr::NonNull; - scope 19 (inlined NonNull::<[T]>::cast::) { - let mut _7: *mut u8; - scope 20 (inlined NonNull::<[T]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[T]>::cast::) { + let mut _8: std::ptr::NonNull; + scope 20 (inlined NonNull::<[T]>::cast::) { + let mut _7: *mut u8; + scope 21 (inlined NonNull::<[T]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[T]>::as_ptr) { - scope 6 (inlined NonNull::<[T]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[T]>) { - let mut _5: usize; - let mut _6: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[T]>::as_ptr) { + scope 7 (inlined NonNull::<[T]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[T]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[T]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[T]>) { + let mut _5: usize; + let mut _6: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[T]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[T]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[T]>) { + scope 13 (inlined align_of_val_raw::<[T]>) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir index cb6a7743d578d..bff261b5c5f66 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir @@ -3,66 +3,68 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { debug ptr => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[T]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[T]>; - let mut _3: *mut [T]; - let mut _4: *const [T]; - let _9: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[T]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[T]>; + let mut _3: *mut [T]; + let mut _4: *const [T]; + let _9: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[T]>::cast::) { - let mut _8: std::ptr::NonNull; - scope 19 (inlined NonNull::<[T]>::cast::) { - let mut _7: *mut u8; - scope 20 (inlined NonNull::<[T]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[T]>::cast::) { + let mut _8: std::ptr::NonNull; + scope 20 (inlined NonNull::<[T]>::cast::) { + let mut _7: *mut u8; + scope 21 (inlined NonNull::<[T]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[T]>::as_ptr) { - scope 6 (inlined NonNull::<[T]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[T]>) { - let mut _5: usize; - let mut _6: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[T]>::as_ptr) { + scope 7 (inlined NonNull::<[T]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[T]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[T]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[T]>) { + let mut _5: usize; + let mut _6: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[T]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[T]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[T]>) { + scope 13 (inlined align_of_val_raw::<[T]>) { + } } } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir index cb6a7743d578d..bff261b5c5f66 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir @@ -3,66 +3,68 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { debug ptr => _1; let mut _0: (); - scope 1 (inlined drop_in_place::> - shim(Some(Box<[T]>))) { - scope 2 (inlined as Drop>::drop) { - let _2: std::ptr::NonNull<[T]>; - let mut _3: *mut [T]; - let mut _4: *const [T]; - let _9: (); - scope 3 { + scope 1 (inlined drop_in_place::>) { + scope 2 (inlined std::ptr::drop_glue::> - shim(Some(Box<[T]>))) { + scope 3 (inlined as Drop>::drop) { + let _2: std::ptr::NonNull<[T]>; + let mut _3: *mut [T]; + let mut _4: *const [T]; + let _9: (); scope 4 { - scope 17 (inlined Layout::size) { - } - scope 18 (inlined std::ptr::Unique::<[T]>::cast::) { - let mut _8: std::ptr::NonNull; - scope 19 (inlined NonNull::<[T]>::cast::) { - let mut _7: *mut u8; - scope 20 (inlined NonNull::<[T]>::as_ptr) { + scope 5 { + scope 18 (inlined Layout::size) { + } + scope 19 (inlined std::ptr::Unique::<[T]>::cast::) { + let mut _8: std::ptr::NonNull; + scope 20 (inlined NonNull::<[T]>::cast::) { + let mut _7: *mut u8; + scope 21 (inlined NonNull::<[T]>::as_ptr) { + } } } - } - scope 21 (inlined as From>>::from) { - scope 22 (inlined std::ptr::Unique::::as_non_null_ptr) { + scope 22 (inlined as From>>::from) { + scope 23 (inlined std::ptr::Unique::::as_non_null_ptr) { + } } - } - scope 23 (inlined ::deallocate) { - scope 24 (inlined std::alloc::Global::deallocate_impl) { - scope 25 (inlined std::alloc::Global::deallocate_impl_runtime) { - scope 26 (inlined Layout::size) { - } - scope 27 (inlined alloc::alloc::dealloc_nonnull) { - scope 28 (inlined Layout::size) { + scope 24 (inlined ::deallocate) { + scope 25 (inlined std::alloc::Global::deallocate_impl) { + scope 26 (inlined std::alloc::Global::deallocate_impl_runtime) { + scope 27 (inlined Layout::size) { } - scope 29 (inlined Layout::alignment) { + scope 28 (inlined alloc::alloc::dealloc_nonnull) { + scope 29 (inlined Layout::size) { + } + scope 30 (inlined Layout::alignment) { + } } } } } } - } - scope 5 (inlined std::ptr::Unique::<[T]>::as_ptr) { - scope 6 (inlined NonNull::<[T]>::as_ptr) { - } - } - scope 7 (inlined Layout::for_value_raw::<[T]>) { - let mut _5: usize; - let mut _6: std::mem::Alignment; - scope 8 { - scope 16 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + scope 6 (inlined std::ptr::Unique::<[T]>::as_ptr) { + scope 7 (inlined NonNull::<[T]>::as_ptr) { } } - scope 9 (inlined size_of_val_raw::<[T]>) { - } - scope 10 (inlined std::mem::Alignment::of_val_raw::<[T]>) { - scope 11 { - scope 13 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { - scope 14 (inlined core::ub_checks::check_language_ub) { - scope 15 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined Layout::for_value_raw::<[T]>) { + let mut _5: usize; + let mut _6: std::mem::Alignment; + scope 9 { + scope 17 (inlined #[track_caller] Layout::from_size_alignment_unchecked) { + } + } + scope 10 (inlined size_of_val_raw::<[T]>) { + } + scope 11 (inlined std::mem::Alignment::of_val_raw::<[T]>) { + scope 12 { + scope 14 (inlined #[track_caller] std::mem::Alignment::new_unchecked) { + scope 15 (inlined core::ub_checks::check_language_ub) { + scope 16 (inlined core::ub_checks::check_language_ub::runtime) { + } } } } - } - scope 12 (inlined align_of_val_raw::<[T]>) { + scope 13 (inlined align_of_val_raw::<[T]>) { + } } } } diff --git a/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-abort.mir b/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-abort.mir new file mode 100644 index 0000000000000..1394d21f9fe31 --- /dev/null +++ b/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-abort.mir @@ -0,0 +1,21 @@ +// MIR for `std::ptr::drop_glue` after SimplifyCfg-make_shim + +fn std::ptr::drop_glue(_1: &mut Test) -> () { + let mut _0: (); + let mut _2: &mut Test; + let mut _3: (); + + bb0: { + Retag([fn entry] _1); + _2 = &mut (*_1); + _3 = ::drop(move _2) -> [return: bb2, unwind: bb1]; + } + + bb1 (cleanup): { + resume; + } + + bb2: { + return; + } +} diff --git a/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-unwind.mir b/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-unwind.mir new file mode 100644 index 0000000000000..55c8f842f3a56 --- /dev/null +++ b/tests/mir-opt/retag.core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.panic-unwind.mir @@ -0,0 +1,17 @@ +// MIR for `std::ptr::drop_glue` after SimplifyCfg-make_shim + +fn std::ptr::drop_glue(_1: &mut Test) -> () { + let mut _0: (); + let mut _2: &mut Test; + let mut _3: (); + + bb0: { + Retag([fn entry] _1); + _2 = &mut (*_1); + _3 = ::drop(move _2) -> [return: bb1, unwind continue]; + } + + bb1: { + return; + } +} diff --git a/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-abort.mir b/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-abort.mir deleted file mode 100644 index 8e47aabb9b9f3..0000000000000 --- a/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-abort.mir +++ /dev/null @@ -1,23 +0,0 @@ -// MIR for `std::ptr::drop_in_place` after SimplifyCfg-make_shim - -fn drop_in_place(_1: *mut Test) -> () { - let mut _0: (); - let mut _2: &mut Test; - let mut _3: &mut Test; - let mut _4: (); - - bb0: { - _2 = &mut (*_1); - Retag([fn entry] _2); - _3 = &mut (*_2); - _4 = ::drop(move _3) -> [return: bb2, unwind: bb1]; - } - - bb1 (cleanup): { - resume; - } - - bb2: { - return; - } -} diff --git a/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-unwind.mir b/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-unwind.mir deleted file mode 100644 index 2457405d9969a..0000000000000 --- a/tests/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.panic-unwind.mir +++ /dev/null @@ -1,19 +0,0 @@ -// MIR for `std::ptr::drop_in_place` after SimplifyCfg-make_shim - -fn drop_in_place(_1: *mut Test) -> () { - let mut _0: (); - let mut _2: &mut Test; - let mut _3: &mut Test; - let mut _4: (); - - bb0: { - _2 = &mut (*_1); - Retag([fn entry] _2); - _3 = &mut (*_2); - _4 = ::drop(move _3) -> [return: bb1, unwind continue]; - } - - bb1: { - return; - } -} diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index 001c559913839..0455043f5bdca 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -20,7 +20,7 @@ impl Test { } } -// EMIT_MIR core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir +// EMIT_MIR core.ptr-drop_glue.Test.SimplifyCfg-make_shim.after.mir impl Drop for Test { fn drop(&mut self) {} 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_glue.[String;42].AddMovesForPackedDrops.before.mir similarity index 91% rename from tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir rename to tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir index ed3f4788cea7d..66591dcc91df2 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_glue.[String;42].AddMovesForPackedDrops.before.mir @@ -1,6 +1,6 @@ -// MIR for `std::ptr::drop_in_place` before AddMovesForPackedDrops +// MIR for `std::ptr::drop_glue` before AddMovesForPackedDrops -fn drop_in_place(_1: *mut [String; 42]) -> () { +fn std::ptr::drop_glue(_1: &mut [String; 42]) -> () { let mut _0: (); let mut _2: *mut [std::string::String; 42]; let mut _3: *mut [std::string::String]; diff --git a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir b/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String].AddMovesForPackedDrops.before.mir similarity index 89% rename from tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir rename to tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String].AddMovesForPackedDrops.before.mir index bee671af6dfea..3c8da0d94bff0 100644 --- a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String].AddMovesForPackedDrops.before.mir @@ -1,6 +1,6 @@ -// MIR for `std::ptr::drop_in_place` before AddMovesForPackedDrops +// MIR for `std::ptr::drop_glue` before AddMovesForPackedDrops -fn drop_in_place(_1: *mut [String]) -> () { +fn std::ptr::drop_glue(_1: &mut [String]) -> () { let mut _0: (); let mut _2: usize; let mut _3: usize; diff --git a/tests/mir-opt/slice_drop_shim.rs b/tests/mir-opt/slice_drop_shim.rs index f34c34855a169..6303001965bc5 100644 --- a/tests/mir-opt/slice_drop_shim.rs +++ b/tests/mir-opt/slice_drop_shim.rs @@ -4,8 +4,8 @@ // so this test only produces MIR for the drop_in_place we're looking for // if we use -Clink-dead-code. -// EMIT_MIR core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir -// EMIT_MIR core.ptr-drop_in_place.[String;42].AddMovesForPackedDrops.before.mir +// EMIT_MIR core.ptr-drop_glue.[String].AddMovesForPackedDrops.before.mir +// EMIT_MIR core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir fn main() { let _fn = std::ptr::drop_in_place::<[String]> as unsafe fn(_); let _fn = std::ptr::drop_in_place::<[String; 42]> as unsafe fn(_); diff --git a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir b/tests/mir-opt/unusual_item_types.core.ptr-drop_glue.Vec_i32_.AddMovesForPackedDrops.before.mir similarity index 83% rename from tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir rename to tests/mir-opt/unusual_item_types.core.ptr-drop_glue.Vec_i32_.AddMovesForPackedDrops.before.mir index 1bdb1c1debdbb..d249e573a78b7 100644 --- a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/unusual_item_types.core.ptr-drop_glue.Vec_i32_.AddMovesForPackedDrops.before.mir @@ -1,6 +1,6 @@ -// MIR for `std::ptr::drop_in_place` before AddMovesForPackedDrops +// MIR for `std::ptr::drop_glue` before AddMovesForPackedDrops -fn drop_in_place(_1: *mut Vec) -> () { +fn std::ptr::drop_glue(_1: &mut Vec) -> () { let mut _0: (); let mut _2: &mut std::vec::Vec; let mut _3: (); diff --git a/tests/mir-opt/unusual_item_types.rs b/tests/mir-opt/unusual_item_types.rs index 2f05981e812eb..3dc41807812fc 100644 --- a/tests/mir-opt/unusual_item_types.rs +++ b/tests/mir-opt/unusual_item_types.rs @@ -22,7 +22,7 @@ enum E { V = 5, } -// EMIT_MIR core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir +// EMIT_MIR core.ptr-drop_glue.Vec_i32_.AddMovesForPackedDrops.before.mir pub fn main() { let f = Test::X as fn(usize) -> Test; let v = Vec::::new(); From 1350a74f0c55b5144e990d4968ac9ff2210e3684 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 6 Apr 2026 21:42:29 +0200 Subject: [PATCH 08/10] bless `codegen-units` tests --- .../item-collection/drop-glue-eager.rs | 8 ++++---- .../item-collection/drop-glue-noop.rs | 4 +++- .../item-collection/drop_in_place_intrinsic.rs | 9 +++++---- .../item-collection/generic-drop-glue.rs | 12 ++++++------ .../item-collection/non-generic-closures.rs | 4 ++-- .../item-collection/non-generic-drop-glue.rs | 4 ++-- .../item-collection/transitive-drop-glue.rs | 18 +++++++++--------- .../item-collection/tuple-drop-glue.rs | 8 ++++---- .../codegen-units/item-collection/unsizing.rs | 2 +- .../partitioning/extern-drop-glue.rs | 6 +++--- .../partitioning/local-drop-glue.rs | 8 ++++---- .../partitioning/vtable-through-const.rs | 2 +- 12 files changed, 44 insertions(+), 41 deletions(-) diff --git a/tests/codegen-units/item-collection/drop-glue-eager.rs b/tests/codegen-units/item-collection/drop-glue-eager.rs index cc0ea701e66f3..c5f8928c283c2 100644 --- a/tests/codegen-units/item-collection/drop-glue-eager.rs +++ b/tests/codegen-units/item-collection/drop-glue-eager.rs @@ -3,7 +3,7 @@ //@ compile-flags:-Clink-dead-code //@ compile-flags:--crate-type=lib -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(StructWithDrop)) +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(StructWithDrop)) struct StructWithDrop { x: i32, } @@ -17,7 +17,7 @@ struct StructNoDrop { x: i32, } -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(EnumWithDrop)) +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(EnumWithDrop)) enum EnumWithDrop { A(i32), } @@ -37,14 +37,14 @@ impl<'a> Drop for StructWithDropAndLt<'a> { fn drop(&mut self) {} } -//~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithDropAndLt<'_>)) +//~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructWithDropAndLt<'_>)) struct StructWithDropAndLt<'a> { x: &'a i32, } // Make sure we don't ICE when checking impossible predicates for the struct. // Regression test for . -//~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithLtAndPredicate<'_>)) +//~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructWithLtAndPredicate<'_>)) struct StructWithLtAndPredicate<'a: 'a> { x: &'a i32, } diff --git a/tests/codegen-units/item-collection/drop-glue-noop.rs b/tests/codegen-units/item-collection/drop-glue-noop.rs index 604ba883bb289..4157e6e20c63c 100644 --- a/tests/codegen-units/item-collection/drop-glue-noop.rs +++ b/tests/codegen-units/item-collection/drop-glue-noop.rs @@ -8,6 +8,8 @@ pub fn start(_: isize, _: *const *const u8) -> isize { // No item produced for this, it's a no-op drop and so is removed. unsafe { + // FIXME: is not removed on opt-level=0 anymore... + //~ MONO_ITEM fn std::ptr::drop_in_place:: @@ drop_glue_noop-cgu.0[External] std::ptr::drop_in_place::(&mut 0); } @@ -16,7 +18,7 @@ pub fn start(_: isize, _: *const *const u8) -> isize { // instantiation-through-vtable.rs) because we special case null pointer for drop glue since // #122662. // - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(None) @@ drop_glue_noop-cgu.0[External] + //~ MONO_ITEM fn std::ptr::drop_in_place:: @@ drop_glue_noop-cgu.0[External] std::ptr::drop_in_place:: as unsafe fn(*mut u64); 0 diff --git a/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs b/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs index ef8f916539395..0957d69b94836 100644 --- a/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs +++ b/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs @@ -4,18 +4,17 @@ #![crate_type = "lib"] -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(StructWithDtor)) @@ drop_in_place_intrinsic-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(StructWithDtor)) @@ drop_in_place_intrinsic-cgu.0[Internal] struct StructWithDtor(u32); impl Drop for StructWithDtor { //~ MONO_ITEM fn ::drop fn drop(&mut self) {} } - //~ MONO_ITEM fn start #[no_mangle] pub fn start(_: isize, _: *const *const u8) -> isize { - //~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor; 2]> - shim(Some([StructWithDtor; 2])) @@ drop_in_place_intrinsic-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<[StructWithDtor; 2]> - shim(Some([StructWithDtor; 2])) @@ drop_in_place_intrinsic-cgu.0[Internal] let x = [StructWithDtor(0), StructWithDtor(1)]; drop_slice_in_place(&x); @@ -26,10 +25,12 @@ pub fn start(_: isize, _: *const *const u8) -> isize { //~ MONO_ITEM fn drop_slice_in_place fn drop_slice_in_place(x: &[StructWithDtor]) { unsafe { + // FIXME: drop_in_place isn't an intrinsic.... // This is the interesting thing in this test case: Normally we would // not have drop-glue for the unsized [StructWithDtor]. This has to be // generated though when the drop_in_place() intrinsic is used. - //~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor]> - shim(Some([StructWithDtor])) @@ drop_in_place_intrinsic-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<[StructWithDtor]> - shim(Some([StructWithDtor])) @@ drop_in_place_intrinsic-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor]> @@ drop_in_place_intrinsic-cgu.0[External] ::std::ptr::drop_in_place(x as *const _ as *mut [StructWithDtor]); } } diff --git a/tests/codegen-units/item-collection/generic-drop-glue.rs b/tests/codegen-units/item-collection/generic-drop-glue.rs index b4c6c231e3d62..beadf9ac0ae3d 100644 --- a/tests/codegen-units/item-collection/generic-drop-glue.rs +++ b/tests/codegen-units/item-collection/generic-drop-glue.rs @@ -35,7 +35,7 @@ enum EnumNoDrop { struct NonGenericNoDrop(#[allow(dead_code)] i32); struct NonGenericWithDrop(#[allow(dead_code)] i32); -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(NonGenericWithDrop)) @@ generic_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(NonGenericWithDrop)) @@ generic_drop_glue-cgu.0[Internal] impl Drop for NonGenericWithDrop { //~ MONO_ITEM fn ::drop @@ -45,11 +45,11 @@ impl Drop for NonGenericWithDrop { //~ MONO_ITEM fn start #[no_mangle] pub fn start(_: isize, _: *const *const u8) -> isize { - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructWithDrop)) @@ generic_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = StructWithDrop { x: 0i8, y: 'a' }.x; - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithDrop<&str, NonGenericNoDrop>)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructWithDrop<&str, NonGenericNoDrop>)) @@ generic_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y; @@ -58,17 +58,17 @@ pub fn start(_: isize, _: *const *const u8) -> isize { // This is supposed to generate drop-glue because it contains a field that // needs to be dropped. - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructNoDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructNoDrop)) @@ generic_drop_glue-cgu.0[Internal] let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y; - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = match EnumWithDrop::A::(0) { EnumWithDrop::A(x) => x, EnumWithDrop::B(x) => x as i32, }; - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = match EnumWithDrop::B::(1.0) { EnumWithDrop::A(x) => x, diff --git a/tests/codegen-units/item-collection/non-generic-closures.rs b/tests/codegen-units/item-collection/non-generic-closures.rs index 2d9c461e6fd2d..faa5c9c0163d8 100644 --- a/tests/codegen-units/item-collection/non-generic-closures.rs +++ b/tests/codegen-units/item-collection/non-generic-closures.rs @@ -43,8 +43,8 @@ fn assigned_to_variable_executed_directly() { //~ MONO_ITEM fn with_drop @@ non_generic_closures-cgu.0[External] fn with_drop(v: PresentDrop) { //~ MONO_ITEM fn with_drop::{closure#0} @@ non_generic_closures-cgu.0[External] - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(PresentDrop)) @@ non_generic_closures-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::<{closure@TEST_PATH:49:14: 49:24}> - shim(Some({closure@TEST_PATH:49:14: 49:24})) @@ non_generic_closures-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(PresentDrop)) @@ non_generic_closures-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<{closure@TEST_PATH:49:14: 49:24}> - shim(Some({closure@TEST_PATH:49:14: 49:24})) @@ non_generic_closures-cgu.0[Internal] let _f = |a: usize| { let _ = a + 2; diff --git a/tests/codegen-units/item-collection/non-generic-drop-glue.rs b/tests/codegen-units/item-collection/non-generic-drop-glue.rs index d83336f4d78d9..750c1eb15c323 100644 --- a/tests/codegen-units/item-collection/non-generic-drop-glue.rs +++ b/tests/codegen-units/item-collection/non-generic-drop-glue.rs @@ -4,7 +4,7 @@ #![deny(dead_code)] #![crate_type = "lib"] -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(StructWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(StructWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] struct StructWithDrop { x: i32, } @@ -18,7 +18,7 @@ struct StructNoDrop { x: i32, } -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(EnumWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(EnumWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] enum EnumWithDrop { A(i32), } diff --git a/tests/codegen-units/item-collection/transitive-drop-glue.rs b/tests/codegen-units/item-collection/transitive-drop-glue.rs index 844d74526f413..4a38059067f32 100644 --- a/tests/codegen-units/item-collection/transitive-drop-glue.rs +++ b/tests/codegen-units/item-collection/transitive-drop-glue.rs @@ -4,11 +4,11 @@ #![deny(dead_code)] #![crate_type = "lib"] -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Root)) @@ transitive_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Root)) @@ transitive_drop_glue-cgu.0[Internal] struct Root(#[allow(dead_code)] Intermediate); -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Intermediate)) @@ transitive_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Intermediate)) @@ transitive_drop_glue-cgu.0[Internal] struct Intermediate(#[allow(dead_code)] Leaf); -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Leaf)) @@ transitive_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Leaf)) @@ transitive_drop_glue-cgu.0[Internal] struct Leaf; impl Drop for Leaf { @@ -29,15 +29,15 @@ impl Drop for LeafGen { pub fn start(_: isize, _: *const *const u8) -> isize { let _ = Root(Intermediate(Leaf)); - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = RootGen(IntermediateGen(LeafGen(0u32))); - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] //~ MONO_ITEM fn as std::ops::Drop>::drop let _ = RootGen(IntermediateGen(LeafGen(0i16))); diff --git a/tests/codegen-units/item-collection/tuple-drop-glue.rs b/tests/codegen-units/item-collection/tuple-drop-glue.rs index 4380735597a4e..60b42eadf0cf6 100644 --- a/tests/codegen-units/item-collection/tuple-drop-glue.rs +++ b/tests/codegen-units/item-collection/tuple-drop-glue.rs @@ -4,7 +4,7 @@ #![deny(dead_code)] #![crate_type = "lib"] -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Dropped)) @@ tuple_drop_glue-cgu.0[Internal] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Dropped)) @@ tuple_drop_glue-cgu.0[Internal] struct Dropped; impl Drop for Dropped { @@ -15,11 +15,11 @@ impl Drop for Dropped { //~ MONO_ITEM fn start #[no_mangle] pub fn start(_: isize, _: *const *const u8) -> isize { - //~ MONO_ITEM fn std::ptr::drop_in_place::<(u32, Dropped)> - shim(Some((u32, Dropped))) @@ tuple_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<(u32, Dropped)> - shim(Some((u32, Dropped))) @@ tuple_drop_glue-cgu.0[Internal] let x = (0u32, Dropped); - //~ MONO_ITEM fn std::ptr::drop_in_place::<(i16, (Dropped, bool))> - shim(Some((i16, (Dropped, bool)))) @@ tuple_drop_glue-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place::<(Dropped, bool)> - shim(Some((Dropped, bool))) @@ tuple_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<(i16, (Dropped, bool))> - shim(Some((i16, (Dropped, bool)))) @@ tuple_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue::<(Dropped, bool)> - shim(Some((Dropped, bool))) @@ tuple_drop_glue-cgu.0[Internal] let x = (0i16, (Dropped, true)); 0 diff --git a/tests/codegen-units/item-collection/unsizing.rs b/tests/codegen-units/item-collection/unsizing.rs index b751d2153a949..6973dd96220c5 100644 --- a/tests/codegen-units/item-collection/unsizing.rs +++ b/tests/codegen-units/item-collection/unsizing.rs @@ -79,7 +79,7 @@ pub fn start(_: isize, _: *const *const u8) -> isize { // with drop let droppable = &PresentDrop; //~ MONO_ITEM fn ::drop @@ unsizing-cgu.0[Internal] - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(PresentDrop)) @@ unsizing-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(PresentDrop)) @@ unsizing-cgu.0[Internal] //~ MONO_ITEM fn ::foo let droppable = droppable as &dyn Trait; diff --git a/tests/codegen-units/partitioning/extern-drop-glue.rs b/tests/codegen-units/partitioning/extern-drop-glue.rs index 45e5393b33d8c..4c4817295b6f2 100644 --- a/tests/codegen-units/partitioning/extern-drop-glue.rs +++ b/tests/codegen-units/partitioning/extern-drop-glue.rs @@ -9,13 +9,13 @@ extern crate cgu_extern_drop_glue; // This test checks that drop glue is generated, even for types not defined in this crate, and all // drop glue is put in the fallback CGU. -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(cgu_extern_drop_glue::Struct)) @@ extern_drop_glue-fallback.cgu[External] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(cgu_extern_drop_glue::Struct)) @@ extern_drop_glue-fallback.cgu[External] struct LocalStruct(cgu_extern_drop_glue::Struct); //~ MONO_ITEM fn user @@ extern_drop_glue[External] pub fn user() { - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] let _ = LocalStruct(cgu_extern_drop_glue::Struct(0)); } @@ -26,7 +26,7 @@ pub mod mod1 { //~ MONO_ITEM fn mod1::user @@ extern_drop_glue-mod1[External] pub fn user() { - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(mod1::LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(mod1::LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] let _ = LocalStruct(cgu_extern_drop_glue::Struct(0)); } } diff --git a/tests/codegen-units/partitioning/local-drop-glue.rs b/tests/codegen-units/partitioning/local-drop-glue.rs index 2ece7f0fa204a..4c7d84573ec6a 100644 --- a/tests/codegen-units/partitioning/local-drop-glue.rs +++ b/tests/codegen-units/partitioning/local-drop-glue.rs @@ -7,7 +7,7 @@ // glue is put in the fallback CGU. // This is rather similar to extern-drop-glue.rs. -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Struct)) @@ local_drop_glue-fallback.cgu[External] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Struct)) @@ local_drop_glue-fallback.cgu[External] pub struct Struct { _a: u32, } @@ -17,7 +17,7 @@ impl Drop for Struct { fn drop(&mut self) {} } -//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Outer)) @@ local_drop_glue-fallback.cgu[External] +//~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(Outer)) @@ local_drop_glue-fallback.cgu[External] pub struct Outer { _a: Struct, } @@ -30,10 +30,10 @@ pub fn user() { pub mod mod1 { use super::Struct; - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(mod1::Struct2)) @@ local_drop_glue-fallback.cgu[External] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(mod1::Struct2)) @@ local_drop_glue-fallback.cgu[External] struct Struct2 { _a: Struct, - //~ MONO_ITEM fn std::ptr::drop_in_place::<(u32, Struct)> - shim(Some((u32, Struct))) @@ local_drop_glue-fallback.cgu[External] + //~ MONO_ITEM fn std::ptr::drop_glue::<(u32, Struct)> - shim(Some((u32, Struct))) @@ local_drop_glue-fallback.cgu[External] _b: (u32, Struct), } diff --git a/tests/codegen-units/partitioning/vtable-through-const.rs b/tests/codegen-units/partitioning/vtable-through-const.rs index 7a070728843c7..49bbed5b1c4de 100644 --- a/tests/codegen-units/partitioning/vtable-through-const.rs +++ b/tests/codegen-units/partitioning/vtable-through-const.rs @@ -74,7 +74,7 @@ mod mod1 { //~ MONO_ITEM fn main @@ vtable_through_const[External] pub fn main() { //~ MONO_ITEM fn ::drop @@ vtable_through_const-fallback.cgu[External] - //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(mod1::NeedsDrop)) @@ vtable_through_const-fallback.cgu[External] + //~ MONO_ITEM fn std::ptr::drop_glue:: - shim(Some(mod1::NeedsDrop)) @@ vtable_through_const-fallback.cgu[External] // Since Trait1::do_something() is instantiated via its default implementation, // it is considered a generic and is instantiated here only because it is From e3aaa43b2e27fb219510a974fcc8acf11bda1bcf Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Wed, 8 Apr 2026 14:59:29 +0200 Subject: [PATCH 09/10] make `NonNull::drop_in_place` call `drop_glue` directly --- library/core/src/ptr/mod.rs | 2 +- library/core/src/ptr/non_null.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 4e6b952dd727e..b2297c862289f 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -823,7 +823,7 @@ where /// Helper function for `drop_in_place`. #[lang = "drop_glue"] -const unsafe fn drop_glue(_: &mut T) +pub(crate) const unsafe fn drop_glue(_: &mut T) where T: [const] Destruct, { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 90f27ca8bdb0a..cab43b3cd6b1a 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1119,12 +1119,12 @@ impl NonNull { #[inline(always)] #[stable(feature = "non_null_convenience", since = "1.80.0")] #[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")] - pub const unsafe fn drop_in_place(self) + pub const unsafe fn drop_in_place(mut self) where T: [const] Destruct, { // SAFETY: the caller must uphold the safety contract for `drop_in_place`. - unsafe { ptr::drop_in_place(self.as_ptr()) } + unsafe { ptr::drop_glue(self.as_mut()) } } /// Overwrites a memory location with the given value without reading or From 2ae092a0c8c5991f2568a1d7f771bd66d2330ca0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 11 Apr 2026 21:35:23 -0700 Subject: [PATCH 10/10] Have arrays' `drop_glue` just unsize and call the slice version --- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 44 +++++++++++- tests/codegen-llvm/array-drop-glue.rs | 67 +++++++++++++++++++ ...ring;42].AddMovesForPackedDrops.before.mir | 54 +-------------- 4 files changed, 113 insertions(+), 54 deletions(-) create mode 100644 tests/codegen-llvm/array-drop-glue.rs diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index f58545149cec2..2bd1b17f5245d 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -292,7 +292,7 @@ impl<'tcx> InstanceKind<'tcx> { use rustc_hir::definitions::DefPathData; let def_id = match *self { ty::InstanceKind::Item(def) => def, - ty::InstanceKind::DropGlue(_, Some(_)) => return false, + ty::InstanceKind::DropGlue(_, Some(ty)) => return ty.is_array(), ty::InstanceKind::AsyncDropGlueCtorShim(_, ty) => return ty.is_coroutine(), ty::InstanceKind::FutureDropPollShim(_, _, _) => return false, ty::InstanceKind::AsyncDropGlue(_, _) => return false, diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 1af2d7f230f9f..9cfab42e71639 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -332,18 +332,58 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) let block = |blocks: &mut IndexVec<_, _>, kind| { blocks.push(BasicBlockData::new(Some(Terminator { source_info, kind }), false)) }; - block(&mut blocks, TerminatorKind::Goto { target: return_block }); + if ty.is_some() { + block(&mut blocks, TerminatorKind::Goto { target: return_block }); + } block(&mut blocks, TerminatorKind::Return); let source = MirSource::from_instance(ty::InstanceKind::DropGlue(def_id, ty)); let mut body = new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); + let Some(ty) = ty else { + return body; + }; + // The first argument (index 0), but add 1 for the return value. let dropee_ptr = Place::from(Local::new(1 + 0)); dropee_emit_retag(tcx, &mut body, dropee_ptr, span); - if ty.is_some() { + if let ty::Array(ety, _len) = *ty.kind() { + // Don't write out the elaboration for each array type. + // Instead, just delegate to the slice version. + let slice_ty = Ty::new_slice(tcx, ety); + let mut_slice_ty = Ty::new_ref(tcx, tcx.lifetimes.re_erased, slice_ty, ty::Mutability::Mut); + let erased_local = body.local_decls.push(LocalDecl::new(mut_slice_ty, span)); + + let start = &mut body.basic_blocks_mut()[START_BLOCK]; + start.statements.push(Statement::new( + source_info, + StatementKind::Assign(Box::new(( + Place::from(erased_local), + Rvalue::Cast( + CastKind::PointerCoercion( + ty::adjustment::PointerCoercion::Unsize, + CoercionSource::Implicit, + ), + Operand::Move(dropee_ptr), + mut_slice_ty, + ), + ))), + )); + start.terminator = Some(Terminator { + source_info, + kind: TerminatorKind::Call { + func: Operand::function_handle(tcx, def_id, [ty::GenericArg::from(slice_ty)], span), + args: Box::new([Spanned { span, node: Operand::Move(Place::from(erased_local)) }]), + destination: Place::from(RETURN_PLACE), + target: Some(return_block), + unwind: UnwindAction::Continue, + call_source: CallSource::Misc, + fn_span: span, + }, + }); + } else { let patch = { let typing_env = ty::TypingEnv::post_analysis(tcx, def_id); let mut elaborator = DropShimElaborator { diff --git a/tests/codegen-llvm/array-drop-glue.rs b/tests/codegen-llvm/array-drop-glue.rs new file mode 100644 index 0000000000000..994879cb65cf1 --- /dev/null +++ b/tests/codegen-llvm/array-drop-glue.rs @@ -0,0 +1,67 @@ +//@ revisions: RAW OPT +//@ compile-flags: -C opt-level=z -C panic=abort +//@[RAW] compile-flags: -C no-prepopulate-passes -Z inline-mir + +#![crate_type = "lib"] + +// Ensure all the different array drop_glue functions just delegate to the slice one, +// rather than emitting two loops in each of the three. + +// When this test was first written, the array drop glues came out in the +// seemingly-arbitrary order of 42, then 7, then 13, so to avoid potential +// fragility from that changing we don't check any particular order. + +// RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> +// RAW-NEXT: inlinehint +// RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> +// RAW-NEXT: noundef [[N]]) +// RAW: } + +// RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> +// RAW-NEXT: inlinehint +// RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> +// RAW-NEXT: noundef [[N]]) +// RAW: } + +// RAW: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; [[N:7|13|42]]]> +// RAW-NEXT: inlinehint +// RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> +// RAW-NEXT: noundef [[N]]) +// RAW: } + +// CHECK-LABEL: ; core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> +// CHECK-NOT: inlinehint +// OPT: add nuw nsw {{.+}} 1 +// CHECK: } + +#[no_mangle] +// CHECK-LABEL: @drop_arrays +pub fn drop_arrays(x: [NeedsDrop; 7], y: [NeedsDrop; 13], z: [NeedsDrop; 42]) { + // I don't remember the parameter drop order, so write out the order the test expects. + + // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 7]> + // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> + // OPT-NEXT: noundef 7) + drop(x); + // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 13]> + // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> + // OPT-NEXT: noundef 13) + drop(y); + // RAW: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop; 42]> + // OPT: call core::ptr::drop_glue::<[array_drop_glue::NeedsDrop]> + // OPT-NEXT: noundef 42) + drop(z); +} + +struct NeedsDrop(u32); + +impl Drop for NeedsDrop { + #[inline] + fn drop(&mut self) { + do_the_drop(self); + } +} + +unsafe extern "Rust" { + safe fn do_the_drop(_: &mut NeedsDrop); +} diff --git a/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir b/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir index 66591dcc91df2..1d4b0f033e0be 100644 --- a/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/slice_drop_shim.core.ptr-drop_glue.[String;42].AddMovesForPackedDrops.before.mir @@ -2,62 +2,14 @@ fn std::ptr::drop_glue(_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: usize; - let mut _5: usize; - let mut _6: *mut std::string::String; - let mut _7: bool; - let mut _8: *mut std::string::String; - let mut _9: bool; + let mut _2: &mut [std::string::String]; bb0: { - goto -> bb9; + _2 = move _1 as &mut [std::string::String] (PointerCoercion(Unsize, Implicit)); + _0 = std::ptr::drop_glue::<[String]>(move _2) -> [return: bb1, unwind continue]; } bb1: { return; } - - bb2 (cleanup): { - resume; - } - - bb3 (cleanup): { - _6 = &raw mut (*_3)[_5]; - _5 = Add(move _5, const 1_usize); - drop((*_6)) -> [return: bb4, unwind terminate(cleanup)]; - } - - bb4 (cleanup): { - _7 = Eq(copy _5, copy _4); - switchInt(move _7) -> [0: bb3, otherwise: bb2]; - } - - bb5: { - _8 = &raw mut (*_3)[_5]; - _5 = Add(move _5, const 1_usize); - drop((*_8)) -> [return: bb6, unwind: bb4]; - } - - bb6: { - _9 = Eq(copy _5, copy _4); - switchInt(move _9) -> [0: bb5, otherwise: bb1]; - } - - bb7: { - _4 = PtrMetadata(copy _3); - _5 = const 0_usize; - goto -> bb6; - } - - bb8: { - goto -> bb7; - } - - bb9: { - _2 = &raw mut (*_1); - _3 = move _2 as *mut [std::string::String] (PointerCoercion(Unsize, Implicit)); - goto -> bb8; - } }