]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_traits/src/normalize_projection_ty.rs
Rollup merge of #99716 - sourcelliu:iomut, r=Mark-Simulacrum
[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_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 pub(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             // 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() })
43         },
44     )
45 }