1
Fork 0

Convert predicates into Predicate in the Obligation constructor

This commit is contained in:
Oli Scherer 2022-11-09 10:49:28 +00:00
parent 634df06fae
commit 4f11f3b257
49 changed files with 252 additions and 228 deletions

View file

@ -200,7 +200,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let new_universe = infcx.universe();
let placeholder_obligation = obligation.with(placeholder_predicate);
let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
match project_and_unify_type(selcx, &placeholder_obligation) {
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
ProjectAndUnifyResult::Holds(obligations)
@ -517,6 +517,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
let recursion_limit = self.tcx().recursion_limit();
if !recursion_limit.value_within_limit(self.depth) {
let obligation = Obligation::with_depth(
self.tcx(),
self.cause.clone(),
recursion_limit.0,
self.param_env,
@ -573,6 +574,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
&& !self.tcx().sess.opts.actually_rustdoc
{
let obligation = Obligation::with_depth(
self.selcx.tcx(),
self.cause.clone(),
recursion_limit.0,
self.param_env,
@ -1110,7 +1112,8 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
}
}
let obligation = Obligation::with_depth(cause.clone(), depth, param_env, projection_ty);
let obligation =
Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_ty);
match project(selcx, &obligation) {
Ok(Projected::Progress(Progress {
@ -1343,8 +1346,8 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
.to_poly_trait_predicate();
let _ =
selcx.infcx().commit_if_ok(|_| match selcx.select(&obligation.with(trait_predicate)) {
let _ = selcx.infcx().commit_if_ok(|_| {
match selcx.select(&obligation.with(tcx, trait_predicate)) {
Ok(Some(super::ImplSource::UserDefined(data))) => {
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
ImplTraitInTraitCandidate::Impl(data),
@ -1364,7 +1367,8 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
candidate_set.mark_error(e);
return Err(());
}
});
}
});
}
}
@ -1538,7 +1542,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
// start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate());
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
let _ = selcx.infcx().commit_if_ok(|_| {
let impl_source = match selcx.select(&trait_obligation) {
Ok(Some(impl_source)) => impl_source,
@ -1705,12 +1709,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
if selcx.infcx().predicate_must_hold_modulo_regions(
&obligation.with(
selcx.tcx(),
ty::Binder::dummy(ty::TraitRef::new(
selcx.tcx().require_lang_item(LangItem::Sized, None),
selcx.tcx().mk_substs_trait(self_ty, &[]),
))
.without_const()
.to_predicate(selcx.tcx()),
.without_const(),
),
) =>
{
@ -1966,13 +1970,8 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
tcx.require_lang_item(LangItem::Sized, None),
tcx.mk_substs_trait(self_ty, &[]),
))
.without_const()
.to_predicate(tcx);
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
sized_predicate,
));
.without_const();
obligations.push(obligation.with(tcx, sized_predicate));
}
let substs = tcx.mk_substs([self_ty.into()].iter());
@ -2289,6 +2288,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
obligations.extend(std::iter::zip(predicates.predicates, predicates.spans).map(
|(pred, span)| {
Obligation::with_depth(
tcx,
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
@ -2342,6 +2342,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
nested,
);
nested.push(Obligation::with_depth(
tcx,
obligation.cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,