Add a helper for replacing the self type in trait refs
This commit is contained in:
parent
6f77c97b38
commit
19a1192d42
5 changed files with 15 additions and 29 deletions
|
@ -998,13 +998,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if trait_predicate.skip_binder().self_ty().is_never()
|
||||
&& self.fallback_has_occurred
|
||||
{
|
||||
let predicate = trait_predicate.map_bound(|mut trait_pred| {
|
||||
trait_pred.trait_ref = self.tcx.mk_trait_ref(
|
||||
trait_pred.trait_ref.def_id,
|
||||
self.tcx.mk_unit(),
|
||||
&trait_pred.trait_ref.substs[1..],
|
||||
);
|
||||
trait_pred
|
||||
let predicate = trait_predicate.map_bound(|trait_pred| {
|
||||
trait_pred.with_self_type(self.tcx, self.tcx.mk_unit())
|
||||
});
|
||||
let unit_obligation = obligation.with(tcx, predicate);
|
||||
if self.predicate_may_hold(&unit_obligation) {
|
||||
|
@ -2026,14 +2021,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
|
||||
) -> PredicateObligation<'tcx> {
|
||||
let trait_pred = trait_ref_and_ty.map_bound_ref(|(tr, new_self_ty)| ty::TraitPredicate {
|
||||
trait_ref: self.tcx.mk_trait_ref(
|
||||
tr.trait_ref.def_id,
|
||||
*new_self_ty,
|
||||
&tr.trait_ref.substs[1..],
|
||||
),
|
||||
..*tr
|
||||
});
|
||||
let trait_pred = trait_ref_and_ty
|
||||
.map_bound(|(tr, new_self_ty)| tr.with_self_type(self.tcx, new_self_ty));
|
||||
|
||||
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred)
|
||||
}
|
||||
|
|
|
@ -18,11 +18,6 @@ pub(crate) fn update<'tcx, T>(
|
|||
{
|
||||
let new_self_ty = infcx.tcx.types.unit;
|
||||
|
||||
let trait_ref = infcx.tcx.mk_trait_ref(
|
||||
tpred.trait_ref.def_id,
|
||||
new_self_ty, &tpred.trait_ref.substs[1..],
|
||||
);
|
||||
|
||||
// Then construct a new obligation with Self = () added
|
||||
// to the ParamEnv, and see if it holds.
|
||||
let o = obligation.with(infcx.tcx,
|
||||
|
@ -31,11 +26,7 @@ pub(crate) fn update<'tcx, T>(
|
|||
.kind()
|
||||
.rebind(
|
||||
// (*) binder moved here
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: tpred.constness,
|
||||
polarity: tpred.polarity,
|
||||
})
|
||||
ty::PredicateKind::Trait(tpred.with_self_type(infcx.tcx, new_self_ty))
|
||||
),
|
||||
);
|
||||
// Don't report overflow errors. Otherwise equivalent to may_hold.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue