diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 19668a4c0f20e..85109f39b4e9d 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -528,7 +528,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { fn for_each_relevant_impl( self, trait_def_id: DefId, - self_ty: Ty<'tcx>, + args: ty::GenericArgsRef<'tcx>, mut f: impl FnMut(DefId) -> R, ) -> R { macro_rules! ret { @@ -540,6 +540,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { }; } + let self_ty = args.type_at(0); let tcx = self; let trait_impls = tcx.trait_impls_of(trait_def_id); let mut consider_impls_for_simplified_type = |simp| { 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 7f3627c6db54e..b634be87d3d7c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -50,6 +50,8 @@ where { fn self_ty(self) -> I::Ty; + fn args(self) -> I::GenericArgs; + fn trait_ref(self, cx: I) -> ty::TraitRef; fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self; @@ -539,7 +541,7 @@ where let cx = self.cx(); cx.for_each_relevant_impl( goal.predicate.trait_def_id(cx), - goal.predicate.self_ty(), + goal.predicate.args(), |impl_def_id| -> Result<_, _> { // For every `default impl`, there's always a non-default `impl` // that will *also* apply. There's no reason to register a candidate diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index ccd5c649d4c9e..97e27129f3b2b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -27,6 +27,10 @@ where self.self_ty() } + fn args(self) -> I::GenericArgs { + self.trait_ref.args + } + fn trait_ref(self, _: I) -> ty::TraitRef { self.trait_ref } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index e9a4d7e5919ad..5d2e6e1a8c98c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -151,6 +151,10 @@ where self.self_ty() } + fn args(self) -> I::GenericArgs { + self.alias.args + } + fn trait_ref(self, cx: I) -> ty::TraitRef { self.alias.trait_ref(cx) } diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 7e56dcb02591d..d5d4e9603d564 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -36,6 +36,10 @@ where self.self_ty() } + fn args(self) -> I::GenericArgs { + self.trait_ref.args + } + fn trait_ref(self, _: I) -> ty::TraitRef { self.trait_ref } @@ -1238,7 +1242,7 @@ where let mut disqualifying_impl = None; self.cx().for_each_relevant_impl( goal.predicate.def_id(), - goal.predicate.self_ty(), + goal.predicate.trait_ref.args, |impl_def_id| { disqualifying_impl = Some(impl_def_id); }, diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 7cdd82fe1a807..856d18b1d5743 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -405,7 +405,7 @@ pub trait Interner: fn for_each_relevant_impl( self, trait_def_id: Self::TraitId, - self_ty: Self::Ty, + args: Self::GenericArgs, f: impl FnMut(Self::ImplId) -> R, ) -> R; fn for_each_blanket_impl(