]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/typeck/infer/to_str.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / librustc / middle / typeck / infer / to_str.rs
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.
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
12 use middle::ty::{FnSig, Vid};
13 use middle::ty::IntVarValue;
14 use middle::ty;
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};
19
20 use syntax::ast;
21
22 pub trait InferStr {
23     fn inf_str(&self, cx: &InferCtxt) -> ~str;
24 }
25
26 impl InferStr for ty::t {
27     fn inf_str(&self, cx: &InferCtxt) -> ~str {
28         ty_to_str(cx.tcx, *self)
29     }
30 }
31
32 impl InferStr for FnSig {
33     fn inf_str(&self, cx: &InferCtxt) -> ~str {
34         format!("({}) -> {}",
35              self.inputs.iter().map(|a| a.inf_str(cx)).collect::<Vec<~str>>().connect(", "),
36              self.output.inf_str(cx))
37     }
38 }
39
40 impl InferStr for ty::mt {
41     fn inf_str(&self, cx: &InferCtxt) -> ~str {
42         mt_to_str(cx.tcx, self)
43     }
44 }
45
46 impl InferStr for ty::Region {
47     fn inf_str(&self, _cx: &InferCtxt) -> ~str {
48         format!("{:?}", *self)
49     }
50 }
51
52 impl<V:InferStr> InferStr for Bound<V> {
53     fn inf_str(&self, cx: &InferCtxt) -> ~str {
54         match *self {
55           Some(ref v) => v.inf_str(cx),
56           None => "none".to_owned()
57         }
58     }
59 }
60
61 impl<T:InferStr> InferStr for Bounds<T> {
62     fn inf_str(&self, cx: &InferCtxt) -> ~str {
63         format!("\\{{} <: {}\\}",
64              self.lb.inf_str(cx),
65              self.ub.inf_str(cx))
66     }
67 }
68
69 impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
70     fn inf_str(&self, cx: &InferCtxt) -> ~str {
71         match *self {
72           Redirect(ref vid) => format!("Redirect({})", vid.to_str()),
73           Root(ref pt, rk) => format!("Root({}, {})", pt.inf_str(cx), rk)
74         }
75     }
76 }
77
78 impl InferStr for IntVarValue {
79     fn inf_str(&self, _cx: &InferCtxt) -> ~str {
80         self.to_str()
81     }
82 }
83
84 impl InferStr for ast::FloatTy {
85     fn inf_str(&self, _cx: &InferCtxt) -> ~str {
86         self.to_str()
87     }
88 }
89
90 impl InferStr for ty::TraitRef {
91     fn inf_str(&self, cx: &InferCtxt) -> ~str {
92         trait_ref_to_str(cx.tcx, self)
93     }
94 }