From 41003d9952e083121607b26005dda60e2eedee09 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Sun, 12 Apr 2026 17:09:52 +0530 Subject: [PATCH 01/10] feat: create an MVP for using `Destruct` for custom dtors --- .../src/back/symbol_export.rs | 4 +- compiler/rustc_hir/src/lang_items.rs | 1 + compiler/rustc_middle/src/ty/instance.rs | 16 +++- compiler/rustc_monomorphize/src/collector.rs | 3 + .../src/solve/assembly/mod.rs | 70 +++++++++------- compiler/rustc_span/src/symbol.rs | 1 + .../src/traits/select/candidate_assembly.rs | 8 +- compiler/rustc_ty_utils/src/instance.rs | 83 ++++++++++++------- library/core/src/marker.rs | 11 ++- tests/ui/drop/custom_dtor_with_destruct.rs | 19 +++++ .../drop/custom_dtor_with_destruct.run.stdout | 1 + 11 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 tests/ui/drop/custom_dtor_with_destruct.rs create mode 100644 tests/ui/drop/custom_dtor_with_destruct.run.stdout diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 7577217401810..8fdc7e9ec1da8 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -430,7 +430,7 @@ fn upstream_monomorphizations_provider( let mut instances: DefIdMap> = Default::default(); - let drop_glue_fn_def_id = tcx.lang_items().drop_glue_fn(); + let drop_in_place_fn_def_id = tcx.lang_items().destruct_drop_in_place(); let async_drop_in_place_fn_def_id = tcx.lang_items().async_drop_in_place_fn(); for &cnum in cnums.iter() { @@ -491,7 +491,7 @@ fn upstream_drop_glue_for_provider<'tcx>( tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>, ) -> Option { - let def_id = tcx.lang_items().drop_glue_fn()?; + let def_id = tcx.lang_items().destruct_drop_in_place()?; 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 e6e0b3726552f..a9a4f3f74bd7d 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -188,6 +188,7 @@ language_item_table! { Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None; Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None; + DestructDropInPlace, sym::destruct_drop_in_place, destruct_drop_in_place, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::None; AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1); diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 6a04357827360..a4b1e1d69c087 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -160,7 +160,7 @@ pub enum ShimKind<'tcx> { /// Proxy shim for async drop of future (def_id, proxy_cor_ty, impl_cor_ty) FutureDropPoll(DefId, Ty<'tcx>, Ty<'tcx>), - /// `core::ptr::drop_glue::`. + /// `Destruct::drop_in_place()` /// /// The `DefId` is for `core::ptr::drop_glue`. /// The `Option>` is either `Some(T)`, or `None` for empty drop glue. @@ -786,8 +786,8 @@ impl<'tcx> 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); + pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { + let def_id = tcx.require_lang_item(LangItem::DestructDropInPlace, DUMMY_SP); let args = tcx.mk_args(&[ty.into()]); Instance::expect_resolve( tcx, @@ -798,6 +798,16 @@ impl<'tcx> Instance<'tcx> { ) } + pub fn try_resolve_drop_in_place( + tcx: TyCtxt<'tcx>, + typing_env: ty::TypingEnv<'tcx>, + ty: Ty<'tcx>, + ) -> Result>, ErrorGuaranteed> { + let def_id = tcx.require_lang_item(LangItem::DestructDropInPlace, DUMMY_SP); + let args = tcx.mk_args(&[ty.into()]); + Instance::try_resolve(tcx, typing_env, def_id, args) + } + pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, DUMMY_SP); let args = tcx.mk_args(&[ty.into()]); diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 68d6c01f15e92..94ebec730a61f 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1066,6 +1066,9 @@ fn visit_instance_use<'tcx>( /// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we /// can just link to the upstream crate and therefore don't need a mono item. fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool { + if let ty::InstanceKind::DropGlue(_, Some(_)) = instance.def { + return instance.upstream_monomorphization(tcx).is_none(); + } let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else { return true; }; diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 040f98de7bcfd..7041248654c1a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -472,37 +472,47 @@ where match assemble_from { AssembleCandidatesFrom::All => { - self.assemble_builtin_impl_candidates(goal, &mut candidates)?; - // For performance we only assemble impls if there are no candidates - // which would shadow them. This is necessary to avoid hangs in rayon, - // see trait-system-refactor-initiative#109 for more details. - // - // We always assemble builtin impls as trivial builtin impls have a higher - // priority than where-clauses. - // - // We only do this if any such candidate applies without any constraints - // as we may want to weaken inference guidance in the future and don't want - // to worry about causing major performance regressions when doing so. - // See trait-system-refactor-initiative#226 for some ideas here. - let assemble_impls = match self.typing_mode() { - TypingMode::Coherence => true, - TypingMode::Typeck { .. } - | TypingMode::PostTypeckUntilBorrowck { .. } - | TypingMode::Reflection - | TypingMode::PostBorrowck { .. } - | TypingMode::PostAnalysis - | TypingMode::Codegen - | TypingMode::ErasedNotCoherence(MayBeErased) => !candidates.iter().any(|c| { - matches!( - c.source, - CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) - | CandidateSource::AliasBound(_) - ) && has_no_inference_or_external_constraints(c.result) - }), - }; - if assemble_impls { - self.assemble_impl_candidates(goal, &mut candidates)?; + let trait_def_id = goal.predicate.trait_def_id(self.cx()); + // Check if there are any user defined impls for Destruct. If there are, + // use those, and fallback to builtin drop glue impl if none are present + if self.cx().is_trait_lang_item(trait_def_id, SolverTraitLangItem::Destruct) { + self.assemble_impl_candidates(goal, &mut candidates); + let has_impl_candidate = + candidates.iter().any(|c| matches!(c.source, CandidateSource::Impl(_))); + if !has_impl_candidate { + self.assemble_builtin_impl_candidates(goal, &mut candidates); + } self.assemble_object_bound_candidates(goal, &mut candidates); + } else { + self.assemble_builtin_impl_candidates(goal, &mut candidates); + // For performance we only assemble impls if there are no candidates + // which would shadow them. This is necessary to avoid hangs in rayon, + // see trait-system-refactor-initiative#109 for more details. + // + // We always assemble builtin impls as trivial builtin impls have a higher + // priority than where-clauses. + // + // We only do this if any such candidate applies without any constraints + // as we may want to weaken inference guidance in the future and don't want + // to worry about causing major performance regressions when doing so. + // See trait-system-refactor-initiative#226 for some ideas here. + let assemble_impls = match self.typing_mode() { + TypingMode::Coherence => true, + TypingMode::Analysis { .. } + | TypingMode::Borrowck { .. } + | TypingMode::PostBorrowckAnalysis { .. } + | TypingMode::PostAnalysis => !candidates.iter().any(|c| { + matches!( + c.source, + CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) + | CandidateSource::AliasBound(_) + ) && has_no_inference_or_external_constraints(c.result) + }), + }; + if assemble_impls { + self.assemble_impl_candidates(goal, &mut candidates); + self.assemble_object_bound_candidates(goal, &mut candidates); + } } } AssembleCandidatesFrom::EnvAndBounds => { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c874c1af265f8..f650d7cbe519c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -813,6 +813,7 @@ symbols! { derive_from, derive_smart_pointer, destruct, + destruct_drop_in_place, destructuring_assignment, diagnostic, diagnostic_namespace, diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index d4027fcf388b1..5a0d1cbfb3b04 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -114,7 +114,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.assemble_candidates_for_unsizing(obligation, &mut candidates); } Some(LangItem::Destruct) => { - self.assemble_const_destruct_candidates(obligation, &mut candidates); + let before = candidates.vec.len(); + self.assemble_candidates_from_impls(obligation, &mut candidates); + let added_impl = + candidates.vec[before..].iter().any(|c| matches!(c, ImplCandidate(_))); + if !added_impl { + self.assemble_const_destruct_candidates(obligation, &mut candidates); + } } Some(LangItem::TransmuteTrait) => { // User-defined transmutability impls are permitted. diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index b5a82793dcc97..6215583b7479c 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -39,34 +39,7 @@ fn resolve_instance_raw<'tcx>( } else if tcx.is_lang_item(def_id, LangItem::DropGlue) { let ty = args.type_at(0); - let shim = if ty.needs_drop(tcx, typing_env) { - debug!(" => nontrivial drop glue"); - match *ty.kind() { - ty::Coroutine(coroutine_def_id, ..) => { - // FIXME: sync drop of coroutine with async drop (generate both versions?) - // Currently just ignored - if tcx.optimized_mir(coroutine_def_id).coroutine_drop_async().is_some() { - ty::ShimKind::DropGlue(def_id, None) - } else { - ty::ShimKind::DropGlue(def_id, Some(ty)) - } - } - ty::Closure(..) - | ty::CoroutineClosure(..) - | ty::Tuple(..) - | ty::Adt(..) - | ty::Dynamic(..) - | ty::Array(..) - | ty::Slice(..) - | ty::UnsafeBinder(..) => ty::ShimKind::DropGlue(def_id, Some(ty)), - // Drop shims can only be built from ADTs. - _ => return Ok(None), - } - } else { - debug!(" => trivial drop glue"); - ty::ShimKind::DropGlue(def_id, None) - }; - ty::InstanceKind::Shim(shim) + return ty::Instance::try_resolve_drop_in_place(tcx, typing_env, ty); } else if tcx.is_lang_item(def_id, LangItem::AsyncDropInPlace) { let ty = args.type_at(0); @@ -177,6 +150,20 @@ fn resolve_associated_item<'tcx>( if !eligible { return Ok(None); } + if tcx.is_lang_item(trait_ref.def_id, LangItem::Destruct) { + if !tcx.is_lang_item(trait_item_id, LangItem::DestructDropInPlace) { + bug!( + "unexpected associated item for built-in `{trait_ref}`: {}", + tcx.item_name(trait_item_id) + ); + } + + debug!("Got user Destruct impl"); + return Ok(Some(Instance { + def: ty::InstanceKind::Item(leaf_def.item.def_id), + args: rcvr_args, + })); + } let typing_env = typing_env.with_post_analysis_normalized(tcx); let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); @@ -427,6 +414,46 @@ fn resolve_associated_item<'tcx>( } else { bug!("unexpected associated associated item") } + } else if tcx.is_lang_item(trait_ref.def_id, LangItem::Destruct) { + debug!( + "resolving Destruct for ImplSource::Builtin: {:?}, {:?}, {:?}", + typing_env, trait_item_id, rcvr_args + ); + if !tcx.is_lang_item(trait_item_id, LangItem::DestructDropInPlace) { + bug!( + "unexpected associated item for built-in `{trait_ref}`: {}", + tcx.item_name(trait_item_id) + ); + } + + let self_ty = trait_ref.self_ty(); + + let def = if self_ty.needs_drop(tcx, typing_env) { + match *self_ty.kind() { + ty::Coroutine(coroutine_def_id, ..) => { + if tcx.optimized_mir(coroutine_def_id).coroutine_drop_async().is_some() + { + ty::InstanceKind::DropGlue(trait_item_id, None) + } else { + ty::InstanceKind::DropGlue(trait_item_id, Some(self_ty)) + } + } + ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::Tuple(..) + | ty::Adt(..) + | ty::Dynamic(..) + | ty::Array(..) + | ty::Slice(..) + | ty::UnsafeBinder(..) => { + ty::InstanceKind::DropGlue(trait_item_id, Some(self_ty)) + } + _ => return Ok(None), + } + } else { + ty::InstanceKind::DropGlue(trait_item_id, None) + }; + Some(ty::Instance { def, args: rcvr_args }) } else { Instance::try_resolve_item_for_coroutine(tcx, trait_item_id, trait_id, rcvr_args) } diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index e3785c92c8d0d..b06003dce1d7d 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1057,10 +1057,15 @@ marker_impls! { #[unstable(feature = "const_destruct", issue = "133214")] #[rustc_const_unstable(feature = "const_destruct", issue = "133214")] #[lang = "destruct"] -#[diagnostic::on_unimplemented(message = "can't drop `{Self}`")] -#[rustc_deny_explicit_impl] +#[rustc_on_unimplemented(message = "can't drop `{Self}`")] #[rustc_dyn_incompatible_trait] -pub const trait Destruct: PointeeSized {} +pub const trait Destruct: PointeeSized { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} /// A marker for tuple types. /// diff --git a/tests/ui/drop/custom_dtor_with_destruct.rs b/tests/ui/drop/custom_dtor_with_destruct.rs new file mode 100644 index 0000000000000..54ca01ca24fa1 --- /dev/null +++ b/tests/ui/drop/custom_dtor_with_destruct.rs @@ -0,0 +1,19 @@ +//@ run-pass +//@ check-stdout +//@ check-run-results + +#![feature(const_destruct)] +use std::marker::Destruct; +struct A { + _a: String, +} + +impl Destruct for A { + unsafe fn drop_in_place(_to_drop: *mut Self) { + println!("Hey i was dropped"); + } +} + +fn main() { + let _a = A { _a: String::new() }; +} diff --git a/tests/ui/drop/custom_dtor_with_destruct.run.stdout b/tests/ui/drop/custom_dtor_with_destruct.run.stdout new file mode 100644 index 0000000000000..e864173b60164 --- /dev/null +++ b/tests/ui/drop/custom_dtor_with_destruct.run.stdout @@ -0,0 +1 @@ +Hey i was dropped From ae77a9b31b9a09074069983b5c8c505e36b2a3cb Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Sun, 3 May 2026 13:37:34 +0530 Subject: [PATCH 02/10] fix: update minicores --- compiler/rustc_codegen_gcc/example/mini_core.rs | 8 +++++++- .../rust-analyzer/crates/hir-ty/src/tests/regression.rs | 8 +++++++- tests/auxiliary/minicore.rs | 8 +++++++- tests/ui/traits/const-traits/auxiliary/minicore.rs | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 2d5a29ceb8191..fbd4df8a45ed3 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -54,7 +54,13 @@ pub trait MetaSized: PointeeSized {} pub trait Sized: MetaSized {} #[lang = "destruct"] -pub trait Destruct {} +pub trait Destruct { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} #[lang = "tuple_trait"] pub trait Tuple {} diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs index c580841244f1b..8b82fe6bd04c1 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs @@ -2437,7 +2437,13 @@ impl const MyClone for i32 { } } #[lang = "destruct"] -pub trait Destruct {} +pub trait Destruct { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} "#, ); } diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index e8bfdf80c98e8..065273db84850 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -70,7 +70,13 @@ pub trait Sized: MetaSized {} #[lang = "destruct"] #[diagnostic::on_unimplemented(message = "can't drop `{Self}`")] -pub trait Destruct: PointeeSized {} +pub trait Destruct: PointeeSized { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} #[lang = "legacy_receiver"] pub trait LegacyReceiver {} diff --git a/tests/ui/traits/const-traits/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs index e1d1135e6d4ec..d5d6cfc2cb342 100644 --- a/tests/ui/traits/const-traits/auxiliary/minicore.rs +++ b/tests/ui/traits/const-traits/auxiliary/minicore.rs @@ -122,7 +122,13 @@ impl Receiver for T { } #[lang = "destruct"] -pub const trait Destruct {} +pub const trait Destruct { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} #[lang = "freeze"] pub unsafe auto trait Freeze {} From d62d40be2b8aacf87916e21e3420ad86a59feafc Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Wed, 6 May 2026 19:19:17 +0530 Subject: [PATCH 03/10] fix: add destruct_drop_in_place to another minicore --- compiler/rustc_codegen_cranelift/example/mini_core.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 08adec96a079b..8d580305baed1 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -50,7 +50,13 @@ pub trait MetaSized: PointeeSized {} pub trait Sized: MetaSized {} #[lang = "destruct"] -pub trait Destruct {} +pub trait Destruct { + /// Entrypoint for drop + /// + /// Generated by default if not implemented manually. + #[lang = "destruct_drop_in_place"] + unsafe fn drop_in_place(_to_drop: *mut Self); +} #[lang = "tuple_trait"] pub trait Tuple {} From 4a6c469c6cc85083953728f5b834e4384a49b145 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Wed, 6 May 2026 20:42:55 +0530 Subject: [PATCH 04/10] fix: bless tests fix: bless tests --- tests/ui/consts/const-eval/c-variadic-fail.stderr | 12 ++++++------ .../collect-in-dead-drop.noopt.stderr | 2 +- .../required-consts/collect-in-dead-drop.opt.stderr | 2 +- .../collect-in-dead-move.noopt.stderr | 2 +- .../required-consts/collect-in-dead-move.opt.stderr | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/ui/consts/const-eval/c-variadic-fail.stderr b/tests/ui/consts/const-eval/c-variadic-fail.stderr index ccf2936324a9c..f4a02006129b5 100644 --- a/tests/ui/consts/const-eval/c-variadic-fail.stderr +++ b/tests/ui/consts/const-eval/c-variadic-fail.stderr @@ -464,8 +464,8 @@ LL | drop(ap); | ^^^^^^^^ note: inside `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside ` as Destruct>::drop_in_place - shim(Some(VaList<'_>))` + --> $SRC_DIR/core/src/marker.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL @@ -496,8 +496,8 @@ LL | drop(ap); | ^^^^^^^^ note: inside `std::mem::drop::>` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside ` as Destruct>::drop_in_place - shim(Some(VaList<'_>))` + --> $SRC_DIR/core/src/marker.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL @@ -549,8 +549,8 @@ 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 `std::ptr::drop_glue::> - shim(Some(VaList<'_>))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside ` as Destruct>::drop_in_place - shim(Some(VaList<'_>))` + --> $SRC_DIR/core/src/marker.rs:LL:COL note: inside ` as Drop>::drop` --> $SRC_DIR/core/src/ffi/va_list.rs:LL:COL diff --git a/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr index 38e169c97016d..2727672dd4d40 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr @@ -11,7 +11,7 @@ LL | let _ = Fail::::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn as Drop>::drop` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + --> $SRC_DIR/core/src/marker.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr index 38e169c97016d..2727672dd4d40 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr @@ -11,7 +11,7 @@ LL | let _ = Fail::::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn as Drop>::drop` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + --> $SRC_DIR/core/src/marker.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr index 9f652e26f242f..19b41fb3e3ae6 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr @@ -11,7 +11,7 @@ LL | let _ = Fail::::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn as Drop>::drop` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + --> $SRC_DIR/core/src/marker.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr index 9f652e26f242f..19b41fb3e3ae6 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr @@ -11,7 +11,7 @@ LL | let _ = Fail::::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn as Drop>::drop` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + --> $SRC_DIR/core/src/marker.rs:LL:COL error: aborting due to 1 previous error From 5de95216b43c67c7e74d57b347760368bf8e4af6 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 19:38:08 +0530 Subject: [PATCH 05/10] refactor: change drop_in_place to take &mut Self --- compiler/rustc_codegen_cranelift/example/mini_core.rs | 2 +- compiler/rustc_codegen_gcc/example/mini_core.rs | 2 +- library/core/src/marker.rs | 4 ++-- src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs | 2 +- tests/auxiliary/minicore.rs | 2 +- tests/ui/drop/custom_dtor_with_destruct.rs | 2 +- tests/ui/traits/const-traits/auxiliary/minicore.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 8d580305baed1..dac03ab7894bf 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -55,7 +55,7 @@ pub trait Destruct { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } #[lang = "tuple_trait"] diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index fbd4df8a45ed3..c3a64c326be55 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -59,7 +59,7 @@ pub trait Destruct { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } #[lang = "tuple_trait"] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index b06003dce1d7d..ecf75697b1777 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -856,7 +856,7 @@ unsafe impl TrivialClone for PhantomData {} #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default", issue = "143894")] -const impl Default for PhantomData { +impl const Default for PhantomData { fn default() -> Self { Self } @@ -1064,7 +1064,7 @@ pub const trait Destruct: PointeeSized { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } /// A marker for tuple types. diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs index 8b82fe6bd04c1..431e7ab898b2c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs @@ -2442,7 +2442,7 @@ pub trait Destruct { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } "#, ); diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 065273db84850..adff947955cb6 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -75,7 +75,7 @@ pub trait Destruct: PointeeSized { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } #[lang = "legacy_receiver"] diff --git a/tests/ui/drop/custom_dtor_with_destruct.rs b/tests/ui/drop/custom_dtor_with_destruct.rs index 54ca01ca24fa1..3c2793c204ade 100644 --- a/tests/ui/drop/custom_dtor_with_destruct.rs +++ b/tests/ui/drop/custom_dtor_with_destruct.rs @@ -9,7 +9,7 @@ struct A { } impl Destruct for A { - unsafe fn drop_in_place(_to_drop: *mut Self) { + unsafe fn drop_in_place(_to_drop: &mut Self) { println!("Hey i was dropped"); } } diff --git a/tests/ui/traits/const-traits/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs index d5d6cfc2cb342..0f425e6fc5ec6 100644 --- a/tests/ui/traits/const-traits/auxiliary/minicore.rs +++ b/tests/ui/traits/const-traits/auxiliary/minicore.rs @@ -127,7 +127,7 @@ pub const trait Destruct { /// /// Generated by default if not implemented manually. #[lang = "destruct_drop_in_place"] - unsafe fn drop_in_place(_to_drop: *mut Self); + unsafe fn drop_in_place(_to_drop: &mut Self); } #[lang = "freeze"] From 2e1a319331d1c4703e7aaff32358dba7cbe60f36 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 20:06:07 +0530 Subject: [PATCH 06/10] fix: fix rebase errors --- .../rustc_codegen_cranelift/src/abi/mod.rs | 2 +- .../src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 2 +- .../rustc_const_eval/src/interpret/call.rs | 4 ++-- .../rustc_const_eval/src/interpret/step.rs | 2 +- .../src/middle/exported_symbols.rs | 2 +- compiler/rustc_middle/src/ty/vtable.rs | 2 +- .../src/remove_noop_landing_pads.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 4 ++-- .../src/solve/assembly/mod.rs | 19 +++++++++++-------- .../rustc_public_bridge/src/context/impls.rs | 2 +- compiler/rustc_ty_utils/src/instance.rs | 8 ++++---- 12 files changed, 27 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 5e152af835613..4fec900f86b7c 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -730,7 +730,7 @@ pub(crate) fn codegen_drop<'tcx>( unwind: UnwindAction, ) { let ty = drop_place.layout().ty; - let drop_instance = Instance::resolve_drop_glue(fx.tcx, ty); + let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty); let ret_block = fx.get_block(target); // AsyncDropGlueCtorShim can't be here diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 8fdc7e9ec1da8..828d6132dc308 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -613,7 +613,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_glue(tcx, ty), + Instance::resolve_drop_in_place(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 20d6c01f12f73..6e1a308c2ad22 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -644,7 +644,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_glue(bx.tcx(), ty); + let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_fn.def { // we don't actually need to drop anything. diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 80cd892c799cd..243264b82fd62 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -927,7 +927,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { _ => { debug_assert_eq!( instance, - ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty) + ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty) ); place } @@ -935,7 +935,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let instance = { let _trace = enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty); - ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty) + ty::Instance::resolve_drop_in_place(*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 dd2477503fd6d..c77100f096611 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -606,7 +606,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let instance = { let _trace = enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty); - Instance::resolve_drop_glue(*self.tcx, place.layout.ty) + Instance::resolve_drop_in_place(*self.tcx, place.layout.ty) }; if let ty::InstanceKind::Shim(ty::ShimKind::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/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index e23ad3c832ef7..39de26b66a1be 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_glue(tcx, ty)) + tcx.symbol_name(ty::Instance::resolve_drop_in_place(tcx, ty)) } ExportedSymbol::AsyncDropGlueCtorShim(ty) => { tcx.symbol_name(ty::Instance::resolve_async_drop_in_place(tcx, ty)) diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index fb56bda7d4562..26d950b26986f 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_glue(tcx, ty); + let instance = ty::Instance::resolve_drop_in_place(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/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index e7c2fb54b2909..889ca37f3ff1b 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -129,7 +129,7 @@ impl RemoveNoopLandingPads { extra.typing_env, ty::EarlyBinder::bind(extra.tcx, ty), ); - let drop_fn = Instance::resolve_drop_glue(extra.tcx, ty); + let drop_fn = Instance::resolve_drop_in_place(extra.tcx, ty); if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = drop_fn.def { // no need to drop anything, if all of our successors are also no-op then we // can be skipped. diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 94ebec730a61f..7ccfebee89f2c 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -946,7 +946,7 @@ fn visit_drop_use<'tcx>( source: Span, output: &mut MonoItems<'tcx>, ) { - let instance = Instance::resolve_drop_glue(tcx, ty); + let instance = Instance::resolve_drop_in_place(tcx, ty); visit_instance_use(tcx, instance, is_direct_call, source, output); } @@ -1066,7 +1066,7 @@ fn visit_instance_use<'tcx>( /// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we /// can just link to the upstream crate and therefore don't need a mono item. fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool { - if let ty::InstanceKind::DropGlue(_, Some(_)) = instance.def { + if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, Some(_))) = instance.def { return instance.upstream_monomorphization(tcx).is_none(); } let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else { diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 7041248654c1a..ac6b086b351d5 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -476,15 +476,15 @@ where // Check if there are any user defined impls for Destruct. If there are, // use those, and fallback to builtin drop glue impl if none are present if self.cx().is_trait_lang_item(trait_def_id, SolverTraitLangItem::Destruct) { - self.assemble_impl_candidates(goal, &mut candidates); + self.assemble_impl_candidates(goal, &mut candidates)?; let has_impl_candidate = candidates.iter().any(|c| matches!(c.source, CandidateSource::Impl(_))); if !has_impl_candidate { - self.assemble_builtin_impl_candidates(goal, &mut candidates); + self.assemble_builtin_impl_candidates(goal, &mut candidates)?; } self.assemble_object_bound_candidates(goal, &mut candidates); } else { - self.assemble_builtin_impl_candidates(goal, &mut candidates); + self.assemble_builtin_impl_candidates(goal, &mut candidates)?; // For performance we only assemble impls if there are no candidates // which would shadow them. This is necessary to avoid hangs in rayon, // see trait-system-refactor-initiative#109 for more details. @@ -498,10 +498,13 @@ where // See trait-system-refactor-initiative#226 for some ideas here. let assemble_impls = match self.typing_mode() { TypingMode::Coherence => true, - TypingMode::Analysis { .. } - | TypingMode::Borrowck { .. } - | TypingMode::PostBorrowckAnalysis { .. } - | TypingMode::PostAnalysis => !candidates.iter().any(|c| { + TypingMode::Typeck { .. } + | TypingMode::PostTypeckUntilBorrowck { .. } + | TypingMode::PostBorrowck { .. } + | TypingMode::Reflection + | TypingMode::PostAnalysis + | TypingMode::Codegen + | TypingMode::ErasedNotCoherence(_) => !candidates.iter().any(|c| { matches!( c.source, CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) @@ -510,7 +513,7 @@ where }), }; if assemble_impls { - self.assemble_impl_candidates(goal, &mut candidates); + self.assemble_impl_candidates(goal, &mut candidates)?; self.assemble_object_bound_candidates(goal, &mut candidates); } } diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 6b12da9d9c4ed..c9715443a6757 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -699,7 +699,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_glue(self.tcx, internal_ty); + let instance = Instance::resolve_drop_in_place(self.tcx, internal_ty); instance } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 6215583b7479c..cdf185a7f329b 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -433,9 +433,9 @@ fn resolve_associated_item<'tcx>( ty::Coroutine(coroutine_def_id, ..) => { if tcx.optimized_mir(coroutine_def_id).coroutine_drop_async().is_some() { - ty::InstanceKind::DropGlue(trait_item_id, None) + ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, None)) } else { - ty::InstanceKind::DropGlue(trait_item_id, Some(self_ty)) + ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, Some(self_ty))) } } ty::Closure(..) @@ -446,12 +446,12 @@ fn resolve_associated_item<'tcx>( | ty::Array(..) | ty::Slice(..) | ty::UnsafeBinder(..) => { - ty::InstanceKind::DropGlue(trait_item_id, Some(self_ty)) + ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, Some(self_ty))) } _ => return Ok(None), } } else { - ty::InstanceKind::DropGlue(trait_item_id, None) + ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, None)) }; Some(ty::Instance { def, args: rcvr_args }) } else { From a0c0553f853acae0306788784aec6242aee8c4d5 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 20:19:31 +0530 Subject: [PATCH 07/10] fix: fix some syntax bugs --- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 2 +- compiler/rustc_ty_utils/src/instance.rs | 12 ++++++++---- library/core/src/marker.rs | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 828d6132dc308..4862cff31c3fd 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -438,7 +438,7 @@ 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_glue_fn_def_id { + if let Some(drop_in_place_fn_def_id) = drop_in_place_fn_def_id { (drop_in_place_fn_def_id, tcx.mk_args(&[ty.into()])) } else { // `drop_glue` does not exist, don't try to use it. diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index cdf185a7f329b..c31351bb22fd9 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -435,7 +435,10 @@ fn resolve_associated_item<'tcx>( { ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, None)) } else { - ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, Some(self_ty))) + ty::InstanceKind::Shim(ty::ShimKind::DropGlue( + trait_item_id, + Some(self_ty), + )) } } ty::Closure(..) @@ -445,9 +448,10 @@ fn resolve_associated_item<'tcx>( | ty::Dynamic(..) | ty::Array(..) | ty::Slice(..) - | ty::UnsafeBinder(..) => { - ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, Some(self_ty))) - } + | ty::UnsafeBinder(..) => ty::InstanceKind::Shim(ty::ShimKind::DropGlue( + trait_item_id, + Some(self_ty), + )), _ => return Ok(None), } } else { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index ecf75697b1777..034576580edad 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -856,7 +856,7 @@ unsafe impl TrivialClone for PhantomData {} #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default", issue = "143894")] -impl const Default for PhantomData { +const impl Default for PhantomData { fn default() -> Self { Self } From 5c418b775e42fe8d853e9c4b2503c0a2a8d93603 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 20:41:38 +0530 Subject: [PATCH 08/10] fix: fix early return that did not rebase args --- compiler/rustc_ty_utils/src/instance.rs | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index c31351bb22fd9..a382b87bafc57 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -150,6 +150,19 @@ fn resolve_associated_item<'tcx>( if !eligible { return Ok(None); } + + let typing_env = typing_env.with_post_analysis_normalized(tcx); + let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); + let args = rcvr_args.rebase_onto(tcx, trait_def_id, impl_data.args); + let args = translate_args( + &infcx, + param_env, + impl_data.impl_def_id, + args, + leaf_def.defining_node, + ); + let args = infcx.tcx.erase_and_anonymize_regions(args); + if tcx.is_lang_item(trait_ref.def_id, LangItem::Destruct) { if !tcx.is_lang_item(trait_item_id, LangItem::DestructDropInPlace) { bug!( @@ -161,22 +174,10 @@ fn resolve_associated_item<'tcx>( debug!("Got user Destruct impl"); return Ok(Some(Instance { def: ty::InstanceKind::Item(leaf_def.item.def_id), - args: rcvr_args, + args, })); } - let typing_env = typing_env.with_post_analysis_normalized(tcx); - let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); - let args = rcvr_args.rebase_onto(tcx, trait_def_id, impl_data.args); - let args = translate_args( - &infcx, - param_env, - impl_data.impl_def_id, - args, - leaf_def.defining_node, - ); - let args = infcx.tcx.erase_and_anonymize_regions(args); - // HACK: We may have overlapping `dyn Trait` built-in impls and // user-provided blanket impls. Detect that case here, and return // ambiguity. From 116daa3e52741e2746ab09ff650580103f350e89 Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 20:44:51 +0530 Subject: [PATCH 09/10] fix: readd dropped comment --- compiler/rustc_ty_utils/src/instance.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index a382b87bafc57..6062106df5be4 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -432,6 +432,8 @@ fn resolve_associated_item<'tcx>( let def = if self_ty.needs_drop(tcx, typing_env) { match *self_ty.kind() { ty::Coroutine(coroutine_def_id, ..) => { + // FIXME: sync drop of coroutine with async drop (generate both versions?) + // Currently just ignored if tcx.optimized_mir(coroutine_def_id).coroutine_drop_async().is_some() { ty::InstanceKind::Shim(ty::ShimKind::DropGlue(trait_item_id, None)) From cb29cb9bb28fa198641df30a5053b74b8fc32ebf Mon Sep 17 00:00:00 2001 From: JayanAXHF Date: Tue, 4 Aug 2026 20:47:40 +0530 Subject: [PATCH 10/10] fix: add comment abt early return --- compiler/rustc_ty_utils/src/instance.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 6062106df5be4..bff78f7be8ce9 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -171,6 +171,9 @@ fn resolve_associated_item<'tcx>( ); } + // `Destruct` isn't object-safe and has no specialization concerns here, + // so the checks below (dyn-Trait overlap, defaultness, args-compatibility, + // compare_impl_item) don't apply so we build the Instance directly. debug!("Got user Destruct impl"); return Ok(Some(Instance { def: ty::InstanceKind::Item(leaf_def.item.def_id),