map_bound_ref -> rebind

This commit is contained in:
Jack Huey 2020-10-16 14:04:11 -04:00
parent 11d62aa284
commit eba10270c6
21 changed files with 77 additions and 78 deletions

View file

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

View file

@ -1004,6 +1004,6 @@ where
self.first_free_index.shift_in(1); self.first_free_index.shift_in(1);
let result = self.relate(a.skip_binder(), a.skip_binder())?; let result = self.relate(a.skip_binder(), a.skip_binder())?;
self.first_free_index.shift_out(1); self.first_free_index.shift_out(1);
Ok(a.map_bound(|_| result)) Ok(ty::Binder::bind(result))
} }
} }

View file

@ -134,7 +134,7 @@ impl Elaborator<'tcx> {
let obligations = predicates.predicates.iter().map(|&(pred, _)| { let obligations = predicates.predicates.iter().map(|&(pred, _)| {
predicate_obligation( predicate_obligation(
pred.subst_supertrait(tcx, &bound_predicate.map_bound(|_| data.trait_ref)), pred.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref)),
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
) )

View file

@ -118,7 +118,6 @@ impl TypeRelation<'tcx> for Match<'tcx> {
where where
T: Relate<'tcx>, T: Relate<'tcx>,
{ {
let result = self.relate(a.skip_binder(), b.skip_binder())?; Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
Ok(a.map_bound(|_| result))
} }
} }

View file

@ -620,7 +620,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(lcnr): Find out why exactly this is the case :) // FIXME(lcnr): Find out why exactly this is the case :)
let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx()); let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx());
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() { 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. // Don't print +Sized, but rather +?Sized if absent.
if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() { if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() {
is_sized = true; 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> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
type Lifted = ty::Binder<T::Lifted>; type Lifted = ty::Binder<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::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))
} }
} }

View file

@ -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> { pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> {
use crate::ty::ToPredicate; use crate::ty::ToPredicate;
match self.skip_binder() { match self.skip_binder() {
ExistentialPredicate::Trait(tr) => self ExistentialPredicate::Trait(tr) => {
.map_bound_ref(|_| tr) self.rebind(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
.with_self_ty(tcx, self_ty) }
.without_const()
.to_predicate(tcx),
ExistentialPredicate::Projection(p) => { 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) => { ExistentialPredicate::AutoTrait(did) => {
let trait_ref = self.map_bound_ref(|_| ty::TraitRef { let trait_ref = self.rebind(ty::TraitRef {
def_id: did, def_id: did,
substs: tcx.mk_substs_trait(self_ty, &[]), substs: tcx.mk_substs_trait(self_ty, &[]),
}); });
@ -779,7 +777,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> { impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
pub fn principal(&self) -> Option<ty::Binder<ExistentialTraitRef<'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> { pub fn principal_def_id(&self) -> Option<DefId> {
@ -1004,6 +1002,14 @@ impl<T> Binder<T> {
Binder(f(self.0)) 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 /// Unwraps and returns the value within, but only if it contains
/// no bound vars at all. (In other words, if this binder -- /// no bound vars at all. (In other words, if this binder --
/// and indeed any enclosing binder -- doesn't bind anything at /// and indeed any enclosing binder -- doesn't bind anything at

View file

@ -651,10 +651,10 @@ impl AutoTraitFinder<'tcx> {
{ {
self.add_user_pred(computed_preds, predicate); self.add_user_pred(computed_preds, predicate);
} }
predicates.push_back(bound_predicate.map_bound_ref(|_| p)); predicates.push_back(bound_predicate.rebind(p));
} }
ty::PredicateAtom::Projection(p) => { ty::PredicateAtom::Projection(p) => {
let p = bound_predicate.map_bound_ref(|_| p); let p = bound_predicate.rebind(p);
debug!( debug!(
"evaluate_nested_obligations: examining projection predicate {:?}", "evaluate_nested_obligations: examining projection predicate {:?}",
predicate predicate
@ -784,13 +784,13 @@ impl AutoTraitFinder<'tcx> {
} }
} }
ty::PredicateAtom::RegionOutlives(binder) => { ty::PredicateAtom::RegionOutlives(binder) => {
let binder = bound_predicate.map_bound_ref(|_| binder); let binder = bound_predicate.rebind(binder);
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() { if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
return false; return false;
} }
} }
ty::PredicateAtom::TypeOutlives(binder) => { ty::PredicateAtom::TypeOutlives(binder) => {
let binder = bound_predicate.map_bound_ref(|_| binder); let binder = bound_predicate.rebind(binder);
match ( match (
binder.no_bound_vars(), binder.no_bound_vars(),
binder.map_bound_ref(|pred| pred.0).no_bound_vars(), binder.map_bound_ref(|pred| pred.0).no_bound_vars(),

View file

@ -258,7 +258,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let bound_predicate = obligation.predicate.bound_atom(self.tcx); let bound_predicate = obligation.predicate.bound_atom(self.tcx);
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
let trait_predicate = bound_predicate.map_bound_ref(|_| trait_predicate); let trait_predicate = bound_predicate.rebind(trait_predicate);
let trait_predicate = self.resolve_vars_if_possible(&trait_predicate); let trait_predicate = self.resolve_vars_if_possible(&trait_predicate);
if self.tcx.sess.has_errors() && trait_predicate.references_error() { if self.tcx.sess.has_errors() && trait_predicate.references_error() {
@ -532,7 +532,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} }
ty::PredicateAtom::RegionOutlives(predicate) => { ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = bound_predicate.map_bound_ref(|_| predicate); let predicate = bound_predicate.rebind(predicate);
let predicate = self.resolve_vars_if_possible(&predicate); let predicate = self.resolve_vars_if_possible(&predicate);
let err = self let err = self
.region_outlives_predicate(&obligation.cause, predicate) .region_outlives_predicate(&obligation.cause, predicate)
@ -1082,7 +1082,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let bound_error = error.bound_atom(self.tcx); let bound_error = error.bound_atom(self.tcx);
let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) { let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) {
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => { (ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
(cond, bound_error.map_bound_ref(|_| error)) (cond, bound_error.rebind(error))
} }
_ => { _ => {
// FIXME: make this work in other cases too. // FIXME: make this work in other cases too.
@ -1094,7 +1094,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let bound_predicate = obligation.predicate.bound_atom(self.tcx); let bound_predicate = obligation.predicate.bound_atom(self.tcx);
if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() { if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() {
let error = error.to_poly_trait_ref(); let error = error.to_poly_trait_ref();
let implication = bound_predicate.map_bound_ref(|_| implication.trait_ref); let implication = bound_predicate.rebind(implication.trait_ref);
// FIXME: I'm just not taking associated types at all here. // FIXME: I'm just not taking associated types at all here.
// Eventually I'll need to implement param-env-aware // Eventually I'll need to implement param-env-aware
// `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic. // `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
@ -1178,7 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let (data, _) = self.replace_bound_vars_with_fresh_vars( let (data, _) = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span, obligation.cause.span,
infer::LateBoundRegionConversionTime::HigherRankedType, infer::LateBoundRegionConversionTime::HigherRankedType,
&bound_predicate.map_bound_ref(|_| data), &bound_predicate.rebind(data),
); );
let mut obligations = vec![]; let mut obligations = vec![];
let normalized_ty = super::normalize_projection_type( let normalized_ty = super::normalize_projection_type(
@ -1463,7 +1463,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut err = match bound_predicate.skip_binder() { let mut err = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => { ty::PredicateAtom::Trait(data, _) => {
let self_ty = data.trait_ref.self_ty(); let self_ty = data.trait_ref.self_ty();
let trait_ref = bound_predicate.map_bound_ref(|_| data.trait_ref); let trait_ref = bound_predicate.rebind(data.trait_ref);
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind(), trait_ref); debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind(), trait_ref);
if predicate.references_error() { if predicate.references_error() {
@ -1587,7 +1587,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282) self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282)
} }
ty::PredicateAtom::Projection(data) => { ty::PredicateAtom::Projection(data) => {
let trait_ref = bound_predicate.map_bound_ref(|_| data).to_poly_trait_ref(self.tcx); let trait_ref = bound_predicate.rebind(data).to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.skip_binder().self_ty(); let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.ty; let ty = data.ty;
if predicate.references_error() { if predicate.references_error() {

View file

@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
// This means we need to pass it the bound version of our // This means we need to pass it the bound version of our
// predicate. // predicate.
ty::PredicateAtom::Trait(trait_ref, _constness) => { ty::PredicateAtom::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(binder.map_bound_ref(|_| trait_ref)); let trait_obligation = obligation.with(binder.rebind(trait_ref));
self.process_trait_obligation( self.process_trait_obligation(
obligation, obligation,
@ -362,7 +362,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
) )
} }
ty::PredicateAtom::Projection(data) => { ty::PredicateAtom::Projection(data) => {
let project_obligation = obligation.with(binder.map_bound_ref(|_| data)); let project_obligation = obligation.with(binder.rebind(data));
self.process_projection_obligation( self.process_projection_obligation(
project_obligation, project_obligation,

View file

@ -634,9 +634,9 @@ fn prune_cache_value_obligations<'a, 'tcx>(
// indirect obligations (e.g., we project to `?0`, // indirect obligations (e.g., we project to `?0`,
// but we have `T: Foo<X = ?1>` and `?1: Bar<X = // but we have `T: Foo<X = ?1>` and `?1: Bar<X =
// ?0>`). // ?0>`).
ty::PredicateAtom::Projection(data) => infcx ty::PredicateAtom::Projection(data) => {
.unresolved_type_vars(&bound_predicate.map_bound_ref(|_| data.ty)) infcx.unresolved_type_vars(&bound_predicate.rebind(data.ty)).is_some()
.is_some(), }
// We are only interested in `T: Foo<X = U>` predicates, whre // We are only interested in `T: Foo<X = U>` predicates, whre
// `U` references one of `unresolved_type_vars`. =) // `U` references one of `unresolved_type_vars`. =)
@ -910,7 +910,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
debug!(?predicate); debug!(?predicate);
let bound_predicate = predicate.bound_atom(infcx.tcx); let bound_predicate = predicate.bound_atom(infcx.tcx);
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() { if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let data = bound_predicate.map_bound_ref(|_| data); let data = bound_predicate.rebind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
let is_match = same_def_id let is_match = same_def_id

View file

@ -449,17 +449,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
let result = ensure_sufficient_stack(|| { let result = ensure_sufficient_stack(|| {
let bound_predicate = obligation.predicate.bound_atom(self.infcx().tcx); let bound_predicate =
obligation.predicate.bound_atom_with_opt_escaping(self.infcx().tcx);
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(t, _) => { ty::PredicateAtom::Trait(t, _) => {
let t = bound_predicate.map_bound_ref(|_| t); let t = bound_predicate.rebind(t);
debug_assert!(!t.has_escaping_bound_vars()); debug_assert!(!t.has_escaping_bound_vars());
let obligation = obligation.with(t); let obligation = obligation.with(t);
self.evaluate_trait_predicate_recursively(previous_stack, obligation) self.evaluate_trait_predicate_recursively(previous_stack, obligation)
} }
ty::PredicateAtom::Subtype(p) => { ty::PredicateAtom::Subtype(p) => {
let p = bound_predicate.map_bound_ref(|_| p); let p = bound_predicate.rebind(p);
// Does this code ever run? // Does this code ever run?
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
Some(Ok(InferOk { mut obligations, .. })) => { Some(Ok(InferOk { mut obligations, .. })) => {
@ -503,7 +504,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
ty::PredicateAtom::Projection(data) => { ty::PredicateAtom::Projection(data) => {
let data = bound_predicate.map_bound_ref(|_| data); let data = bound_predicate.rebind(data);
let project_obligation = obligation.with(data); let project_obligation = obligation.with(data);
match project::poly_project_and_unify_type(self, &project_obligation) { match project::poly_project_and_unify_type(self, &project_obligation) {
Ok(Ok(Some(mut subobligations))) => { Ok(Ok(Some(mut subobligations))) => {
@ -1177,7 +1178,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.filter_map(|(idx, bound)| { .filter_map(|(idx, bound)| {
let bound_predicate = bound.bound_atom(self.infcx.tcx); let bound_predicate = bound.bound_atom(self.infcx.tcx);
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() { if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let bound = bound_predicate.map_bound_ref(|_| pred.trait_ref); let bound = bound_predicate.rebind(pred.trait_ref);
if self.infcx.probe(|_| { if self.infcx.probe(|_| {
match self.match_projection( match self.match_projection(
obligation, obligation,
@ -1534,15 +1535,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Tuple(tys) => Where( ty::Tuple(tys) => Where(
obligation obligation
.predicate .predicate
.map_bound_ref(|_| tys.last().into_iter().map(|k| k.expect_ty()).collect()), .rebind(tys.last().into_iter().map(|k| k.expect_ty()).collect()),
), ),
ty::Adt(def, substs) => { ty::Adt(def, substs) => {
let sized_crit = def.sized_constraint(self.tcx()); let sized_crit = def.sized_constraint(self.tcx());
// (*) binder moved here // (*) binder moved here
Where(obligation.predicate.map_bound_ref(|_| { Where(
sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect() obligation.predicate.rebind({
})) sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect()
}),
)
} }
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None, ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
@ -1594,16 +1597,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Array(element_ty, _) => { ty::Array(element_ty, _) => {
// (*) binder moved here // (*) binder moved here
Where(obligation.predicate.map_bound_ref(|_| vec![*element_ty])) Where(obligation.predicate.rebind(vec![*element_ty]))
} }
ty::Tuple(tys) => { ty::Tuple(tys) => {
// (*) binder moved here // (*) binder moved here
Where( Where(obligation.predicate.rebind(tys.iter().map(|k| k.expect_ty()).collect()))
obligation
.predicate
.map_bound_ref(|_| tys.iter().map(|k| k.expect_ty()).collect()),
)
} }
ty::Closure(_, substs) => { ty::Closure(_, substs) => {
@ -1613,11 +1612,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Not yet resolved. // Not yet resolved.
Ambiguous Ambiguous
} else { } else {
Where( Where(obligation.predicate.rebind(substs.as_closure().upvar_tys().collect()))
obligation
.predicate
.map_bound_ref(|_| substs.as_closure().upvar_tys().collect()),
)
} }
} }

View file

@ -1098,7 +1098,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let bound_predicate = obligation.predicate.bound_atom(tcx); let bound_predicate = obligation.predicate.bound_atom(tcx);
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(pred, _) => { ty::PredicateAtom::Trait(pred, _) => {
let pred = bound_predicate.map_bound_ref(|_| pred); let pred = bound_predicate.rebind(pred);
associated_types.entry(span).or_default().extend( associated_types.entry(span).or_default().extend(
tcx.associated_items(pred.def_id()) tcx.associated_items(pred.def_id())
.in_definition_order() .in_definition_order()
@ -1107,7 +1107,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
); );
} }
ty::PredicateAtom::Projection(pred) => { ty::PredicateAtom::Projection(pred) => {
let pred = bound_predicate.map_bound_ref(|_| pred); let pred = bound_predicate.rebind(pred);
// A `Self` within the original bound will be substituted with a // A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that. // `trait_object_dummy_self`, so check for that.
let references_self = let references_self =

View file

@ -200,7 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the complete signature. // the complete signature.
self.deduce_sig_from_projection( self.deduce_sig_from_projection(
Some(obligation.cause.span), Some(obligation.cause.span),
bound_predicate.map_bound_ref(|_| proj_predicate), bound_predicate.rebind(proj_predicate),
) )
} else { } else {
None None

View file

@ -595,7 +595,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
has_unsized_tuple_coercion = true; has_unsized_tuple_coercion = true;
} }
} }
bound_predicate.map_bound_ref(|_| trait_pred) bound_predicate.rebind(trait_pred)
} }
_ => { _ => {
coercion.obligations.push(obligation); coercion.obligations.push(obligation);

View file

@ -229,12 +229,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
let bound_predicate = predicate.bound_atom(tcx); let bound_predicate = predicate.bound_atom(tcx);
let bound_p = p.bound_atom(tcx); let bound_p = p.bound_atom(tcx);
match (predicate.skip_binders(), p.skip_binders()) { match (predicate.skip_binders(), p.skip_binders()) {
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => relator (ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
.relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b)) relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
.is_ok(), }
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => relator (ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
.relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b)) relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
.is_ok(), }
_ => predicate == p, _ => predicate == p,
} }
}; };

View file

@ -803,7 +803,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
match trait_predicate.trait_ref.self_ty().kind() { match trait_predicate.trait_ref.self_ty().kind() {
ty::Param(ref p) if *p == param_ty => { ty::Param(ref p) if *p == param_ty => {
Some(bound_predicate.map_bound_ref(|_| trait_predicate.trait_ref)) Some(bound_predicate.rebind(trait_predicate.trait_ref))
} }
_ => None, _ => None,
} }

View file

@ -640,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let bound_predicate = pred.bound_atom(tcx); let bound_predicate = pred.bound_atom(tcx);
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Projection(pred) => { ty::PredicateAtom::Projection(pred) => {
let pred = bound_predicate.map_bound_ref(|_| pred); let pred = bound_predicate.rebind(pred);
// `<Foo as Iterator>::Item = String`. // `<Foo as Iterator>::Item = String`.
let trait_ref = let trait_ref =
pred.skip_binder().projection_ty.trait_ref(self.tcx); pred.skip_binder().projection_ty.trait_ref(self.tcx);

View file

@ -862,7 +862,7 @@ fn bounds_from_generic_predicates<'tcx>(
} }
} }
ty::PredicateAtom::Projection(projection_pred) => { ty::PredicateAtom::Projection(projection_pred) => {
projections.push(bound_predicate.map_bound_ref(|_| projection_pred)); projections.push(bound_predicate.rebind(projection_pred));
} }
_ => {} _ => {}
} }

View file

@ -317,14 +317,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
) -> FxHashSet<GenericParamDef> { ) -> FxHashSet<GenericParamDef> {
let bound_predicate = pred.bound_atom(tcx); let bound_predicate = pred.bound_atom(tcx);
let regions = match bound_predicate.skip_binder() { let regions = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(poly_trait_pred, _) => tcx ty::PredicateAtom::Trait(poly_trait_pred, _) => {
.collect_referenced_late_bound_regions( tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))
&bound_predicate.map_bound_ref(|_| poly_trait_pred), }
), ty::PredicateAtom::Projection(poly_proj_pred) => {
ty::PredicateAtom::Projection(poly_proj_pred) => tcx tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred))
.collect_referenced_late_bound_regions( }
&bound_predicate.map_bound_ref(|_| poly_proj_pred),
),
_ => return FxHashSet::default(), _ => return FxHashSet::default(),
}; };

View file

@ -1689,7 +1689,10 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
.filter_map(|bound| { .filter_map(|bound| {
// Note: The substs of opaque types can contain unbound variables, // Note: The substs of opaque types can contain unbound variables,
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
let trait_ref = match bound.bound_atom(cx.tcx).skip_binder() { let trait_ref = match bound
.bound_atom_with_opt_escaping(cx.tcx)
.skip_binder()
{
ty::PredicateAtom::Trait(tr, _constness) => { ty::PredicateAtom::Trait(tr, _constness) => {
ty::Binder::bind(tr.trait_ref) ty::Binder::bind(tr.trait_ref)
} }
@ -1713,7 +1716,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
.iter() .iter()
.filter_map(|bound| { .filter_map(|bound| {
if let ty::PredicateAtom::Projection(proj) = if let ty::PredicateAtom::Projection(proj) =
bound.bound_atom(cx.tcx).skip_binder() bound.bound_atom_with_opt_escaping(cx.tcx).skip_binder()
{ {
if proj.projection_ty.trait_ref(cx.tcx) if proj.projection_ty.trait_ref(cx.tcx)
== trait_ref.skip_binder() == trait_ref.skip_binder()