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.
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.
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
;
21 crate fn provide(p
: &mut Providers
) {
23 normalize_projection_ty
,
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
);
36 .normalize_projection_ty
37 .fetch_add(1, Ordering
::Relaxed
);
38 tcx
.infer_ctxt().enter_canonical_trait_query(
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(
57 fulfill_cx
.register_predicate_obligations(infcx
, obligations
);
58 Ok(NormalizationResult
{
59 normalized_ty
: answer
,