]> git.proxmox.com Git - rustc.git/blob - src/librustc_traits/normalize_projection_ty.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / librustc_traits / normalize_projection_ty.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use rustc::infer::canonical::{Canonical, QueryResponse};
12 use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
13 use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt};
14 use rustc::ty::query::Providers;
15 use rustc::ty::{ParamEnvAnd, TyCtxt};
16 use rustc_data_structures::sync::Lrc;
17 use std::sync::atomic::Ordering;
18 use syntax::ast::DUMMY_NODE_ID;
19 use syntax_pos::DUMMY_SP;
20
21 crate fn provide(p: &mut Providers) {
22 *p = Providers {
23 normalize_projection_ty,
24 ..*p
25 };
26 }
27
28 fn normalize_projection_ty<'tcx>(
29 tcx: TyCtxt<'_, 'tcx, 'tcx>,
30 goal: CanonicalProjectionGoal<'tcx>,
31 ) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
32 debug!("normalize_provider(goal={:#?})", goal);
33
34 tcx.sess
35 .perf_stats
36 .normalize_projection_ty
37 .fetch_add(1, Ordering::Relaxed);
38 tcx.infer_ctxt().enter_canonical_trait_query(
39 &goal,
40 |infcx,
41 fulfill_cx,
42 ParamEnvAnd {
43 param_env,
44 value: goal,
45 }| {
46 let selcx = &mut SelectionContext::new(infcx);
47 let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
48 let mut obligations = vec![];
49 let answer = traits::normalize_projection_type(
50 selcx,
51 param_env,
52 goal,
53 cause,
54 0,
55 &mut obligations,
56 );
57 fulfill_cx.register_predicate_obligations(infcx, obligations);
58 Ok(NormalizationResult {
59 normalized_ty: answer,
60 })
61 },
62 )
63 }