assoc.rs 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use middle::infer::InferCtxt;
12 13 14 15 16
use middle::mem_categorization as mc;
use middle::traits::{mod, FulfillmentContext, Normalized, MiscObligation,
                     SelectionContext, ObligationCause};
use middle::ty::{mod, HasProjectionTypes};
use middle::ty_fold::{TypeFoldable, TypeFolder};
17 18
use syntax::ast;
use syntax::codemap::Span;
19
use util::ppaux::Repr;
20 21

pub fn normalize_associated_types_in<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
22 23
                                                param_env: &ty::ParameterEnvironment<'tcx>,
                                                typer: &(mc::Typer<'tcx>+'a),
24 25 26 27 28
                                                fulfillment_cx: &mut FulfillmentContext<'tcx>,
                                                span: Span,
                                                body_id: ast::NodeId,
                                                value: &T)
                                                -> T
29
    where T : TypeFoldable<'tcx> + HasProjectionTypes + Clone + Repr<'tcx>
30
{
31 32 33 34 35 36 37 38 39
    debug!("normalize_associated_types_in(value={})", value.repr(infcx.tcx));
    let mut selcx = SelectionContext::new(infcx, param_env, typer);
    let cause = ObligationCause::new(span, body_id, MiscObligation);
    let Normalized { value: result, obligations } = traits::normalize(&mut selcx, cause, value);
    debug!("normalize_associated_types_in: result={} predicates={}",
           result.repr(infcx.tcx),
           obligations.repr(infcx.tcx));
    for obligation in obligations.into_iter() {
        fulfillment_cx.register_predicate_obligation(infcx, obligation);
40
    }
41
    result
42
}