1
Fork 0

Replacing bound vars is actually instantiating a binder

This commit is contained in:
Michael Goulet 2023-02-07 23:13:22 +00:00
parent bd39bbb4bb
commit 03a8a4ff3e
28 changed files with 67 additions and 60 deletions

View file

@ -1139,7 +1139,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if let ty::Adt(def, substs) = ty.kind() if let ty::Adt(def, substs) = ty.kind()
&& Some(def.did()) == tcx.lang_items().pin_type() && Some(def.did()) == tcx.lang_items().pin_type()
&& let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind() && let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind()
&& let self_ty = infcx.replace_bound_vars_with_fresh_vars( && let self_ty = infcx.instantiate_binder_with_fresh_vars(
fn_call_span, fn_call_span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
tcx.fn_sig(method_did).subst(tcx, method_substs).input(0), tcx.fn_sig(method_did).subst(tcx, method_substs).input(0),

View file

@ -38,7 +38,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// so that they represent the view from "inside" the closure. // so that they represent the view from "inside" the closure.
let user_provided_sig = self let user_provided_sig = self
.instantiate_canonical_with_fresh_inference_vars(body.span, &user_provided_poly_sig); .instantiate_canonical_with_fresh_inference_vars(body.span, &user_provided_poly_sig);
let user_provided_sig = self.infcx.replace_bound_vars_with_fresh_vars( let user_provided_sig = self.infcx.instantiate_binder_with_fresh_vars(
body.span, body.span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
user_provided_sig, user_provided_sig,

View file

@ -246,7 +246,7 @@ fn compare_method_predicate_entailment<'tcx>(
let mut wf_tys = FxIndexSet::default(); let mut wf_tys = FxIndexSet::default();
let unnormalized_impl_sig = infcx.replace_bound_vars_with_fresh_vars( let unnormalized_impl_sig = infcx.instantiate_binder_with_fresh_vars(
impl_m_span, impl_m_span,
infer::HigherRankedType, infer::HigherRankedType,
tcx.fn_sig(impl_m.def_id).subst_identity(), tcx.fn_sig(impl_m.def_id).subst_identity(),
@ -640,7 +640,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
let impl_sig = ocx.normalize( let impl_sig = ocx.normalize(
&norm_cause, &norm_cause,
param_env, param_env,
infcx.replace_bound_vars_with_fresh_vars( infcx.instantiate_binder_with_fresh_vars(
return_span, return_span,
infer::HigherRankedType, infer::HigherRankedType,
tcx.fn_sig(impl_m.def_id).subst_identity(), tcx.fn_sig(impl_m.def_id).subst_identity(),

View file

@ -156,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// fnmut vs fnonce. If so, we have to defer further processing. // fnmut vs fnonce. If so, we have to defer further processing.
if self.closure_kind(substs).is_none() { if self.closure_kind(substs).is_none() {
let closure_sig = substs.as_closure().sig(); let closure_sig = substs.as_closure().sig();
let closure_sig = self.replace_bound_vars_with_fresh_vars( let closure_sig = self.instantiate_binder_with_fresh_vars(
call_expr.span, call_expr.span,
infer::FnCall, infer::FnCall,
closure_sig, closure_sig,
@ -437,7 +437,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// renormalize the associated types at this point, since they // renormalize the associated types at this point, since they
// previously appeared within a `Binder<>` and hence would not // previously appeared within a `Binder<>` and hence would not
// have been normalized before. // have been normalized before.
let fn_sig = self.replace_bound_vars_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig); let fn_sig = self.instantiate_binder_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig);
let fn_sig = self.normalize(call_expr.span, fn_sig); let fn_sig = self.normalize(call_expr.span, fn_sig);
// Call the generic checker. // Call the generic checker.

View file

@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
.map(|(hir_ty, &supplied_ty)| { .map(|(hir_ty, &supplied_ty)| {
// Instantiate (this part of..) S to S', i.e., with fresh variables. // Instantiate (this part of..) S to S', i.e., with fresh variables.
self.replace_bound_vars_with_fresh_vars( self.instantiate_binder_with_fresh_vars(
hir_ty.span, hir_ty.span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
// (*) binder moved to here // (*) binder moved to here
@ -566,7 +566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
all_obligations.extend(obligations); all_obligations.extend(obligations);
} }
let supplied_output_ty = self.replace_bound_vars_with_fresh_vars( let supplied_output_ty = self.instantiate_binder_with_fresh_vars(
decl.output.span(), decl.output.span(),
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
supplied_sig.output(), supplied_sig.output(),

View file

@ -568,7 +568,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// placeholder lifetimes with probing, we just replace higher lifetimes // placeholder lifetimes with probing, we just replace higher lifetimes
// with fresh vars. // with fresh vars.
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span); let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
let input = self.replace_bound_vars_with_fresh_vars( let input = self.instantiate_binder_with_fresh_vars(
span, span,
infer::LateBoundRegionConversionTime::FnCall, infer::LateBoundRegionConversionTime::FnCall,
fn_sig.input(i), fn_sig.input(i),
@ -586,7 +586,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Also, as we just want to check sizedness, instead of introducing // Also, as we just want to check sizedness, instead of introducing
// placeholder lifetimes with probing, we just replace higher lifetimes // placeholder lifetimes with probing, we just replace higher lifetimes
// with fresh vars. // with fresh vars.
let output = self.replace_bound_vars_with_fresh_vars( let output = self.instantiate_binder_with_fresh_vars(
expr.span, expr.span,
infer::LateBoundRegionConversionTime::FnCall, infer::LateBoundRegionConversionTime::FnCall,
fn_sig.output(), fn_sig.output(),

View file

@ -289,7 +289,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
item_segment: &hir::PathSegment<'_>, item_segment: &hir::PathSegment<'_>,
poly_trait_ref: ty::PolyTraitRef<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let trait_ref = self.replace_bound_vars_with_fresh_vars( let trait_ref = self.instantiate_binder_with_fresh_vars(
span, span,
infer::LateBoundRegionConversionTime::AssocTypeProjection(item_def_id), infer::LateBoundRegionConversionTime::AssocTypeProjection(item_def_id),
poly_trait_ref, poly_trait_ref,

View file

@ -262,7 +262,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty); let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty);
let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id); let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id);
let upcast_trait_ref = let upcast_trait_ref =
this.replace_bound_vars_with_fresh_vars(upcast_poly_trait_ref); this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref);
debug!( debug!(
"original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}", "original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}",
original_poly_trait_ref, upcast_trait_ref, trait_def_id original_poly_trait_ref, upcast_trait_ref, trait_def_id
@ -285,7 +285,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
probe::WhereClausePick(poly_trait_ref) => { probe::WhereClausePick(poly_trait_ref) => {
// Where clauses can have bound regions in them. We need to instantiate // Where clauses can have bound regions in them. We need to instantiate
// those to convert from a poly-trait-ref to a trait-ref. // those to convert from a poly-trait-ref to a trait-ref.
self.replace_bound_vars_with_fresh_vars(poly_trait_ref).substs self.instantiate_binder_with_fresh_vars(poly_trait_ref).substs
} }
} }
} }
@ -506,7 +506,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let sig = self.tcx.fn_sig(def_id).subst(self.tcx, all_substs); let sig = self.tcx.fn_sig(def_id).subst(self.tcx, all_substs);
debug!("type scheme substituted, sig={:?}", sig); debug!("type scheme substituted, sig={:?}", sig);
let sig = self.replace_bound_vars_with_fresh_vars(sig); let sig = self.instantiate_binder_with_fresh_vars(sig);
debug!("late-bound lifetimes from method instantiated, sig={:?}", sig); debug!("late-bound lifetimes from method instantiated, sig={:?}", sig);
(sig, method_predicates) (sig, method_predicates)
@ -625,10 +625,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
upcast_trait_refs.into_iter().next().unwrap() upcast_trait_refs.into_iter().next().unwrap()
} }
fn replace_bound_vars_with_fresh_vars<T>(&self, value: ty::Binder<'tcx, T>) -> T fn instantiate_binder_with_fresh_vars<T>(&self, value: ty::Binder<'tcx, T>) -> T
where where
T: TypeFoldable<'tcx> + Copy, T: TypeFoldable<'tcx> + Copy,
{ {
self.fcx.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, value) self.fcx.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, value)
} }
} }

View file

@ -401,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// with bound regions. // with bound regions.
let fn_sig = tcx.fn_sig(def_id).subst(self.tcx, substs); let fn_sig = tcx.fn_sig(def_id).subst(self.tcx, substs);
let fn_sig = let fn_sig =
self.replace_bound_vars_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig); self.instantiate_binder_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);
let InferOk { value, obligations: o } = let InferOk { value, obligations: o } =
self.at(&obligation.cause, self.param_env).normalize(fn_sig); self.at(&obligation.cause, self.param_env).normalize(fn_sig);

View file

@ -924,7 +924,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
ty::AssocKind::Fn => self.probe(|_| { ty::AssocKind::Fn => self.probe(|_| {
let substs = self.fresh_substs_for_item(self.span, method.def_id); let substs = self.fresh_substs_for_item(self.span, method.def_id);
let fty = self.tcx.fn_sig(method.def_id).subst(self.tcx, substs); let fty = self.tcx.fn_sig(method.def_id).subst(self.tcx, substs);
let fty = self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty); let fty = self.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, fty);
if let Some(self_ty) = self_ty { if let Some(self_ty) = self_ty {
if self if self

View file

@ -129,7 +129,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
let a_types = infcx.tcx.anonymize_bound_vars(a_types); let a_types = infcx.tcx.anonymize_bound_vars(a_types);
let b_types = infcx.tcx.anonymize_bound_vars(b_types); let b_types = infcx.tcx.anonymize_bound_vars(b_types);
if a_types.bound_vars() == b_types.bound_vars() { if a_types.bound_vars() == b_types.bound_vars() {
let (a_types, b_types) = infcx.replace_bound_vars_with_placeholders( let (a_types, b_types) = infcx.instantiate_binder_with_placeholders(
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())), a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
); );
for (a, b) in std::iter::zip(a_types, b_types) { for (a, b) in std::iter::zip(a_types, b_types) {

View file

@ -38,13 +38,13 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
// First, we instantiate each bound region in the supertype with a // First, we instantiate each bound region in the supertype with a
// fresh placeholder region. Note that this automatically creates // fresh placeholder region. Note that this automatically creates
// a new universe if needed. // a new universe if needed.
let sup_prime = self.infcx.replace_bound_vars_with_placeholders(sup); let sup_prime = self.infcx.instantiate_binder_with_placeholders(sup);
// Next, we instantiate each bound region in the subtype // Next, we instantiate each bound region in the subtype
// with a fresh region variable. These region variables -- // with a fresh region variable. These region variables --
// but no other pre-existing region variables -- can name // but no other pre-existing region variables -- can name
// the placeholders. // the placeholders.
let sub_prime = self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, sub); let sub_prime = self.infcx.instantiate_binder_with_fresh_vars(span, HigherRankedType, sub);
debug!("a_prime={:?}", sub_prime); debug!("a_prime={:?}", sub_prime);
debug!("b_prime={:?}", sup_prime); debug!("b_prime={:?}", sup_prime);
@ -70,7 +70,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// ///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: ty::Binder<'tcx, T>) -> T pub fn instantiate_binder_with_placeholders<T>(&self, binder: ty::Binder<'tcx, T>) -> T
where where
T: TypeFoldable<'tcx> + Copy, T: TypeFoldable<'tcx> + Copy,
{ {

View file

@ -995,7 +995,7 @@ impl<'tcx> InferCtxt<'tcx> {
Ok(self.commit_if_ok(|_snapshot| { Ok(self.commit_if_ok(|_snapshot| {
let ty::SubtypePredicate { a_is_expected, a, b } = let ty::SubtypePredicate { a_is_expected, a, b } =
self.replace_bound_vars_with_placeholders(predicate); self.instantiate_binder_with_placeholders(predicate);
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?; let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
@ -1008,7 +1008,7 @@ impl<'tcx> InferCtxt<'tcx> {
cause: &traits::ObligationCause<'tcx>, cause: &traits::ObligationCause<'tcx>,
predicate: ty::PolyRegionOutlivesPredicate<'tcx>, predicate: ty::PolyRegionOutlivesPredicate<'tcx>,
) { ) {
let ty::OutlivesPredicate(r_a, r_b) = self.replace_bound_vars_with_placeholders(predicate); let ty::OutlivesPredicate(r_a, r_b) = self.instantiate_binder_with_placeholders(predicate);
let origin = let origin =
SubregionOrigin::from_obligation_cause(cause, || RelateRegionParamBound(cause.span)); SubregionOrigin::from_obligation_cause(cause, || RelateRegionParamBound(cause.span));
self.sub_regions(origin, r_b, r_a); // `b : a` ==> `a <= b` self.sub_regions(origin, r_b, r_a); // `b : a` ==> `a <= b`
@ -1447,7 +1447,14 @@ impl<'tcx> InferCtxt<'tcx> {
value value
} }
pub fn replace_bound_vars_with_fresh_vars<T>( // Instantiates the bound variables in a given binder with fresh inference
// variables in the current universe.
//
// Use this method if you'd like to find some substitution of the binder's
// variables (e.g. during a method call). If there isn't a [`LateBoundRegionConversionTime`]
// that corresponds to your use case, consider whether or not you should
// use [`InferCtxt::instantiate_binder_with_placeholders`] instead.
pub fn instantiate_binder_with_fresh_vars<T>(
&self, &self,
span: Span, span: Span,
lbrct: LateBoundRegionConversionTime, lbrct: LateBoundRegionConversionTime,

View file

@ -161,7 +161,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
let a_types = infcx.tcx.anonymize_bound_vars(a_types); let a_types = infcx.tcx.anonymize_bound_vars(a_types);
let b_types = infcx.tcx.anonymize_bound_vars(b_types); let b_types = infcx.tcx.anonymize_bound_vars(b_types);
if a_types.bound_vars() == b_types.bound_vars() { if a_types.bound_vars() == b_types.bound_vars() {
let (a_types, b_types) = infcx.replace_bound_vars_with_placeholders( let (a_types, b_types) = infcx.instantiate_binder_with_placeholders(
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())), a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
); );
for (a, b) in std::iter::zip(a_types, b_types) { for (a, b) in std::iter::zip(a_types, b_types) {

View file

@ -74,7 +74,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
) )
} }
ty::PredicateKind::Subtype(pred) => { ty::PredicateKind::Subtype(pred) => {
let (a, b) = infcx.replace_bound_vars_with_placeholders( let (a, b) = infcx.instantiate_binder_with_placeholders(
goal.predicate.kind().rebind((pred.a, pred.b)), goal.predicate.kind().rebind((pred.a, pred.b)),
); );
let expected_found = ExpectedFound::new(true, a, b); let expected_found = ExpectedFound::new(true, a, b);
@ -84,7 +84,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
) )
} }
ty::PredicateKind::Coerce(pred) => { ty::PredicateKind::Coerce(pred) => {
let (a, b) = infcx.replace_bound_vars_with_placeholders( let (a, b) = infcx.instantiate_binder_with_placeholders(
goal.predicate.kind().rebind((pred.a, pred.b)), goal.predicate.kind().rebind((pred.a, pred.b)),
); );
let expected_found = ExpectedFound::new(false, a, b); let expected_found = ExpectedFound::new(false, a, b);
@ -94,7 +94,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
) )
} }
ty::PredicateKind::ConstEquate(a, b) => { ty::PredicateKind::ConstEquate(a, b) => {
let (a, b) = infcx.replace_bound_vars_with_placeholders( let (a, b) = infcx.instantiate_binder_with_placeholders(
goal.predicate.kind().rebind((a, b)), goal.predicate.kind().rebind((a, b)),
); );
let expected_found = ExpectedFound::new(true, a, b); let expected_found = ExpectedFound::new(true, a, b);

View file

@ -26,7 +26,7 @@ pub(super) trait InferCtxtExt<'tcx> {
rhs: T, rhs: T,
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>; ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>( fn instantiate_binder_with_infer<T: TypeFoldable<'tcx> + Copy>(
&self, &self,
value: ty::Binder<'tcx, T>, value: ty::Binder<'tcx, T>,
) -> T; ) -> T;
@ -65,11 +65,11 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}) })
} }
fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>( fn instantiate_binder_with_infer<T: TypeFoldable<'tcx> + Copy>(
&self, &self,
value: ty::Binder<'tcx, T>, value: ty::Binder<'tcx, T>,
) -> T { ) -> T {
self.replace_bound_vars_with_fresh_vars( self.instantiate_binder_with_fresh_vars(
DUMMY_SP, DUMMY_SP,
LateBoundRegionConversionTime::HigherRankedType, LateBoundRegionConversionTime::HigherRankedType,
value, value,

View file

@ -304,7 +304,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
} }
} }
} else { } else {
let kind = self.infcx.replace_bound_vars_with_placeholders(kind); let kind = self.infcx.instantiate_binder_with_placeholders(kind);
let goal = goal.with(self.tcx(), ty::Binder::dummy(kind)); let goal = goal.with(self.tcx(), ty::Binder::dummy(kind));
let (_, certainty) = self.evaluate_goal(goal)?; let (_, certainty) = self.evaluate_goal(goal)?;
self.make_canonical_response(certainty) self.make_canonical_response(certainty)

View file

@ -323,7 +323,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
{ {
ecx.infcx.probe(|_| { ecx.infcx.probe(|_| {
let assumption_projection_pred = let assumption_projection_pred =
ecx.infcx.instantiate_bound_vars_with_infer(poly_projection_pred); ecx.infcx.instantiate_binder_with_infer(poly_projection_pred);
let nested_goals = ecx.infcx.eq( let nested_goals = ecx.infcx.eq(
goal.param_env, goal.param_env,
goal.predicate.projection_ty, goal.predicate.projection_ty,

View file

@ -72,7 +72,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
// FIXME: Constness and polarity // FIXME: Constness and polarity
ecx.infcx.probe(|_| { ecx.infcx.probe(|_| {
let assumption_trait_pred = let assumption_trait_pred =
ecx.infcx.instantiate_bound_vars_with_infer(poly_trait_pred); ecx.infcx.instantiate_binder_with_infer(poly_trait_pred);
let nested_goals = ecx.infcx.eq( let nested_goals = ecx.infcx.eq(
goal.param_env, goal.param_env,
goal.predicate.trait_ref, goal.predicate.trait_ref,

View file

@ -54,7 +54,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
} }
ty::GeneratorWitness(types) => { ty::GeneratorWitness(types) => {
Ok(infcx.replace_bound_vars_with_placeholders(types).to_vec()) Ok(infcx.instantiate_binder_with_placeholders(types).to_vec())
} }
ty::GeneratorWitnessMIR(..) => todo!(), ty::GeneratorWitnessMIR(..) => todo!(),
@ -174,7 +174,7 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
} }
ty::GeneratorWitness(types) => { ty::GeneratorWitness(types) => {
Ok(infcx.replace_bound_vars_with_placeholders(types).to_vec()) Ok(infcx.instantiate_binder_with_placeholders(types).to_vec())
} }
ty::GeneratorWitnessMIR(..) => todo!(), ty::GeneratorWitnessMIR(..) => todo!(),

View file

@ -22,7 +22,7 @@ pub fn recompute_applicable_impls<'tcx>(
let impl_may_apply = |impl_def_id| { let impl_may_apply = |impl_def_id| {
let ocx = ObligationCtxt::new_in_snapshot(infcx); let ocx = ObligationCtxt::new_in_snapshot(infcx);
let placeholder_obligation = let placeholder_obligation =
infcx.replace_bound_vars_with_placeholders(obligation.predicate); infcx.instantiate_binder_with_placeholders(obligation.predicate);
let obligation_trait_ref = let obligation_trait_ref =
ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref); ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref);
@ -47,11 +47,11 @@ pub fn recompute_applicable_impls<'tcx>(
let param_env_candidate_may_apply = |poly_trait_predicate: ty::PolyTraitPredicate<'tcx>| { let param_env_candidate_may_apply = |poly_trait_predicate: ty::PolyTraitPredicate<'tcx>| {
let ocx = ObligationCtxt::new_in_snapshot(infcx); let ocx = ObligationCtxt::new_in_snapshot(infcx);
let placeholder_obligation = let placeholder_obligation =
infcx.replace_bound_vars_with_placeholders(obligation.predicate); infcx.instantiate_binder_with_placeholders(obligation.predicate);
let obligation_trait_ref = let obligation_trait_ref =
ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref); ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref);
let param_env_predicate = infcx.replace_bound_vars_with_fresh_vars( let param_env_predicate = infcx.instantiate_binder_with_fresh_vars(
DUMMY_SP, DUMMY_SP,
LateBoundRegionConversionTime::HigherRankedType, LateBoundRegionConversionTime::HigherRankedType,
poly_trait_predicate, poly_trait_predicate,

View file

@ -1716,7 +1716,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let (values, err) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) = let (values, err) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
bound_predicate.skip_binder() bound_predicate.skip_binder()
{ {
let data = self.replace_bound_vars_with_fresh_vars( let data = self.instantiate_binder_with_fresh_vars(
obligation.cause.span, obligation.cause.span,
infer::LateBoundRegionConversionTime::HigherRankedType, infer::LateBoundRegionConversionTime::HigherRankedType,
bound_predicate.rebind(data), bound_predicate.rebind(data),

View file

@ -898,7 +898,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
return false; return false;
} }
let self_ty = self.replace_bound_vars_with_fresh_vars( let self_ty = self.instantiate_binder_with_fresh_vars(
DUMMY_SP, DUMMY_SP,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
trait_pred.self_ty(), trait_pred.self_ty(),
@ -1191,7 +1191,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
}) else { return None; }; }) else { return None; };
let output = self.replace_bound_vars_with_fresh_vars( let output = self.instantiate_binder_with_fresh_vars(
DUMMY_SP, DUMMY_SP,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
output, output,
@ -1200,7 +1200,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.skip_binder() .skip_binder()
.iter() .iter()
.map(|ty| { .map(|ty| {
self.replace_bound_vars_with_fresh_vars( self.instantiate_binder_with_fresh_vars(
DUMMY_SP, DUMMY_SP,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
inputs.rebind(*ty), inputs.rebind(*ty),
@ -3806,13 +3806,13 @@ fn hint_missing_borrow<'tcx>(
err: &mut Diagnostic, err: &mut Diagnostic,
) { ) {
let found_args = match found.kind() { let found_args = match found.kind() {
ty::FnPtr(f) => infcx.replace_bound_vars_with_placeholders(*f).inputs().iter(), ty::FnPtr(f) => infcx.instantiate_binder_with_placeholders(*f).inputs().iter(),
kind => { kind => {
span_bug!(span, "found was converted to a FnPtr above but is now {:?}", kind) span_bug!(span, "found was converted to a FnPtr above but is now {:?}", kind)
} }
}; };
let expected_args = match expected.kind() { let expected_args = match expected.kind() {
ty::FnPtr(f) => infcx.replace_bound_vars_with_placeholders(*f).inputs().iter(), ty::FnPtr(f) => infcx.instantiate_binder_with_placeholders(*f).inputs().iter(),
kind => { kind => {
span_bug!(span, "expected was converted to a FnPtr above but is now {:?}", kind) span_bug!(span, "expected was converted to a FnPtr above but is now {:?}", kind)
} }

View file

@ -321,7 +321,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
| ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => { | ty::PredicateKind::ConstEquate(..) => {
let pred = let pred =
ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder)); ty::Binder::dummy(infcx.instantiate_binder_with_placeholders(binder));
ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)])) ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)]))
} }
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged, ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,

View file

@ -215,7 +215,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
let r = infcx.commit_if_ok(|_snapshot| { let r = infcx.commit_if_ok(|_snapshot| {
let old_universe = infcx.universe(); let old_universe = infcx.universe();
let placeholder_predicate = let placeholder_predicate =
infcx.replace_bound_vars_with_placeholders(obligation.predicate); infcx.instantiate_binder_with_placeholders(obligation.predicate);
let new_universe = infcx.universe(); let new_universe = infcx.universe();
let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate); let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
@ -2046,7 +2046,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
let cause = &obligation.cause; let cause = &obligation.cause;
let param_env = obligation.param_env; let param_env = obligation.param_env;
let cache_entry = infcx.replace_bound_vars_with_fresh_vars( let cache_entry = infcx.instantiate_binder_with_fresh_vars(
cause.span, cause.span,
LateBoundRegionConversionTime::HigherRankedType, LateBoundRegionConversionTime::HigherRankedType,
poly_cache_entry, poly_cache_entry,

View file

@ -488,7 +488,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate); let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx.replace_bound_vars_with_placeholders(poly_trait_predicate); self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
// Count only those upcast versions that match the trait-ref // Count only those upcast versions that match the trait-ref
// we are looking for. Specifically, do not only check for the // we are looking for. Specifically, do not only check for the

View file

@ -151,7 +151,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let trait_predicate = self.infcx.shallow_resolve(obligation.predicate); let trait_predicate = self.infcx.shallow_resolve(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx.replace_bound_vars_with_placeholders(trait_predicate).trait_ref; self.infcx.instantiate_binder_with_placeholders(trait_predicate).trait_ref;
let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_self_ty = placeholder_trait_predicate.self_ty();
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
let (def_id, substs) = match *placeholder_self_ty.kind() { let (def_id, substs) = match *placeholder_self_ty.kind() {
@ -336,7 +336,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let cause = obligation.derived_cause(BuiltinDerivedObligation); let cause = obligation.derived_cause(BuiltinDerivedObligation);
let poly_trait_ref = obligation.predicate.to_poly_trait_ref(); let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
let trait_ref = self.infcx.replace_bound_vars_with_placeholders(poly_trait_ref); let trait_ref = self.infcx.instantiate_binder_with_placeholders(poly_trait_ref);
let trait_obligations: Vec<PredicateObligation<'_>> = self.impl_or_trait_obligations( let trait_obligations: Vec<PredicateObligation<'_>> = self.impl_or_trait_obligations(
&cause, &cause,
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
@ -427,7 +427,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
debug!(?obligation, ?index, "confirm_object_candidate"); debug!(?obligation, ?index, "confirm_object_candidate");
let trait_predicate = self.infcx.replace_bound_vars_with_placeholders(obligation.predicate); let trait_predicate = self.infcx.instantiate_binder_with_placeholders(obligation.predicate);
let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty()); let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty());
let obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref); let obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref);
let ty::Dynamic(data, ..) = *self_ty.kind() else { let ty::Dynamic(data, ..) = *self_ty.kind() else {
@ -437,7 +437,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let object_trait_ref = data.principal().unwrap_or_else(|| { let object_trait_ref = data.principal().unwrap_or_else(|| {
span_bug!(obligation.cause.span, "object candidate with no principal") span_bug!(obligation.cause.span, "object candidate with no principal")
}); });
let object_trait_ref = self.infcx.replace_bound_vars_with_fresh_vars( let object_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span, obligation.cause.span,
HigherRankedType, HigherRankedType,
object_trait_ref, object_trait_ref,
@ -629,7 +629,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
// Confirm the `type Output: Sized;` bound that is present on `FnOnce` // Confirm the `type Output: Sized;` bound that is present on `FnOnce`
let output_ty = self.infcx.replace_bound_vars_with_placeholders(sig.output()); let output_ty = self.infcx.instantiate_binder_with_placeholders(sig.output());
let output_ty = normalize_with_depth_to( let output_ty = normalize_with_depth_to(
self, self,
obligation.param_env, obligation.param_env,
@ -652,7 +652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, "confirm_trait_alias_candidate"); debug!(?obligation, "confirm_trait_alias_candidate");
let alias_def_id = obligation.predicate.def_id(); let alias_def_id = obligation.predicate.def_id();
let predicate = self.infcx.replace_bound_vars_with_placeholders(obligation.predicate); let predicate = self.infcx.instantiate_binder_with_placeholders(obligation.predicate);
let trait_ref = predicate.trait_ref; let trait_ref = predicate.trait_ref;
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let substs = trait_ref.substs; let substs = trait_ref.substs;

View file

@ -1618,7 +1618,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> smallvec::SmallVec<[(usize, ty::BoundConstness); 2]> { ) -> smallvec::SmallVec<[(usize, ty::BoundConstness); 2]> {
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate); let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx.replace_bound_vars_with_placeholders(poly_trait_predicate); self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
debug!(?placeholder_trait_predicate); debug!(?placeholder_trait_predicate);
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
@ -1738,7 +1738,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
potentially_unnormalized_candidates: bool, potentially_unnormalized_candidates: bool,
) -> ProjectionMatchesProjection { ) -> ProjectionMatchesProjection {
let mut nested_obligations = Vec::new(); let mut nested_obligations = Vec::new();
let infer_predicate = self.infcx.replace_bound_vars_with_fresh_vars( let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span, obligation.cause.span,
LateBoundRegionConversionTime::HigherRankedType, LateBoundRegionConversionTime::HigherRankedType,
env_predicate, env_predicate,
@ -2339,7 +2339,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.flat_map(|ty| { .flat_map(|ty| {
let ty: ty::Binder<'tcx, Ty<'tcx>> = types.rebind(*ty); // <----/ let ty: ty::Binder<'tcx, Ty<'tcx>> = types.rebind(*ty); // <----/
let placeholder_ty = self.infcx.replace_bound_vars_with_placeholders(ty); let placeholder_ty = self.infcx.instantiate_binder_with_placeholders(ty);
let Normalized { value: normalized_ty, mut obligations } = let Normalized { value: normalized_ty, mut obligations } =
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
project::normalize_with_depth( project::normalize_with_depth(
@ -2418,7 +2418,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>, obligation: &TraitObligation<'tcx>,
) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> { ) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> {
let placeholder_obligation = let placeholder_obligation =
self.infcx.replace_bound_vars_with_placeholders(obligation.predicate); self.infcx.instantiate_binder_with_placeholders(obligation.predicate);
let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref; let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id); let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);