]> git.proxmox.com Git - rustc.git/blob - src/librustc_typeck/check/assoc.rs
Imported Upstream version 1.10.0+dfsg1
[rustc.git] / src / librustc_typeck / check / assoc.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::InferCtxt;
12 use rustc::traits::{self, FulfillmentContext, Normalized, MiscObligation,
13 SelectionContext, ObligationCause};
14 use rustc::ty::fold::TypeFoldable;
15 use syntax::ast;
16 use syntax::codemap::Span;
17
18 //FIXME(@jroesch): Ideally we should be able to drop the fulfillment_cx argument.
19 pub fn normalize_associated_types_in<'a, 'gcx, 'tcx, T>(
20 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
21 fulfillment_cx: &mut FulfillmentContext<'tcx>,
22 span: Span,
23 body_id: ast::NodeId,
24 value: &T) -> T
25
26 where T : TypeFoldable<'tcx>
27 {
28 debug!("normalize_associated_types_in(value={:?})", value);
29 let mut selcx = SelectionContext::new(infcx);
30 let cause = ObligationCause::new(span, body_id, MiscObligation);
31 let Normalized { value: result, obligations } = traits::normalize(&mut selcx, cause, value);
32 debug!("normalize_associated_types_in: result={:?} predicates={:?}",
33 result,
34 obligations);
35 for obligation in obligations {
36 fulfillment_cx.register_predicate_obligation(infcx, obligation);
37 }
38 result
39 }