]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/check/assoc.rs
Auto merge of #21376 - fhahn:issue-15881-model-lexer-dotdotdot, r=cmr
[rust.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 middle::infer::InferCtxt;
12 use middle::traits::{self, FulfillmentContext, Normalized, MiscObligation,
13                      SelectionContext, ObligationCause};
14 use middle::ty::{self, HasProjectionTypes};
15 use middle::ty_fold::{TypeFoldable, TypeFolder};
16 use syntax::ast;
17 use syntax::codemap::Span;
18 use util::ppaux::Repr;
19
20 pub fn normalize_associated_types_in<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
21                                                 typer: &(ty::ClosureTyper<'tcx>+'a),
22                                                 fulfillment_cx: &mut FulfillmentContext<'tcx>,
23                                                 span: Span,
24                                                 body_id: ast::NodeId,
25                                                 value: &T)
26                                                 -> T
27     where T : TypeFoldable<'tcx> + HasProjectionTypes + Clone + Repr<'tcx>
28 {
29     debug!("normalize_associated_types_in(value={})", value.repr(infcx.tcx));
30     let mut selcx = SelectionContext::new(infcx, typer);
31     let cause = ObligationCause::new(span, body_id, MiscObligation);
32     let Normalized { value: result, obligations } = traits::normalize(&mut selcx, cause, value);
33     debug!("normalize_associated_types_in: result={} predicates={}",
34            result.repr(infcx.tcx),
35            obligations.repr(infcx.tcx));
36     for obligation in obligations {
37         fulfillment_cx.register_predicate_obligation(infcx, obligation);
38     }
39     result
40 }