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

@@ -52,6 +52,7 @@ pub use rustc_session::lint::RegisteredTools;
use rustc_span::hygiene::MacroKind; use rustc_span::hygiene::MacroKind;
use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet}; pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet};
pub use rustc_type_ir::fast_reject::DeepRejectCtxt;
#[allow( #[allow(
hidden_glob_reexports, hidden_glob_reexports,
rustc::usage_of_type_ir_inherent, rustc::usage_of_type_ir_inherent,

View File

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