1
Fork 0

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

@ -118,6 +118,7 @@ impl TypeRelation<'tcx> for Match<'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))
}
}

View file

@ -618,10 +618,9 @@ pub trait PrettyPrinter<'tcx>:
// may contain unbound variables. We therefore do this manually.
//
// FIXME(lcnr): Find out why exactly this is the case :)
if let ty::PredicateAtom::Trait(pred, _) =
predicate.bound_atom(self.tcx()).skip_binder()
{
let trait_ref = ty::Binder::bind(pred.trait_ref);
let bound_predicate = predicate.bound_atom(self.tcx());
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let trait_ref = bound_predicate.map_bound(|_| pred.trait_ref);
// Don't print +Sized, but rather +?Sized if absent.
if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() {
is_sized = true;

View file

@ -549,7 +549,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
type Lifted = ty::Binder<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(self.as_ref().skip_binder()).map(ty::Binder::bind)
tcx.lift(self.as_ref().skip_binder()).map(|v| self.map_bound_ref(|_| v))
}
}

View file

@ -702,15 +702,19 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> {
use crate::ty::ToPredicate;
match self.skip_binder() {
ExistentialPredicate::Trait(tr) => {
Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
}
ExistentialPredicate::Trait(tr) => self
.map_bound_ref(|_| tr)
.with_self_ty(tcx, self_ty)
.without_const()
.to_predicate(tcx),
ExistentialPredicate::Projection(p) => {
Binder(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
self.map_bound_ref(|_| p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
}
ExistentialPredicate::AutoTrait(did) => {
let trait_ref =
Binder(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]) });
let trait_ref = self.map_bound_ref(|_| ty::TraitRef {
def_id: did,
substs: tcx.mk_substs_trait(self_ty, &[]),
});
trait_ref.without_const().to_predicate(tcx)
}
}
@ -775,7 +779,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
pub fn principal(&self) -> Option<ty::Binder<ExistentialTraitRef<'tcx>>> {
self.skip_binder().principal().map(Binder::bind)
self.map_bound_ref(|b| b.principal()).transpose()
}
pub fn principal_def_id(&self) -> Option<DefId> {
@ -858,8 +862,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
}
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
// Note that we preserve binding levels
Binder(ty::TraitPredicate { trait_ref: self.skip_binder() })
self.map_bound(|trait_ref| ty::TraitPredicate { trait_ref })
}
}