2023-05-09 20:18:22 +00:00
|
|
|
use rustc_infer::infer::TyCtxtInferExt;
|
2023-05-15 04:24:45 +00:00
|
|
|
use rustc_middle::query::Providers;
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
|
2023-11-02 03:10:12 +00:00
|
|
|
use rustc_span::DUMMY_SP;
|
2020-02-11 20:19:40 +00:00
|
|
|
use rustc_trait_selection::traits::query::CanonicalPredicateGoal;
|
|
|
|
use rustc_trait_selection::traits::{
|
2020-01-06 22:28:45 +00:00
|
|
|
EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext, TraitQueryMode,
|
|
|
|
};
|
2024-04-29 06:24:06 +00:00
|
|
|
use tracing::debug;
|
2018-03-09 00:30:37 +00:00
|
|
|
|
2022-05-20 23:51:09 +00:00
|
|
|
pub(crate) fn provide(p: &mut Providers) {
|
2018-06-27 13:42:00 +00:00
|
|
|
*p = Providers { evaluate_obligation, ..*p };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn evaluate_obligation<'tcx>(
|
2019-06-13 21:48:52 +00:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2018-09-24 19:15:25 +00:00
|
|
|
canonical_goal: CanonicalPredicateGoal<'tcx>,
|
2018-04-19 08:15:36 +00:00
|
|
|
) -> Result<EvaluationResult, OverflowError> {
|
2023-05-31 01:02:32 +00:00
|
|
|
assert!(!tcx.next_trait_solver_globally());
|
2019-10-07 15:00:09 +00:00
|
|
|
debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal);
|
2023-02-10 10:26:26 +00:00
|
|
|
let (ref infcx, goal, _canonical_inference_vars) =
|
|
|
|
tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &canonical_goal);
|
2019-10-07 15:00:09 +00:00
|
|
|
debug!("evaluate_obligation: goal={:#?}", goal);
|
2018-10-08 10:59:37 +00:00
|
|
|
let ParamEnvAnd { param_env, value: predicate } = goal;
|
2018-03-09 00:30:37 +00:00
|
|
|
|
2023-11-21 19:07:32 +00:00
|
|
|
let mut selcx = SelectionContext::with_query_mode(infcx, TraitQueryMode::Canonical);
|
2022-11-09 10:49:28 +00:00
|
|
|
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
|
2018-03-09 00:30:37 +00:00
|
|
|
|
2019-06-04 16:27:56 +00:00
|
|
|
selcx.evaluate_root_obligation(&obligation)
|
2018-03-09 00:30:37 +00:00
|
|
|
}
|