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