Replacing bound vars is actually instantiating a binder
This commit is contained in:
parent
bd39bbb4bb
commit
03a8a4ff3e
28 changed files with 67 additions and 60 deletions
|
@ -74,7 +74,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
|
|||
)
|
||||
}
|
||||
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)),
|
||||
);
|
||||
let expected_found = ExpectedFound::new(true, a, b);
|
||||
|
@ -84,7 +84,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
|
|||
)
|
||||
}
|
||||
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)),
|
||||
);
|
||||
let expected_found = ExpectedFound::new(false, a, b);
|
||||
|
@ -94,7 +94,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
|
|||
)
|
||||
}
|
||||
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)),
|
||||
);
|
||||
let expected_found = ExpectedFound::new(true, a, b);
|
||||
|
|
|
@ -26,7 +26,7 @@ pub(super) trait InferCtxtExt<'tcx> {
|
|||
rhs: T,
|
||||
) -> 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,
|
||||
value: ty::Binder<'tcx, 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,
|
||||
value: ty::Binder<'tcx, T>,
|
||||
) -> T {
|
||||
self.replace_bound_vars_with_fresh_vars(
|
||||
self.instantiate_binder_with_fresh_vars(
|
||||
DUMMY_SP,
|
||||
LateBoundRegionConversionTime::HigherRankedType,
|
||||
value,
|
||||
|
|
|
@ -304,7 +304,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
} 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 (_, certainty) = self.evaluate_goal(goal)?;
|
||||
self.make_canonical_response(certainty)
|
||||
|
|
|
@ -323,7 +323,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||
{
|
||||
ecx.infcx.probe(|_| {
|
||||
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(
|
||||
goal.param_env,
|
||||
goal.predicate.projection_ty,
|
||||
|
|
|
@ -72,7 +72,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
|||
// FIXME: Constness and polarity
|
||||
ecx.infcx.probe(|_| {
|
||||
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(
|
||||
goal.param_env,
|
||||
goal.predicate.trait_ref,
|
||||
|
|
|
@ -54,7 +54,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
|
|||
}
|
||||
|
||||
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!(),
|
||||
|
@ -174,7 +174,7 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
|
|||
}
|
||||
|
||||
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!(),
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn recompute_applicable_impls<'tcx>(
|
|||
let impl_may_apply = |impl_def_id| {
|
||||
let ocx = ObligationCtxt::new_in_snapshot(infcx);
|
||||
let placeholder_obligation =
|
||||
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
|
||||
infcx.instantiate_binder_with_placeholders(obligation.predicate);
|
||||
let 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 ocx = ObligationCtxt::new_in_snapshot(infcx);
|
||||
let placeholder_obligation =
|
||||
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
|
||||
infcx.instantiate_binder_with_placeholders(obligation.predicate);
|
||||
let 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,
|
||||
LateBoundRegionConversionTime::HigherRankedType,
|
||||
poly_trait_predicate,
|
||||
|
|
|
@ -1716,7 +1716,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let (values, err) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
|
||||
bound_predicate.skip_binder()
|
||||
{
|
||||
let data = self.replace_bound_vars_with_fresh_vars(
|
||||
let data = self.instantiate_binder_with_fresh_vars(
|
||||
obligation.cause.span,
|
||||
infer::LateBoundRegionConversionTime::HigherRankedType,
|
||||
bound_predicate.rebind(data),
|
||||
|
|
|
@ -898,7 +898,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
return false;
|
||||
}
|
||||
|
||||
let self_ty = self.replace_bound_vars_with_fresh_vars(
|
||||
let self_ty = self.instantiate_binder_with_fresh_vars(
|
||||
DUMMY_SP,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
trait_pred.self_ty(),
|
||||
|
@ -1191,7 +1191,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}) else { return None; };
|
||||
|
||||
let output = self.replace_bound_vars_with_fresh_vars(
|
||||
let output = self.instantiate_binder_with_fresh_vars(
|
||||
DUMMY_SP,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
output,
|
||||
|
@ -1200,7 +1200,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
.skip_binder()
|
||||
.iter()
|
||||
.map(|ty| {
|
||||
self.replace_bound_vars_with_fresh_vars(
|
||||
self.instantiate_binder_with_fresh_vars(
|
||||
DUMMY_SP,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
inputs.rebind(*ty),
|
||||
|
@ -3806,13 +3806,13 @@ fn hint_missing_borrow<'tcx>(
|
|||
err: &mut Diagnostic,
|
||||
) {
|
||||
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 => {
|
||||
span_bug!(span, "found was converted to a FnPtr above but is now {:?}", 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 => {
|
||||
span_bug!(span, "expected was converted to a FnPtr above but is now {:?}", kind)
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => {
|
||||
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)]))
|
||||
}
|
||||
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
|
||||
|
|
|
@ -215,7 +215,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
|
|||
let r = infcx.commit_if_ok(|_snapshot| {
|
||||
let old_universe = infcx.universe();
|
||||
let placeholder_predicate =
|
||||
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
|
||||
infcx.instantiate_binder_with_placeholders(obligation.predicate);
|
||||
let new_universe = infcx.universe();
|
||||
|
||||
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 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,
|
||||
LateBoundRegionConversionTime::HigherRankedType,
|
||||
poly_cache_entry,
|
||||
|
|
|
@ -488,7 +488,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.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
|
||||
// we are looking for. Specifically, do not only check for the
|
||||
|
|
|
@ -151,7 +151,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
let trait_predicate = self.infcx.shallow_resolve(obligation.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_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
|
||||
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 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(
|
||||
&cause,
|
||||
obligation.recursion_depth + 1,
|
||||
|
@ -427,7 +427,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let tcx = self.tcx();
|
||||
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 obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref);
|
||||
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(|| {
|
||||
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,
|
||||
HigherRankedType,
|
||||
object_trait_ref,
|
||||
|
@ -629,7 +629,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// 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(
|
||||
self,
|
||||
obligation.param_env,
|
||||
|
@ -652,7 +652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
debug!(?obligation, "confirm_trait_alias_candidate");
|
||||
|
||||
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_def_id = trait_ref.def_id;
|
||||
let substs = trait_ref.substs;
|
||||
|
|
|
@ -1618,7 +1618,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
) -> smallvec::SmallVec<[(usize, ty::BoundConstness); 2]> {
|
||||
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.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);
|
||||
|
||||
let tcx = self.infcx.tcx;
|
||||
|
@ -1738,7 +1738,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
potentially_unnormalized_candidates: bool,
|
||||
) -> ProjectionMatchesProjection {
|
||||
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,
|
||||
LateBoundRegionConversionTime::HigherRankedType,
|
||||
env_predicate,
|
||||
|
@ -2339,7 +2339,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
.flat_map(|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 } =
|
||||
ensure_sufficient_stack(|| {
|
||||
project::normalize_with_depth(
|
||||
|
@ -2418,7 +2418,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation: &TraitObligation<'tcx>,
|
||||
) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> {
|
||||
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 impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue