map_bound_ref -> rebind
This commit is contained in:
parent
11d62aa284
commit
eba10270c6
21 changed files with 77 additions and 78 deletions
|
@ -118,7 +118,6 @@ impl TypeRelation<'tcx> for Match<'tcx> {
|
|||
where
|
||||
T: Relate<'tcx>,
|
||||
{
|
||||
let result = self.relate(a.skip_binder(), b.skip_binder())?;
|
||||
Ok(a.map_bound(|_| result))
|
||||
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -620,7 +620,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||
// FIXME(lcnr): Find out why exactly this is the case :)
|
||||
let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx());
|
||||
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
|
||||
let trait_ref = bound_predicate.map_bound(|_| pred.trait_ref);
|
||||
let trait_ref = bound_predicate.rebind(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;
|
||||
|
|
|
@ -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(|v| self.map_bound_ref(|_| v))
|
||||
tcx.lift(self.as_ref().skip_binder()).map(|v| self.rebind(v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -702,16 +702,14 @@ 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) => self
|
||||
.map_bound_ref(|_| tr)
|
||||
.with_self_ty(tcx, self_ty)
|
||||
.without_const()
|
||||
.to_predicate(tcx),
|
||||
ExistentialPredicate::Trait(tr) => {
|
||||
self.rebind(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
|
||||
}
|
||||
ExistentialPredicate::Projection(p) => {
|
||||
self.map_bound_ref(|_| p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
|
||||
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
|
||||
}
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let trait_ref = self.map_bound_ref(|_| ty::TraitRef {
|
||||
let trait_ref = self.rebind(ty::TraitRef {
|
||||
def_id: did,
|
||||
substs: tcx.mk_substs_trait(self_ty, &[]),
|
||||
});
|
||||
|
@ -779,7 +777,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
|
|||
|
||||
impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
|
||||
pub fn principal(&self) -> Option<ty::Binder<ExistentialTraitRef<'tcx>>> {
|
||||
self.map_bound_ref(|b| b.principal()).transpose()
|
||||
self.map_bound(|b| b.principal()).transpose()
|
||||
}
|
||||
|
||||
pub fn principal_def_id(&self) -> Option<DefId> {
|
||||
|
@ -1004,6 +1002,14 @@ impl<T> Binder<T> {
|
|||
Binder(f(self.0))
|
||||
}
|
||||
|
||||
/// Wraps a `value` in a binder, using the same bound variables as the
|
||||
/// current `Binder`. This should not be used if the new value *changes*
|
||||
/// the bound variables. Note: the (old or new) value itself does not
|
||||
/// necessarily need to *name* all the bound variables.
|
||||
pub fn rebind<U>(&self, value: U) -> Binder<U> {
|
||||
Binder(value)
|
||||
}
|
||||
|
||||
/// Unwraps and returns the value within, but only if it contains
|
||||
/// no bound vars at all. (In other words, if this binder --
|
||||
/// and indeed any enclosing binder -- doesn't bind anything at
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue