1 // Copyright 2012 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.
12 use middle::ty::{FnSig, Vid};
13 use middle::ty::IntVarValue;
15 use middle::typeck::infer::{Bound, Bounds};
16 use middle::typeck::infer::InferCtxt;
17 use middle::typeck::infer::unify::{Redirect, Root, VarValue};
18 use util::ppaux::{mt_to_str, ty_to_str, trait_ref_to_str};
23 fn inf_str(&self, cx: &InferCtxt) -> String;
26 impl InferStr for ty::t {
27 fn inf_str(&self, cx: &InferCtxt) -> String {
28 ty_to_str(cx.tcx, *self)
32 impl InferStr for FnSig {
33 fn inf_str(&self, cx: &InferCtxt) -> String {
36 .map(|a| a.inf_str(cx))
37 .collect::<Vec<String>>().connect(", "),
38 self.output.inf_str(cx))
42 impl InferStr for ty::mt {
43 fn inf_str(&self, cx: &InferCtxt) -> String {
44 mt_to_str(cx.tcx, self)
48 impl InferStr for ty::Region {
49 fn inf_str(&self, _cx: &InferCtxt) -> String {
50 format!("{:?}", *self)
54 impl<V:InferStr> InferStr for Bound<V> {
55 fn inf_str(&self, cx: &InferCtxt) -> String {
57 Some(ref v) => v.inf_str(cx),
58 None => "none".to_string()
63 impl<T:InferStr> InferStr for Bounds<T> {
64 fn inf_str(&self, cx: &InferCtxt) -> String {
65 format!("{{{} <: {}}}", self.lb.inf_str(cx), self.ub.inf_str(cx))
69 impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
70 fn inf_str(&self, cx: &InferCtxt) -> String {
72 Redirect(ref vid) => format!("Redirect({})", vid.to_str()),
74 format!("Root({}, {})", pt.inf_str(cx), rk)
80 impl InferStr for IntVarValue {
81 fn inf_str(&self, _cx: &InferCtxt) -> String {
86 impl InferStr for ast::FloatTy {
87 fn inf_str(&self, _cx: &InferCtxt) -> String {
92 impl InferStr for ty::TraitRef {
93 fn inf_str(&self, cx: &InferCtxt) -> String {
94 trait_ref_to_str(cx.tcx, self)