Inline and remove SelectionContext::fast_reject_trait_refs.

Because it has a single call site, and it lets us move a small amount of
the work outside the loop.
This commit is contained in:
Nicholas Nethercote 2023-03-09 11:00:05 +11:00
parent 9fa69473fd
commit 03923661af
2 changed files with 4 additions and 18 deletions

View File

@ -11,7 +11,7 @@ use hir::LangItem;
use rustc_hir as hir;
use rustc_infer::traits::ObligationCause;
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
use rustc_middle::ty::fast_reject::TreatProjections;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use crate::traits;
@ -344,6 +344,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return;
}
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
let obligation_substs = obligation.predicate.skip_binder().trait_ref.substs;
self.tcx().for_each_relevant_impl(
obligation.predicate.def_id(),
obligation.predicate.skip_binder().trait_ref.self_ty(),
@ -352,7 +354,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// consider a "quick reject". This avoids creating more types
// and so forth that we need to.
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
if self.fast_reject_trait_refs(obligation, &impl_trait_ref.0) {
if !drcx.substs_refs_may_unify(obligation_substs, impl_trait_ref.0.substs) {
return;
}
if self.reject_fn_ptr_impls(

View File

@ -45,7 +45,6 @@ use rustc_infer::traits::TraitEngineExt;
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::SubstsRef;
@ -2533,21 +2532,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
Ok(Normalized { value: impl_substs, obligations: nested_obligations })
}
fn fast_reject_trait_refs(
&mut self,
obligation: &TraitObligation<'tcx>,
impl_trait_ref: &ty::TraitRef<'tcx>,
) -> bool {
// We can avoid creating type variables and doing the full
// substitution if we find that any of the input types, when
// simplified, do not match.
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
!drcx.substs_refs_may_unify(
obligation.predicate.skip_binder().trait_ref.substs,
impl_trait_ref.substs,
)
}
/// Normalize `where_clause_trait_ref` and try to match it against
/// `obligation`. If successful, return any predicates that
/// result from the normalization.