Skip to content

Commit 41cb440

Browse files
Pass the whole GenericArgs to Interner::for_each_relevant_impl()
And not just the self type. rustc does not make use of this, but rust-analyzer needs it to support impls in the same block as args, see https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/non.20local.20impls.20for.20generic.20args/with/593629693. I'm not entirely sure this covers all cases (e.g. an unnormalized alias), and wants feedback from a types team member.
1 parent 29155a4 commit 41cb440

6 files changed

Lines changed: 19 additions & 4 deletions

File tree

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
528528
fn for_each_relevant_impl<R: VisitorResult>(
529529
self,
530530
trait_def_id: DefId,
531-
self_ty: Ty<'tcx>,
531+
args: ty::GenericArgsRef<'tcx>,
532532
mut f: impl FnMut(DefId) -> R,
533533
) -> R {
534534
macro_rules! ret {
@@ -540,6 +540,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
540540
};
541541
}
542542

543+
let self_ty = args.type_at(0);
543544
let tcx = self;
544545
let trait_impls = tcx.trait_impls_of(trait_def_id);
545546
let mut consider_impls_for_simplified_type = |simp| {

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ where
5050
{
5151
fn self_ty(self) -> I::Ty;
5252

53+
fn args(self) -> I::GenericArgs;
54+
5355
fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
5456

5557
fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
@@ -539,7 +541,7 @@ where
539541
let cx = self.cx();
540542
cx.for_each_relevant_impl(
541543
goal.predicate.trait_def_id(cx),
542-
goal.predicate.self_ty(),
544+
goal.predicate.args(),
543545
|impl_def_id| -> Result<_, _> {
544546
// For every `default impl`, there's always a non-default `impl`
545547
// that will *also* apply. There's no reason to register a candidate

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ where
2727
self.self_ty()
2828
}
2929

30+
fn args(self) -> I::GenericArgs {
31+
self.trait_ref.args
32+
}
33+
3034
fn trait_ref(self, _: I) -> ty::TraitRef<I> {
3135
self.trait_ref
3236
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ where
151151
self.self_ty()
152152
}
153153

154+
fn args(self) -> I::GenericArgs {
155+
self.alias.args
156+
}
157+
154158
fn trait_ref(self, cx: I) -> ty::TraitRef<I> {
155159
self.alias.trait_ref(cx)
156160
}

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ where
3636
self.self_ty()
3737
}
3838

39+
fn args(self) -> I::GenericArgs {
40+
self.trait_ref.args
41+
}
42+
3943
fn trait_ref(self, _: I) -> ty::TraitRef<I> {
4044
self.trait_ref
4145
}
@@ -1238,7 +1242,7 @@ where
12381242
let mut disqualifying_impl = None;
12391243
self.cx().for_each_relevant_impl(
12401244
goal.predicate.def_id(),
1241-
goal.predicate.self_ty(),
1245+
goal.predicate.trait_ref.args,
12421246
|impl_def_id| {
12431247
disqualifying_impl = Some(impl_def_id);
12441248
},

compiler/rustc_type_ir/src/interner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub trait Interner:
405405
fn for_each_relevant_impl<R: VisitorResult>(
406406
self,
407407
trait_def_id: Self::TraitId,
408-
self_ty: Self::Ty,
408+
args: Self::GenericArgs,
409409
f: impl FnMut(Self::ImplId) -> R,
410410
) -> R;
411411
fn for_each_blanket_impl<R: VisitorResult>(

0 commit comments

Comments
 (0)