Pass ObligationCtxt from enter_canonical_trait_query and use ObligationCtxt API
This commit is contained in:
parent
5b3a06a3c2
commit
859b147d4f
@ -5,16 +5,15 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::infer::canonical::{self, Canonical};
|
||||
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
|
||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::traits::query::OutlivesBound;
|
||||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
use rustc_trait_selection::infer::InferCtxtBuilderExt;
|
||||
use rustc_trait_selection::traits::query::{CanonicalTyGoal, Fallible, NoSolution};
|
||||
use rustc_trait_selection::traits::wf;
|
||||
use rustc_trait_selection::traits::{TraitEngine, TraitEngineExt};
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
pub(crate) fn provide(p: &mut Providers) {
|
||||
@ -30,16 +29,16 @@ fn implied_outlives_bounds<'tcx>(
|
||||
> {
|
||||
tcx.infer_ctxt().enter_canonical_trait_query(&goal, |ocx, key| {
|
||||
let (param_env, ty) = key.into_parts();
|
||||
compute_implied_outlives_bounds(&ocx.infcx, param_env, ty)
|
||||
compute_implied_outlives_bounds(ocx, param_env, ty)
|
||||
})
|
||||
}
|
||||
|
||||
fn compute_implied_outlives_bounds<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
ocx: &ObligationCtxt<'_, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Fallible<Vec<OutlivesBound<'tcx>>> {
|
||||
let tcx = infcx.tcx;
|
||||
let tcx = ocx.infcx.tcx;
|
||||
|
||||
// Sometimes when we ask what it takes for T: WF, we get back that
|
||||
// U: WF is required; in that case, we push U onto this stack and
|
||||
@ -52,8 +51,6 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
let mut outlives_bounds: Vec<ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>> =
|
||||
vec![];
|
||||
|
||||
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(tcx);
|
||||
|
||||
while let Some(arg) = wf_args.pop() {
|
||||
if !checked_wf_args.insert(arg) {
|
||||
continue;
|
||||
@ -70,15 +67,15 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
// FIXME(@lcnr): It's not really "always fine", having fewer implied
|
||||
// bounds can be backward incompatible, e.g. #101951 was caused by
|
||||
// us not dealing with inference vars in `TypeOutlives` predicates.
|
||||
let obligations = wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP)
|
||||
.unwrap_or_default();
|
||||
let obligations =
|
||||
wf::obligations(ocx.infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP)
|
||||
.unwrap_or_default();
|
||||
|
||||
// While these predicates should all be implied by other parts of
|
||||
// the program, they are still relevant as they may constrain
|
||||
// inference variables, which is necessary to add the correct
|
||||
// implied bounds in some cases, mostly when dealing with projections.
|
||||
fulfill_cx.register_predicate_obligations(
|
||||
infcx,
|
||||
ocx.register_obligations(
|
||||
obligations.iter().filter(|o| o.predicate.has_non_region_infer()).cloned(),
|
||||
);
|
||||
|
||||
@ -116,9 +113,9 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
}));
|
||||
}
|
||||
|
||||
// Ensure that those obligations that we had to solve
|
||||
// get solved *here*.
|
||||
match fulfill_cx.select_all_or_error(infcx).as_slice() {
|
||||
// This call to `select_all_or_error` is necessary to constrain inference variables, which we
|
||||
// use further down when computing the implied bounds.
|
||||
match ocx.select_all_or_error().as_slice() {
|
||||
[] => (),
|
||||
_ => return Err(NoSolution),
|
||||
}
|
||||
@ -130,7 +127,7 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
.flat_map(|ty::OutlivesPredicate(a, r_b)| match a.unpack() {
|
||||
ty::GenericArgKind::Lifetime(r_a) => vec![OutlivesBound::RegionSubRegion(r_b, r_a)],
|
||||
ty::GenericArgKind::Type(ty_a) => {
|
||||
let ty_a = infcx.resolve_vars_if_possible(ty_a);
|
||||
let ty_a = ocx.infcx.resolve_vars_if_possible(ty_a);
|
||||
let mut components = smallvec![];
|
||||
push_outlives_components(tcx, ty_a, &mut components);
|
||||
implied_bounds_from_components(r_b, components)
|
||||
|
Loading…
x
Reference in New Issue
Block a user