1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use rustc::traits::{EvaluationResult, Obligation, ObligationCause,
12 OverflowError, SelectionContext, TraitQueryMode};
13 use rustc::traits::query::CanonicalPredicateGoal;
14 use rustc::ty::query::Providers;
15 use rustc::ty::{ParamEnvAnd, TyCtxt};
16 use syntax::codemap::DUMMY_SP;
18 crate fn provide(p: &mut Providers) {
25 fn evaluate_obligation<'tcx>(
26 tcx: TyCtxt<'_, 'tcx, 'tcx>,
27 goal: CanonicalPredicateGoal<'tcx>,
28 ) -> Result<EvaluationResult, OverflowError> {
29 tcx.infer_ctxt().enter(|ref infcx| {
35 _canonical_inference_vars,
36 ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &goal);
38 let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
39 let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate);
41 selcx.evaluate_obligation_recursively(&obligation)