]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
54a0048b SL |
11 | use rustc::infer::InferCtxt; |
12 | use rustc::traits::{self, FulfillmentContext, Normalized, MiscObligation, | |
1a4d82fc | 13 | SelectionContext, ObligationCause}; |
54a0048b | 14 | use rustc::ty::fold::TypeFoldable; |
1a4d82fc JJ |
15 | use syntax::ast; |
16 | use syntax::codemap::Span; | |
1a4d82fc | 17 | |
c1a9b12d | 18 | //FIXME(@jroesch): Ideally we should be able to drop the fulfillment_cx argument. |
1a4d82fc | 19 | pub fn normalize_associated_types_in<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>, |
1a4d82fc JJ |
20 | fulfillment_cx: &mut FulfillmentContext<'tcx>, |
21 | span: Span, | |
22 | body_id: ast::NodeId, | |
23 | value: &T) | |
24 | -> T | |
9cc50fc6 | 25 | where T : TypeFoldable<'tcx> |
1a4d82fc | 26 | { |
62682a34 | 27 | debug!("normalize_associated_types_in(value={:?})", value); |
c1a9b12d | 28 | let mut selcx = SelectionContext::new(infcx); |
1a4d82fc JJ |
29 | let cause = ObligationCause::new(span, body_id, MiscObligation); |
30 | let Normalized { value: result, obligations } = traits::normalize(&mut selcx, cause, value); | |
62682a34 SL |
31 | debug!("normalize_associated_types_in: result={:?} predicates={:?}", |
32 | result, | |
33 | obligations); | |
85aaf69f | 34 | for obligation in obligations { |
1a4d82fc JJ |
35 | fulfillment_cx.register_predicate_obligation(infcx, obligation); |
36 | } | |
37 | result | |
38 | } |