1 use rustc_infer::infer::canonical::{Canonical, QueryResponse};
2 use rustc_infer::infer::TyCtxtInferExt;
3 use rustc_middle::ty::query::Providers;
4 use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
5 use rustc_trait_selection::infer::InferCtxtBuilderExt;
6 use rustc_trait_selection::traits::query::{
7 normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution,
9 use rustc_trait_selection::traits::{self, ObligationCause, SelectionContext};
10 use std::sync::atomic::Ordering;
12 pub(crate) fn provide(p: &mut Providers) {
13 *p = Providers { normalize_projection_ty, ..*p };
16 fn normalize_projection_ty<'tcx>(
18 goal: CanonicalProjectionGoal<'tcx>,
19 ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
20 debug!("normalize_provider(goal={:#?})", goal);
22 tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
23 tcx.infer_ctxt().enter_canonical_trait_query(
25 |ocx, ParamEnvAnd { param_env, value: goal }| {
26 let selcx = &mut SelectionContext::new(ocx.infcx);
27 let cause = ObligationCause::dummy();
28 let mut obligations = vec![];
29 let answer = traits::normalize_projection_type(
37 ocx.register_obligations(obligations);
38 // FIXME(associated_const_equality): All users of normalize_projection_ty expected
39 // a type, but there is the possibility it could've been a const now. Maybe change
40 // it to a Term later?
41 Ok(NormalizationResult { normalized_ty: answer.ty().unwrap() })