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