]> git.lizzy.rs Git - rust.git/blob - src/librustc_traits/normalize_projection_ty.rs
submodule: update rls from c9d25b667a to f331ff7
[rust.git] / src / librustc_traits / normalize_projection_ty.rs
1 use rustc::infer::canonical::{Canonical, QueryResponse};
2 use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
3 use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt};
4 use rustc::ty::query::Providers;
5 use rustc::ty::{ParamEnvAnd, TyCtxt};
6 use rustc_data_structures::sync::Lrc;
7 use std::sync::atomic::Ordering;
8 use syntax::ast::DUMMY_NODE_ID;
9 use syntax_pos::DUMMY_SP;
10
11 crate fn provide(p: &mut Providers) {
12     *p = Providers {
13         normalize_projection_ty,
14         ..*p
15     };
16 }
17
18 fn normalize_projection_ty<'tcx>(
19     tcx: TyCtxt<'_, 'tcx, 'tcx>,
20     goal: CanonicalProjectionGoal<'tcx>,
21 ) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
22     debug!("normalize_provider(goal={:#?})", goal);
23
24     tcx.sess
25         .perf_stats
26         .normalize_projection_ty
27         .fetch_add(1, Ordering::Relaxed);
28     tcx.infer_ctxt().enter_canonical_trait_query(
29         &goal,
30         |infcx,
31          fulfill_cx,
32          ParamEnvAnd {
33              param_env,
34              value: goal,
35          }| {
36             let selcx = &mut SelectionContext::new(infcx);
37             let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
38             let mut obligations = vec![];
39             let answer = traits::normalize_projection_type(
40                 selcx,
41                 param_env,
42                 goal,
43                 cause,
44                 0,
45                 &mut obligations,
46             );
47             fulfill_cx.register_predicate_obligations(infcx, obligations);
48             Ok(NormalizationResult {
49                 normalized_ty: answer,
50             })
51         },
52     )
53 }