From eba10270c6b7927672da6e73f58ec80afff4a2d6 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Fri, 16 Oct 2020 14:04:11 -0400 Subject: [PATCH] map_bound_ref -> rebind --- compiler/rustc_infer/src/infer/combine.rs | 6 ++-- .../rustc_infer/src/infer/nll_relate/mod.rs | 2 +- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_middle/src/ty/_match.rs | 3 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 22 +++++++----- .../src/traits/auto_trait.rs | 8 ++--- .../src/traits/error_reporting/mod.rs | 14 ++++---- .../src/traits/fulfill.rs | 4 +-- .../src/traits/project.rs | 8 ++--- .../src/traits/select/mod.rs | 35 ++++++++----------- compiler/rustc_typeck/src/astconv/mod.rs | 4 +-- compiler/rustc_typeck/src/check/closure.rs | 2 +- compiler/rustc_typeck/src/check/coercion.rs | 2 +- compiler/rustc_typeck/src/check/dropck.rs | 12 +++---- .../rustc_typeck/src/check/method/probe.rs | 2 +- .../rustc_typeck/src/check/method/suggest.rs | 2 +- compiler/rustc_typeck/src/check/mod.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 14 ++++---- src/librustdoc/clean/mod.rs | 7 ++-- 21 files changed, 77 insertions(+), 78 deletions(-) diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index afa6a2a8166a..6a1715ef8189 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -551,8 +551,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, '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())?)) } fn relate_item_substs( @@ -834,8 +833,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, '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())?)) } fn tys(&mut self, t: Ty<'tcx>, _t: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index b1ec7a7902db..abdd6edea902 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -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(a.map_bound(|_| result)) + Ok(ty::Binder::bind(result)) } } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 043d24c9767d..2116c2365263 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -134,7 +134,7 @@ impl Elaborator<'tcx> { let obligations = predicates.predicates.iter().map(|&(pred, _)| { 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.cause.clone(), ) diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index 5f5593eb0d81..27bccc0bcafa 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -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())?)) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index eaddfefb8e5f..acdf1f642ab9 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -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; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 5f326d700ee0..15803dbd8429 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -549,7 +549,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder { type Lifted = ty::Binder; fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option { - 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)) } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 932cadee1003..fd2c7dd5b5ab 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -702,16 +702,14 @@ impl<'tcx> Binder> { 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> { impl<'tcx> Binder<&'tcx List>> { pub fn principal(&self) -> Option>> { - self.map_bound_ref(|b| b.principal()).transpose() + self.map_bound(|b| b.principal()).transpose() } pub fn principal_def_id(&self) -> Option { @@ -1004,6 +1002,14 @@ impl Binder { 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(&self, value: U) -> Binder { + 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 diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 96a0c339e185..867ecea04e42 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -651,10 +651,10 @@ impl AutoTraitFinder<'tcx> { { 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) => { - let p = bound_predicate.map_bound_ref(|_| p); + let p = bound_predicate.rebind(p); debug!( "evaluate_nested_obligations: examining projection predicate {:?}", predicate @@ -784,13 +784,13 @@ impl AutoTraitFinder<'tcx> { } } 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() { return false; } } ty::PredicateAtom::TypeOutlives(binder) => { - let binder = bound_predicate.map_bound_ref(|_| binder); + let binder = bound_predicate.rebind(binder); match ( binder.no_bound_vars(), binder.map_bound_ref(|pred| pred.0).no_bound_vars(), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 3c4394e7d034..2b95da4c5b96 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -258,7 +258,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = obligation.predicate.bound_atom(self.tcx); match bound_predicate.skip_binder() { 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); 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) => { - let predicate = bound_predicate.map_bound_ref(|_| predicate); + let predicate = bound_predicate.rebind(predicate); let predicate = self.resolve_vars_if_possible(&predicate); let err = self .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 (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) { (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. @@ -1094,7 +1094,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = obligation.predicate.bound_atom(self.tcx); if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() { 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. // Eventually I'll need to implement param-env-aware // `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic. @@ -1178,7 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, infer::LateBoundRegionConversionTime::HigherRankedType, - &bound_predicate.map_bound_ref(|_| data), + &bound_predicate.rebind(data), ); let mut obligations = vec![]; 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() { ty::PredicateAtom::Trait(data, _) => { 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); 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) } 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 ty = data.ty; if predicate.references_error() { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 01217457eb4b..495a250be7c1 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { // This means we need to pass it the bound version of our // predicate. 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( obligation, @@ -362,7 +362,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ) } 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( project_obligation, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 295ba6041fb9..63e1fe4a38a9 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -634,9 +634,9 @@ fn prune_cache_value_obligations<'a, 'tcx>( // indirect obligations (e.g., we project to `?0`, // but we have `T: Foo` and `?1: Bar`). - ty::PredicateAtom::Projection(data) => infcx - .unresolved_type_vars(&bound_predicate.map_bound_ref(|_| data.ty)) - .is_some(), + ty::PredicateAtom::Projection(data) => { + infcx.unresolved_type_vars(&bound_predicate.rebind(data.ty)).is_some() + } // We are only interested in `T: Foo` predicates, whre // `U` references one of `unresolved_type_vars`. =) @@ -910,7 +910,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( debug!(?predicate); let bound_predicate = predicate.bound_atom(infcx.tcx); 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 is_match = same_def_id diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 29c9c29d2089..d0f1af253eb3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -449,17 +449,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } 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() { 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()); let obligation = obligation.with(t); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } ty::PredicateAtom::Subtype(p) => { - let p = bound_predicate.map_bound_ref(|_| p); + let p = bound_predicate.rebind(p); // Does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { Some(Ok(InferOk { mut obligations, .. })) => { @@ -503,7 +504,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::PredicateAtom::Projection(data) => { - let data = bound_predicate.map_bound_ref(|_| data); + let data = bound_predicate.rebind(data); let project_obligation = obligation.with(data); match project::poly_project_and_unify_type(self, &project_obligation) { Ok(Ok(Some(mut subobligations))) => { @@ -1177,7 +1178,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .filter_map(|(idx, bound)| { let bound_predicate = bound.bound_atom(self.infcx.tcx); 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(|_| { match self.match_projection( obligation, @@ -1534,15 +1535,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Tuple(tys) => Where( obligation .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) => { let sized_crit = def.sized_constraint(self.tcx()); // (*) binder moved here - Where(obligation.predicate.map_bound_ref(|_| { - sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect() - })) + Where( + obligation.predicate.rebind({ + sized_crit.iter().map(|ty| ty.subst(self.tcx(), substs)).collect() + }), + ) } ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None, @@ -1594,16 +1597,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Array(element_ty, _) => { // (*) binder moved here - Where(obligation.predicate.map_bound_ref(|_| vec![*element_ty])) + Where(obligation.predicate.rebind(vec![*element_ty])) } ty::Tuple(tys) => { // (*) binder moved here - Where( - obligation - .predicate - .map_bound_ref(|_| tys.iter().map(|k| k.expect_ty()).collect()), - ) + Where(obligation.predicate.rebind(tys.iter().map(|k| k.expect_ty()).collect())) } ty::Closure(_, substs) => { @@ -1613,11 +1612,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Not yet resolved. Ambiguous } else { - Where( - obligation - .predicate - .map_bound_ref(|_| substs.as_closure().upvar_tys().collect()), - ) + Where(obligation.predicate.rebind(substs.as_closure().upvar_tys().collect())) } } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index cea7eaec9a71..7674259b8fe4 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1098,7 +1098,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let bound_predicate = obligation.predicate.bound_atom(tcx); match bound_predicate.skip_binder() { 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( tcx.associated_items(pred.def_id()) .in_definition_order() @@ -1107,7 +1107,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ); } 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 // `trait_object_dummy_self`, so check for that. let references_self = diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index 500cc92921b9..5b42a9c4c0bc 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -200,7 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the complete signature. self.deduce_sig_from_projection( Some(obligation.cause.span), - bound_predicate.map_bound_ref(|_| proj_predicate), + bound_predicate.rebind(proj_predicate), ) } else { None diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 0eb5593e8bd7..53ad10020629 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -595,7 +595,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { has_unsized_tuple_coercion = true; } } - bound_predicate.map_bound_ref(|_| trait_pred) + bound_predicate.rebind(trait_pred) } _ => { coercion.obligations.push(obligation); diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index c777b87d4886..9fcb3a8cdfda 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -229,12 +229,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let bound_predicate = predicate.bound_atom(tcx); let bound_p = p.bound_atom(tcx); match (predicate.skip_binders(), p.skip_binders()) { - (ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => relator - .relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b)) - .is_ok(), - (ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => relator - .relate(bound_predicate.map_bound_ref(|_| a), bound_p.map_bound_ref(|_| b)) - .is_ok(), + (ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => { + relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok() + } + (ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => { + relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok() + } _ => predicate == p, } }; diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index e6e7e229f888..a70705bd85a0 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -803,7 +803,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { ty::PredicateAtom::Trait(trait_predicate, _) => { match trait_predicate.trait_ref.self_ty().kind() { 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, } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index d1d6d002d4c9..bd0ac75c8ed9 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -640,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bound_predicate = pred.bound_atom(tcx); match bound_predicate.skip_binder() { ty::PredicateAtom::Projection(pred) => { - let pred = bound_predicate.map_bound_ref(|_| pred); + let pred = bound_predicate.rebind(pred); // `::Item = String`. let trait_ref = pred.skip_binder().projection_ty.trait_ref(self.tcx); diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 124ba91f74c9..94f961218ba4 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -862,7 +862,7 @@ fn bounds_from_generic_predicates<'tcx>( } } ty::PredicateAtom::Projection(projection_pred) => { - projections.push(bound_predicate.map_bound_ref(|_| projection_pred)); + projections.push(bound_predicate.rebind(projection_pred)); } _ => {} } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index f6a4dfd85a5e..20d6bda1f115 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -317,14 +317,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { ) -> FxHashSet { let bound_predicate = pred.bound_atom(tcx); let regions = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(poly_trait_pred, _) => tcx - .collect_referenced_late_bound_regions( - &bound_predicate.map_bound_ref(|_| poly_trait_pred), - ), - ty::PredicateAtom::Projection(poly_proj_pred) => tcx - .collect_referenced_late_bound_regions( - &bound_predicate.map_bound_ref(|_| poly_proj_pred), - ), + ty::PredicateAtom::Trait(poly_trait_pred, _) => { + tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) + } + ty::PredicateAtom::Projection(poly_proj_pred) => { + tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred)) + } _ => return FxHashSet::default(), }; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 776b131a0761..f74dd875ca30 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1689,7 +1689,10 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|bound| { // Note: The substs of opaque types can contain unbound variables, // 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::Binder::bind(tr.trait_ref) } @@ -1713,7 +1716,7 @@ impl<'tcx> Clean for Ty<'tcx> { .iter() .filter_map(|bound| { 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) == trait_ref.skip_binder()