Apply EarlyBinder only to TraitRef in ImplTraitHeader

This commit is contained in:
Yoshitomo Nakanishi 2024-03-05 20:19:05 +01:00
parent 8c9a75b323
commit 9669934798
22 changed files with 74 additions and 82 deletions

View file

@ -166,13 +166,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
if !drcx.args_may_unify(
goal.predicate.trait_ref(tcx).args,
impl_trait_header.skip_binder().trait_ref.args,
impl_trait_header.trait_ref.skip_binder().args,
) {
return Err(NoSolution);
}
// We have to ignore negative impls when projecting.
let impl_polarity = impl_trait_header.skip_binder().polarity;
let impl_polarity = impl_trait_header.polarity;
match impl_polarity {
ty::ImplPolarity::Negative => return Err(NoSolution),
ty::ImplPolarity::Reservation => {
@ -183,7 +183,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_trait_ref = impl_trait_header.instantiate(tcx, impl_args).trait_ref;
let impl_trait_ref = impl_trait_header.trait_ref.instantiate(tcx, impl_args);
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;

View file

@ -47,14 +47,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
if !drcx.args_may_unify(
goal.predicate.trait_ref.args,
impl_trait_header.skip_binder().trait_ref.args,
impl_trait_header.trait_ref.skip_binder().args,
) {
return Err(NoSolution);
}
// An upper bound of the certainty of this goal, used to lower the certainty
// of reservation impl to ambiguous during coherence.
let impl_polarity = impl_trait_header.skip_binder().polarity;
let impl_polarity = impl_trait_header.polarity;
let maximal_certainty = match impl_polarity {
ty::ImplPolarity::Positive | ty::ImplPolarity::Negative => {
match impl_polarity == goal.predicate.polarity {
@ -70,7 +70,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id);
let impl_trait_ref = impl_trait_header.instantiate(tcx, impl_args).trait_ref;
let impl_trait_ref = impl_trait_header.trait_ref.instantiate(tcx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = tcx

View file

@ -1888,13 +1888,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.tcx
.all_impls(trait_pred.def_id())
.filter_map(|def_id| {
let imp = self.tcx.impl_trait_header(def_id).unwrap().skip_binder();
let imp = self.tcx.impl_trait_header(def_id).unwrap();
if imp.polarity == ty::ImplPolarity::Negative
|| !self.tcx.is_user_visible_dep(def_id.krate)
{
return None;
}
let imp = imp.trait_ref;
let imp = imp.trait_ref.skip_binder();
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false).map(
|similarity| ImplCandidate { trait_ref: imp, similarity, impl_def_id: def_id },
@ -2078,12 +2078,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.all_impls(def_id)
// Ignore automatically derived impls and `!Trait` impls.
.filter_map(|def_id| self.tcx.impl_trait_header(def_id))
.map(ty::EarlyBinder::instantiate_identity)
.filter(|header| {
header.polarity != ty::ImplPolarity::Negative
|| self.tcx.is_automatically_derived(def_id)
.filter_map(|header| {
(header.polarity != ty::ImplPolarity::Negative
|| self.tcx.is_automatically_derived(def_id))
.then(|| header.trait_ref.instantiate_identity())
})
.map(|header| header.trait_ref)
.filter(|trait_ref| {
let self_ty = trait_ref.self_ty();
// Avoid mentioning type parameters.

View file

@ -562,7 +562,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// and so forth that we need to.
let impl_trait_header = self.tcx().impl_trait_header(impl_def_id).unwrap();
if !drcx
.args_may_unify(obligation_args, impl_trait_header.skip_binder().trait_ref.args)
.args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
{
return;
}
@ -577,7 +577,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if self.reject_fn_ptr_impls(
impl_def_id,
obligation,
impl_trait_header.skip_binder().trait_ref.self_ty(),
impl_trait_header.trait_ref.skip_binder().self_ty(),
) {
return;
}

View file

@ -42,7 +42,7 @@ use rustc_middle::ty::_match::MatchAgainstFreshVars;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
use rustc_span::symbol::sym;
use rustc_span::Symbol;
@ -2441,7 +2441,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
fn match_impl(
&mut self,
impl_def_id: DefId,
impl_trait_header: EarlyBinder<ty::ImplTraitHeader<'tcx>>,
impl_trait_header: ty::ImplTraitHeader<'tcx>,
obligation: &PolyTraitObligation<'tcx>,
) -> Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> {
let placeholder_obligation =
@ -2450,8 +2450,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
let impl_trait_header = impl_trait_header.instantiate(self.tcx(), impl_args);
if impl_trait_header.references_error() {
let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
if trait_ref.references_error() {
return Err(());
}
@ -2464,7 +2464,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
impl_trait_header.trait_ref,
trait_ref,
)
});

View file

@ -169,7 +169,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
}
}
let impl1_trait_header = tcx.impl_trait_header(impl1_def_id).unwrap().instantiate_identity();
let impl1_trait_header = tcx.impl_trait_header(impl1_def_id).unwrap();
// We determine whether there's a subset relationship by:
//
@ -198,7 +198,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
fulfill_implication(
&infcx,
penv,
impl1_trait_header.trait_ref,
impl1_trait_header.trait_ref.instantiate_identity(),
impl1_def_id,
impl2_def_id,
|_, _| ObligationCause::dummy(),