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