1 use rustc::ty::query::Providers;
2 use rustc::ty::{ParamEnvAnd, TyCtxt};
4 use rustc_infer::infer::canonical::{Canonical, QueryResponse};
5 use rustc_infer::infer::TyCtxtInferExt;
6 use rustc_infer::traits::TraitEngineExt as _;
7 use rustc_span::DUMMY_SP;
8 use rustc_trait_selection::infer::InferCtxtBuilderExt;
9 use rustc_trait_selection::traits::query::{
10 normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution,
12 use rustc_trait_selection::traits::{self, ObligationCause, SelectionContext};
13 use std::sync::atomic::Ordering;
15 crate fn provide(p: &mut Providers<'_>) {
16 *p = Providers { normalize_projection_ty, ..*p };
19 fn normalize_projection_ty<'tcx>(
21 goal: CanonicalProjectionGoal<'tcx>,
22 ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
23 debug!("normalize_provider(goal={:#?})", goal);
25 tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
26 tcx.infer_ctxt().enter_canonical_trait_query(
28 |infcx, fulfill_cx, ParamEnvAnd { param_env, value: goal }| {
29 let selcx = &mut SelectionContext::new(infcx);
30 let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
31 let mut obligations = vec![];
32 let answer = traits::normalize_projection_type(
40 fulfill_cx.register_predicate_obligations(infcx, obligations);
41 Ok(NormalizationResult { normalized_ty: answer })