]> git.lizzy.rs Git - rust.git/blob - src/librustc_traits/normalize_projection_ty.rs
Rollup merge of #60766 - vorner:weak-into-raw, r=sfackler
[rust.git] / src / librustc_traits / normalize_projection_ty.rs
1 use rustc::hir;
2 use rustc::infer::canonical::{Canonical, QueryResponse};
3 use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
4 use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt};
5 use rustc::ty::query::Providers;
6 use rustc::ty::{ParamEnvAnd, TyCtxt};
7 use std::sync::atomic::Ordering;
8 use syntax_pos::DUMMY_SP;
9
10 crate fn provide(p: &mut Providers<'_>) {
11     *p = Providers {
12         normalize_projection_ty,
13         ..*p
14     };
15 }
16
17 fn normalize_projection_ty<'tcx>(
18     tcx: TyCtxt<'_, 'tcx, '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
24         .perf_stats
25         .normalize_projection_ty
26         .fetch_add(1, Ordering::Relaxed);
27     tcx.infer_ctxt().enter_canonical_trait_query(
28         &goal,
29         |infcx,
30          fulfill_cx,
31          ParamEnvAnd {
32              param_env,
33              value: goal,
34          }| {
35             let selcx = &mut SelectionContext::new(infcx);
36             let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
37             let mut obligations = vec![];
38             let answer = traits::normalize_projection_type(
39                 selcx,
40                 param_env,
41                 goal,
42                 cause,
43                 0,
44                 &mut obligations,
45             );
46             fulfill_cx.register_predicate_obligations(infcx, obligations);
47             Ok(NormalizationResult {
48                 normalized_ty: answer,
49             })
50         },
51     )
52 }