Use map_bound(_ref) instead of Binder::bind when possible

This commit is contained in:
Jack Huey 2020-10-07 20:02:06 -04:00
parent a78a62fc99
commit dd5c9bf139
24 changed files with 173 additions and 143 deletions

View file

@ -551,7 +551,8 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
where
T: Relate<'tcx>,
{
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
let result = self.relate(a.skip_binder(), b.skip_binder())?;
Ok(a.map_bound(|_| result))
}
fn relate_item_substs(
@ -833,7 +834,8 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
where
T: Relate<'tcx>,
{
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
let result = self.relate(a.skip_binder(), b.skip_binder())?;
Ok(a.map_bound(|_| result))
}
fn tys(&mut self, t: Ty<'tcx>, _t: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {

View file

@ -636,7 +636,7 @@ where
if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars()) {
// Fast path for the common case.
self.relate(a, b)?;
return Ok(ty::Binder::bind(a));
return Ok(ty::Binder::dummy(a));
}
if self.ambient_covariance() {
@ -1004,6 +1004,6 @@ where
self.first_free_index.shift_in(1);
let result = self.relate(a.skip_binder(), a.skip_binder())?;
self.first_free_index.shift_out(1);
Ok(ty::Binder::bind(result))
Ok(a.map_bound(|_| result))
}
}

View file

@ -126,14 +126,15 @@ impl Elaborator<'tcx> {
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
match obligation.predicate.skip_binders() {
let bound_predicate = obligation.predicate.bound_atom(tcx);
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());
let obligations = predicates.predicates.iter().map(|&(pred, _)| {
predicate_obligation(
pred.subst_supertrait(tcx, &ty::Binder::bind(data.trait_ref)),
pred.subst_supertrait(tcx, &bound_predicate.map_bound(|_| data.trait_ref)),
obligation.param_env,
obligation.cause.clone(),
)