trait_sel: deep reject match_normalize_trait_ref

Spotted during an in-person review of unrelated changes,
`match_normalize_trait_ref` could be using `DeepRejectCtxt` to exit early
as an optimisation for prejection candidates, like is done in param
candidates.
This commit is contained in:
David Wood
2025-05-13 07:33:51 +00:00
parent 414482f6a0
commit a5e1dba0cd
2 changed files with 9 additions and 2 deletions

View File

@@ -27,8 +27,8 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::TypeErrorToStringExt;
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
use rustc_middle::ty::{
self, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
TypingMode, Upcast, elaborate,
self, DeepRejectCtxt, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable,
TypeVisitableExt, TypingMode, Upcast, elaborate,
};
use rustc_span::{Symbol, sym};
use tracing::{debug, instrument, trace};
@@ -1669,6 +1669,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return Err(());
}
let drcx = DeepRejectCtxt::relate_rigid_rigid(self.infcx.tcx);
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
if !drcx.args_may_unify(obligation_args, trait_bound.skip_binder().args) {
return Err(());
}
let trait_bound = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
HigherRankedType,