]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_traits/src/normalize_projection_ty.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / compiler / rustc_traits / src / normalize_projection_ty.rs
CommitLineData
74b04a01
XL
1use rustc_infer::infer::canonical::{Canonical, QueryResponse};
2use rustc_infer::infer::TyCtxtInferExt;
ba9703b0
XL
3use rustc_middle::ty::query::Providers;
4use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
5use rustc_trait_selection::infer::InferCtxtBuilderExt;
6use rustc_trait_selection::traits::query::{
74b04a01
XL
7 normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution,
8};
ba9703b0 9use rustc_trait_selection::traits::{self, ObligationCause, SelectionContext};
8faf50e0 10use std::sync::atomic::Ordering;
0531ce1d 11
923072b8 12pub(crate) fn provide(p: &mut Providers) {
dfeec247 13 *p = Providers { normalize_projection_ty, ..*p };
8faf50e0
XL
14}
15
16fn normalize_projection_ty<'tcx>(
dc9dc135 17 tcx: TyCtxt<'tcx>,
0531ce1d 18 goal: CanonicalProjectionGoal<'tcx>,
48663c56 19) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
0531ce1d
XL
20 debug!("normalize_provider(goal={:#?})", goal);
21
dfeec247 22 tcx.sess.perf_stats.normalize_projection_ty.fetch_add(1, Ordering::Relaxed);
8faf50e0
XL
23 tcx.infer_ctxt().enter_canonical_trait_query(
24 &goal,
487cf647
FG
25 |ocx, ParamEnvAnd { param_env, value: goal }| {
26 let selcx = &mut SelectionContext::new(ocx.infcx);
ba9703b0 27 let cause = ObligationCause::dummy();
8faf50e0
XL
28 let mut obligations = vec![];
29 let answer = traits::normalize_projection_type(
30 selcx,
0531ce1d 31 param_env,
8faf50e0
XL
32 goal,
33 cause,
34 0,
35 &mut obligations,
36 );
487cf647 37 ocx.register_obligations(obligations);
5099ac24
FG
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() })
8faf50e0
XL
42 },
43 )
0531ce1d 44}