]> git.proxmox.com Git - rustc.git/blob - src/librustc_traits/normalize_projection_ty.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_traits / normalize_projection_ty.rs
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,
9 };
10 use rustc_trait_selection::traits::{self, ObligationCause, SelectionContext};
11 use std::sync::atomic::Ordering;
12
13 crate fn provide(p: &mut Providers<'_>) {
14 *p = Providers { normalize_projection_ty, ..*p };
15 }
16
17 fn normalize_projection_ty<'tcx>(
18 tcx: TyCtxt<'tcx>,
19 goal: CanonicalProjectionGoal<'tcx>,
20 ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
21 debug!("normalize_provider(goal={:#?})", goal);
22
23 tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
24 tcx.infer_ctxt().enter_canonical_trait_query(
25 &goal,
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(
31 selcx,
32 param_env,
33 goal,
34 cause,
35 0,
36 &mut obligations,
37 );
38 fulfill_cx.register_predicate_obligations(infcx, obligations);
39 Ok(NormalizationResult { normalized_ty: answer })
40 },
41 )
42 }