rust/compiler/rustc_traits/src/evaluate_obligation.rs

33 lines
1.2 KiB
Rust
Raw Normal View History

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,
};
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>,
canonical_goal: CanonicalPredicateGoal<'tcx>,
) -> 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-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);
selcx.evaluate_root_obligation(&obligation)
2018-10-08 05:59:37 -05:00
},
)
}