]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_traits/src/normalize_projection_ty.rs
Rollup merge of #103837 - GuillaumeGomez:migrate-sidebar-links-color-gui-test, r...
[rust.git] / compiler / rustc_traits / src / normalize_projection_ty.rs
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,
8 };
9 use rustc_trait_selection::traits::{self, ObligationCause, SelectionContext};
10 use std::sync::atomic::Ordering;
11
12 pub(crate) fn provide(p: &mut Providers) {
13     *p = Providers { normalize_projection_ty, ..*p };
14 }
15
16 fn normalize_projection_ty<'tcx>(
17     tcx: TyCtxt<'tcx>,
18     goal: CanonicalProjectionGoal<'tcx>,
19 ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
20     debug!("normalize_provider(goal={:#?})", goal);
21
22     tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
23     tcx.infer_ctxt().enter_canonical_trait_query(
24         &goal,
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(
30                 selcx,
31                 param_env,
32                 goal,
33                 cause,
34                 0,
35                 &mut obligations,
36             );
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() })
42         },
43     )
44 }