Skip to content

Commit 4cc659e

Browse files
short-circuit when proj def ids differ
1 parent 1bb6ae5 commit 4cc659e

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,20 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
625625
// in b_ty's bound. Use this to first determine *which* apply without
626626
// having any inference side-effects. We process obligations because
627627
// unification may initially succeed due to deferred projection equality.
628-
let projection_may_match = |ecx: &mut Self, source_projection, target_projection| {
629-
ecx.probe(|_| CandidateKind::UpcastProbe)
630-
.enter(|ecx| -> Result<(), NoSolution> {
631-
ecx.eq(param_env, source_projection, target_projection)?;
632-
let _ = ecx.try_evaluate_added_goals()?;
633-
Ok(())
634-
})
635-
.is_ok()
636-
};
628+
let projection_may_match =
629+
|ecx: &mut Self,
630+
source_projection: ty::PolyExistentialProjection<'tcx>,
631+
target_projection: ty::PolyExistentialProjection<'tcx>| {
632+
source_projection.item_def_id() == target_projection.item_def_id()
633+
&& ecx
634+
.probe(|_| CandidateKind::UpcastProbe)
635+
.enter(|ecx| -> Result<(), NoSolution> {
636+
ecx.eq(param_env, source_projection, target_projection)?;
637+
let _ = ecx.try_evaluate_added_goals()?;
638+
Ok(())
639+
})
640+
.is_ok()
641+
};
637642

638643
for bound in b_data {
639644
match bound.skip_binder() {

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
920920
a_data.projection_bounds().filter(|source_projection| {
921921
// Eager normalization means that we can just use can_eq
922922
// here instead of equating and processing obligations.
923-
self.infcx.can_eq(
924-
obligation.param_env,
925-
*source_projection,
926-
target_projection,
927-
)
923+
source_projection.item_def_id() == target_projection.item_def_id()
924+
&& self.infcx.can_eq(
925+
obligation.param_env,
926+
*source_projection,
927+
target_projection,
928+
)
928929
});
929930
let Some(source_projection) = matching_projections.next() else {
930931
return Err(SelectionError::Unimplemented);

0 commit comments

Comments
 (0)