]> git.lizzy.rs Git - rust.git/blob - src/librustc/util/ppaux.rs
prefer "FIXME" to "TODO".
[rust.git] / src / librustc / util / ppaux.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::def;
13 use middle::subst::{VecPerParamSpace,Subst};
14 use middle::subst;
15 use middle::ty::{BoundRegion, BrAnon, BrNamed};
16 use middle::ty::{ReEarlyBound, BrFresh, ctxt};
17 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
18 use middle::ty::{ReSkolemized, ReVar, BrEnv};
19 use middle::ty::{mt, Ty, ParamTy};
20 use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum};
21 use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
22 use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open};
23 use middle::ty::{ty_unboxed_closure};
24 use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
25 use middle::ty;
26
27 use std::rc::Rc;
28 use syntax::abi;
29 use syntax::ast_map;
30 use syntax::codemap::{Span, Pos};
31 use syntax::parse::token;
32 use syntax::print::pprust;
33 use syntax::ptr::P;
34 use syntax::{ast, ast_util};
35 use syntax::owned_slice::OwnedSlice;
36
37 /// Produces a string suitable for debugging output.
38 pub trait Repr<'tcx> for Sized? {
39     fn repr(&self, tcx: &ctxt<'tcx>) -> String;
40 }
41
42 /// Produces a string suitable for showing to the user.
43 pub trait UserString<'tcx> {
44     fn user_string(&self, tcx: &ctxt<'tcx>) -> String;
45 }
46
47 pub fn note_and_explain_region(cx: &ctxt,
48                                prefix: &str,
49                                region: ty::Region,
50                                suffix: &str) -> Option<Span> {
51     match explain_region_and_span(cx, region) {
52       (ref str, Some(span)) => {
53         cx.sess.span_note(
54             span,
55             format!("{}{}{}", prefix, *str, suffix).as_slice());
56         Some(span)
57       }
58       (ref str, None) => {
59         cx.sess.note(
60             format!("{}{}{}", prefix, *str, suffix).as_slice());
61         None
62       }
63     }
64 }
65
66 /// When a free region is associated with `item`, how should we describe the item in the error
67 /// message.
68 fn item_scope_tag(item: &ast::Item) -> &'static str {
69     match item.node {
70         ast::ItemImpl(..) => "impl",
71         ast::ItemStruct(..) => "struct",
72         ast::ItemEnum(..) => "enum",
73         ast::ItemTrait(..) => "trait",
74         ast::ItemFn(..) => "function body",
75         _ => "item"
76     }
77 }
78
79 pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
80                             -> (String, Option<Span>) {
81     return match region {
82       ReScope(scope) => {
83         match cx.map.find(scope.node_id()) {
84           Some(ast_map::NodeBlock(ref blk)) => {
85             explain_span(cx, "block", blk.span)
86           }
87           Some(ast_map::NodeExpr(expr)) => {
88             match expr.node {
89               ast::ExprCall(..) => explain_span(cx, "call", expr.span),
90               ast::ExprMethodCall(..) => {
91                 explain_span(cx, "method call", expr.span)
92               },
93               ast::ExprMatch(_, _, ast::MatchIfLetDesugar) => explain_span(cx, "if let", expr.span),
94               ast::ExprMatch(_, _, ast::MatchWhileLetDesugar) => {
95                   explain_span(cx, "while let", expr.span)
96               },
97               ast::ExprMatch(..) => explain_span(cx, "match", expr.span),
98               _ => explain_span(cx, "expression", expr.span)
99             }
100           }
101           Some(ast_map::NodeStmt(stmt)) => {
102               explain_span(cx, "statement", stmt.span)
103           }
104           Some(ast_map::NodeItem(it)) => {
105               let tag = item_scope_tag(&*it);
106               explain_span(cx, tag, it.span)
107           }
108           Some(_) | None => {
109             // this really should not happen
110             (format!("unknown scope: {}.  Please report a bug.", scope), None)
111           }
112         }
113       }
114
115       ReFree(ref fr) => {
116         let prefix = match fr.bound_region {
117           BrAnon(idx) => {
118               format!("the anonymous lifetime #{} defined on", idx + 1)
119           }
120           BrFresh(_) => "an anonymous lifetime defined on".to_string(),
121           _ => {
122               format!("the lifetime {} as defined on",
123                       bound_region_ptr_to_string(cx, fr.bound_region))
124           }
125         };
126
127         match cx.map.find(fr.scope.node_id()) {
128           Some(ast_map::NodeBlock(ref blk)) => {
129               let (msg, opt_span) = explain_span(cx, "block", blk.span);
130               (format!("{} {}", prefix, msg), opt_span)
131           }
132           Some(ast_map::NodeItem(it)) => {
133               let tag = item_scope_tag(&*it);
134               let (msg, opt_span) = explain_span(cx, tag, it.span);
135               (format!("{} {}", prefix, msg), opt_span)
136           }
137           Some(_) | None => {
138               // this really should not happen
139               (format!("{} unknown free region bounded by scope {}", prefix, fr.scope), None)
140           }
141         }
142       }
143
144       ReStatic => { ("the static lifetime".to_string(), None) }
145
146       ReEmpty => { ("the empty lifetime".to_string(), None) }
147
148       ReEarlyBound(_, _, _, name) => {
149         (format!("{}", token::get_name(name)), None)
150       }
151
152       // I believe these cases should not occur (except when debugging,
153       // perhaps)
154       ty::ReInfer(_) | ty::ReLateBound(..) => {
155         (format!("lifetime {}", region), None)
156       }
157     };
158
159     fn explain_span(cx: &ctxt, heading: &str, span: Span)
160                     -> (String, Option<Span>) {
161         let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
162         (format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
163          Some(span))
164     }
165 }
166
167 pub fn bound_region_ptr_to_string(cx: &ctxt, br: BoundRegion) -> String {
168     bound_region_to_string(cx, "", false, br)
169 }
170
171 pub fn bound_region_to_string(cx: &ctxt,
172                            prefix: &str, space: bool,
173                            br: BoundRegion) -> String {
174     let space_str = if space { " " } else { "" };
175
176     if cx.sess.verbose() {
177         return format!("{}{}{}", prefix, br.repr(cx), space_str)
178     }
179
180     match br {
181         BrNamed(_, name) => {
182             format!("{}{}{}", prefix, token::get_name(name), space_str)
183         }
184         BrAnon(_) | BrFresh(_) | BrEnv => prefix.to_string()
185     }
186 }
187
188 // In general, if you are giving a region error message,
189 // you should use `explain_region()` or, better yet,
190 // `note_and_explain_region()`
191 pub fn region_ptr_to_string(cx: &ctxt, region: Region) -> String {
192     region_to_string(cx, "&", true, region)
193 }
194
195 pub fn region_to_string(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
196     let space_str = if space { " " } else { "" };
197
198     if cx.sess.verbose() {
199         return format!("{}{}{}", prefix, region.repr(cx), space_str)
200     }
201
202     // These printouts are concise.  They do not contain all the information
203     // the user might want to diagnose an error, but there is basically no way
204     // to fit that into a short string.  Hence the recommendation to use
205     // `explain_region()` or `note_and_explain_region()`.
206     match region {
207         ty::ReScope(_) => prefix.to_string(),
208         ty::ReEarlyBound(_, _, _, name) => {
209             token::get_name(name).get().to_string()
210         }
211         ty::ReLateBound(_, br) => bound_region_to_string(cx, prefix, space, br),
212         ty::ReFree(ref fr) => bound_region_to_string(cx, prefix, space, fr.bound_region),
213         ty::ReInfer(ReSkolemized(_, br)) => {
214             bound_region_to_string(cx, prefix, space, br)
215         }
216         ty::ReInfer(ReVar(_)) => prefix.to_string(),
217         ty::ReStatic => format!("{}'static{}", prefix, space_str),
218         ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
219     }
220 }
221
222 pub fn mutability_to_string(m: ast::Mutability) -> String {
223     match m {
224         ast::MutMutable => "mut ".to_string(),
225         ast::MutImmutable => "".to_string(),
226     }
227 }
228
229 pub fn mt_to_string<'tcx>(cx: &ctxt<'tcx>, m: &mt<'tcx>) -> String {
230     format!("{}{}",
231         mutability_to_string(m.mutbl),
232         ty_to_string(cx, m.ty))
233 }
234
235 pub fn trait_store_to_string(cx: &ctxt, s: ty::TraitStore) -> String {
236     match s {
237         ty::UniqTraitStore => "Box ".to_string(),
238         ty::RegionTraitStore(r, m) => {
239             format!("{}{}", region_ptr_to_string(cx, r), mutability_to_string(m))
240         }
241     }
242 }
243
244 pub fn vec_map_to_string<T>(ts: &[T], f: |t: &T| -> String) -> String {
245     let tstrs = ts.iter().map(f).collect::<Vec<String>>();
246     format!("[{}]", tstrs.connect(", "))
247 }
248
249 pub fn fn_sig_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::FnSig<'tcx>) -> String {
250     format!("fn{} -> {}", typ.inputs.repr(cx), typ.output.repr(cx))
251 }
252
253 pub fn trait_ref_to_string<'tcx>(cx: &ctxt<'tcx>,
254                                  trait_ref: &ty::TraitRef<'tcx>) -> String {
255     trait_ref.user_string(cx).to_string()
256 }
257
258 pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
259     fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
260                                fn_style: ast::FnStyle,
261                                abi: abi::Abi,
262                                ident: Option<ast::Ident>,
263                                sig: &ty::FnSig<'tcx>)
264                                -> String {
265         let mut s = String::new();
266         match fn_style {
267             ast::NormalFn => {}
268             _ => {
269                 s.push_str(fn_style.to_string().as_slice());
270                 s.push(' ');
271             }
272         };
273
274         if abi != abi::Rust {
275             s.push_str(format!("extern {} ", abi.to_string()).as_slice());
276         };
277
278         s.push_str("fn");
279
280         match ident {
281             Some(i) => {
282                 s.push(' ');
283                 s.push_str(token::get_ident(i).get());
284             }
285             _ => { }
286         }
287
288         push_sig_to_string(cx, &mut s, '(', ')', sig, "");
289
290         s
291     }
292
293     fn closure_to_string<'tcx>(cx: &ctxt<'tcx>, cty: &ty::ClosureTy<'tcx>) -> String {
294         let mut s = String::new();
295
296         match cty.store {
297             ty::UniqTraitStore => {}
298             ty::RegionTraitStore(region, _) => {
299                 s.push_str(region_to_string(cx, "", true, region).as_slice());
300             }
301         }
302
303         match cty.fn_style {
304             ast::NormalFn => {}
305             _ => {
306                 s.push_str(cty.fn_style.to_string().as_slice());
307                 s.push(' ');
308             }
309         };
310
311         let bounds_str = cty.bounds.user_string(cx);
312
313         match cty.store {
314             ty::UniqTraitStore => {
315                 assert_eq!(cty.onceness, ast::Once);
316                 s.push_str("proc");
317                 push_sig_to_string(cx, &mut s, '(', ')', &cty.sig,
318                                    bounds_str.as_slice());
319             }
320             ty::RegionTraitStore(..) => {
321                 match cty.onceness {
322                     ast::Many => {}
323                     ast::Once => s.push_str("once ")
324                 }
325                 push_sig_to_string(cx, &mut s, '|', '|', &cty.sig,
326                                    bounds_str.as_slice());
327             }
328         }
329
330         s
331     }
332
333     fn push_sig_to_string<'tcx>(cx: &ctxt<'tcx>,
334                                 s: &mut String,
335                                 bra: char,
336                                 ket: char,
337                                 sig: &ty::FnSig<'tcx>,
338                                 bounds: &str) {
339         s.push(bra);
340         let strs = sig.inputs
341             .iter()
342             .map(|a| ty_to_string(cx, *a))
343             .collect::<Vec<_>>();
344         s.push_str(strs.connect(", ").as_slice());
345         if sig.variadic {
346             s.push_str(", ...");
347         }
348         s.push(ket);
349
350         if !bounds.is_empty() {
351             s.push_str(":");
352             s.push_str(bounds);
353         }
354
355         match sig.output {
356             ty::FnConverging(t) => {
357                 if !ty::type_is_nil(t) {
358                    s.push_str(" -> ");
359                    s.push_str(ty_to_string(cx, t).as_slice());
360                 }
361             }
362             ty::FnDiverging => {
363                 s.push_str(" -> !");
364             }
365         }
366     }
367
368     fn infer_ty_to_string(cx: &ctxt, ty: ty::InferTy) -> String {
369         let print_var_ids = cx.sess.verbose();
370         match ty {
371             ty::TyVar(ref vid) if print_var_ids => vid.repr(cx),
372             ty::IntVar(ref vid) if print_var_ids => vid.repr(cx),
373             ty::FloatVar(ref vid) if print_var_ids => vid.repr(cx),
374             ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => format!("_"),
375             ty::SkolemizedTy(v) => format!("SkolemizedTy({})", v),
376             ty::SkolemizedIntTy(v) => format!("SkolemizedIntTy({})", v)
377         }
378     }
379
380     // pretty print the structural type representation:
381     match typ.sty {
382         ty_bool => "bool".to_string(),
383         ty_char => "char".to_string(),
384         ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
385         ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
386         ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
387         ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
388         ty_ptr(ref tm) => {
389             format!("*{} {}", match tm.mutbl {
390                 ast::MutMutable => "mut",
391                 ast::MutImmutable => "const",
392             }, ty_to_string(cx, tm.ty))
393         }
394         ty_rptr(r, ref tm) => {
395             let mut buf = region_ptr_to_string(cx, r);
396             buf.push_str(mt_to_string(cx, tm).as_slice());
397             buf
398         }
399         ty_open(typ) =>
400             format!("opened<{}>", ty_to_string(cx, typ)),
401         ty_tup(ref elems) => {
402             let strs = elems
403                 .iter()
404                 .map(|elem| ty_to_string(cx, *elem))
405                 .collect::<Vec<_>>();
406             match strs.as_slice() {
407                 [ref string] => format!("({},)", string),
408                 strs => format!("({})", strs.connect(", "))
409             }
410         }
411         ty_closure(ref f) => {
412             closure_to_string(cx, &**f)
413         }
414         ty_bare_fn(ref f) => {
415             bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
416         }
417         ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
418         ty_err => "[type error]".to_string(),
419         ty_param(ref param_ty) => {
420             if cx.sess.verbose() {
421                 param_ty.repr(cx)
422             } else {
423                 param_ty.user_string(cx)
424             }
425         }
426         ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
427             let base = ty::item_path_str(cx, did);
428             let generics = ty::lookup_item_type(cx, did).generics;
429             parameterized(cx, base.as_slice(), substs, &generics)
430         }
431         ty_trait(box ty::TyTrait {
432             ref principal, ref bounds
433         }) => {
434             let base = ty::item_path_str(cx, principal.def_id);
435             let trait_def = ty::lookup_trait_def(cx, principal.def_id);
436             let ty = parameterized(cx, base.as_slice(),
437                                    &principal.substs, &trait_def.generics);
438             let bound_str = bounds.user_string(cx);
439             let bound_sep = if bound_str.is_empty() { "" } else { "+" };
440             format!("{}{}{}",
441                     ty,
442                     bound_sep,
443                     bound_str)
444         }
445         ty_str => "str".to_string(),
446         ty_unboxed_closure(ref did, _, ref substs) => {
447             let unboxed_closures = cx.unboxed_closures.borrow();
448             unboxed_closures.get(did).map(|cl| {
449                 closure_to_string(cx, &cl.closure_type.subst(cx, substs))
450             }).unwrap_or_else(|| "closure".to_string())
451         }
452         ty_vec(t, sz) => {
453             let inner_str = ty_to_string(cx, t);
454             match sz {
455                 Some(n) => format!("[{}, ..{}]", inner_str, n),
456                 None => format!("[{}]", inner_str),
457             }
458         }
459     }
460 }
461
462 pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
463                                      -> &'static str {
464     match *category {
465         ty::StaticExplicitSelfCategory => "static",
466         ty::ByValueExplicitSelfCategory => "self",
467         ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
468             "&mut self"
469         }
470         ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
471         ty::ByBoxExplicitSelfCategory => "Box<self>",
472     }
473 }
474
475 pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
476                            base: &str,
477                            substs: &subst::Substs<'tcx>,
478                            generics: &ty::Generics<'tcx>)
479                            -> String
480 {
481     if cx.sess.verbose() {
482         if substs.is_noop() {
483             return format!("{}", base);
484         } else {
485             return format!("{}<{},{}>",
486                            base,
487                            substs.regions.repr(cx),
488                            substs.types.repr(cx));
489         }
490     }
491
492     let mut strs = Vec::new();
493
494     match substs.regions {
495         subst::ErasedRegions => { }
496         subst::NonerasedRegions(ref regions) => {
497             for &r in regions.iter() {
498                 let s = region_to_string(cx, "", false, r);
499                 if s.is_empty() {
500                     // This happens when the value of the region
501                     // parameter is not easily serialized. This may be
502                     // because the user omitted it in the first place,
503                     // or because it refers to some block in the code,
504                     // etc. I'm not sure how best to serialize this.
505                     strs.push(format!("'_"));
506                 } else {
507                     strs.push(s)
508                 }
509             }
510         }
511     }
512
513     let tps = substs.types.get_slice(subst::TypeSpace);
514     let ty_params = generics.types.get_slice(subst::TypeSpace);
515     let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
516     let num_defaults = if has_defaults {
517         ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
518             match def.default {
519                 Some(default) => default.subst(cx, substs) == actual,
520                 None => false
521             }
522         }).count()
523     } else {
524         0
525     };
526
527     for t in tps[..tps.len() - num_defaults].iter() {
528         strs.push(ty_to_string(cx, *t))
529     }
530
531     if strs.len() > 0u {
532         format!("{}<{}>", base, strs.connect(", "))
533     } else {
534         format!("{}", base)
535     }
536 }
537
538 pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
539     let mut s = typ.repr(cx).to_string();
540     if s.len() >= 32u {
541         s = s.as_slice().slice(0u, 32u).to_string();
542     }
543     return s;
544 }
545
546 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Option<T> {
547     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
548         match self {
549             &None => "None".to_string(),
550             &Some(ref t) => t.repr(tcx),
551         }
552     }
553 }
554
555 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for P<T> {
556     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
557         (*self).repr(tcx)
558     }
559 }
560
561 impl<'tcx,T:Repr<'tcx>,U:Repr<'tcx>> Repr<'tcx> for Result<T,U> {
562     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
563         match self {
564             &Ok(ref t) => t.repr(tcx),
565             &Err(ref u) => format!("Err({})", u.repr(tcx))
566         }
567     }
568 }
569
570 impl<'tcx> Repr<'tcx> for () {
571     fn repr(&self, _tcx: &ctxt) -> String {
572         "()".to_string()
573     }
574 }
575
576 impl<'a, 'tcx, Sized? T:Repr<'tcx>> Repr<'tcx> for &'a T {
577     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
578         Repr::repr(*self, tcx)
579     }
580 }
581
582 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Rc<T> {
583     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
584         (&**self).repr(tcx)
585     }
586 }
587
588 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Box<T> {
589     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
590         (&**self).repr(tcx)
591     }
592 }
593
594 fn repr_vec<'tcx, T:Repr<'tcx>>(tcx: &ctxt<'tcx>, v: &[T]) -> String {
595     vec_map_to_string(v, |t| t.repr(tcx))
596 }
597
598 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for [T] {
599     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
600         repr_vec(tcx, self)
601     }
602 }
603
604 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice<T> {
605     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
606         repr_vec(tcx, self.as_slice())
607     }
608 }
609
610 // This is necessary to handle types like Option<~[T]>, for which
611 // autoderef cannot convert the &[T] handler
612 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec<T> {
613     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
614         repr_vec(tcx, self.as_slice())
615     }
616 }
617
618 impl<'tcx, T:UserString<'tcx>> UserString<'tcx> for Vec<T> {
619     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
620         let strs: Vec<String> =
621             self.iter().map(|t| t.user_string(tcx)).collect();
622         strs.connect(", ")
623     }
624 }
625
626 impl<'tcx> Repr<'tcx> for def::Def {
627     fn repr(&self, _tcx: &ctxt) -> String {
628         format!("{}", *self)
629     }
630 }
631
632 impl<'tcx> Repr<'tcx> for ty::TypeParameterDef<'tcx> {
633     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
634         format!("TypeParameterDef({}, {}, {}/{})",
635                 self.def_id,
636                 self.bounds.repr(tcx),
637                 self.space,
638                 self.index)
639     }
640 }
641
642 impl<'tcx> Repr<'tcx> for ty::RegionParameterDef {
643     fn repr(&self, tcx: &ctxt) -> String {
644         format!("RegionParameterDef(name={}, def_id={}, bounds={})",
645                 token::get_name(self.name),
646                 self.def_id.repr(tcx),
647                 self.bounds.repr(tcx))
648     }
649 }
650
651 impl<'tcx> Repr<'tcx> for ty::TyS<'tcx> {
652     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
653         ty_to_string(tcx, self)
654     }
655 }
656
657 impl<'tcx> Repr<'tcx> for ty::mt<'tcx> {
658     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
659         mt_to_string(tcx, self)
660     }
661 }
662
663 impl<'tcx> Repr<'tcx> for subst::Substs<'tcx> {
664     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
665         format!("Substs[types={}, regions={}]",
666                        self.types.repr(tcx),
667                        self.regions.repr(tcx))
668     }
669 }
670
671 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for subst::VecPerParamSpace<T> {
672     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
673         format!("[{};{};{};{}]",
674                 self.get_slice(subst::TypeSpace).repr(tcx),
675                 self.get_slice(subst::SelfSpace).repr(tcx),
676                 self.get_slice(subst::AssocSpace).repr(tcx),
677                 self.get_slice(subst::FnSpace).repr(tcx))
678     }
679 }
680
681 impl<'tcx> Repr<'tcx> for ty::ItemSubsts<'tcx> {
682     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
683         format!("ItemSubsts({})", self.substs.repr(tcx))
684     }
685 }
686
687 impl<'tcx> Repr<'tcx> for subst::RegionSubsts {
688     fn repr(&self, tcx: &ctxt) -> String {
689         match *self {
690             subst::ErasedRegions => "erased".to_string(),
691             subst::NonerasedRegions(ref regions) => regions.repr(tcx)
692         }
693     }
694 }
695
696 impl<'tcx> Repr<'tcx> for ty::BuiltinBounds {
697     fn repr(&self, _tcx: &ctxt) -> String {
698         let mut res = Vec::new();
699         for b in self.iter() {
700             res.push(match b {
701                 ty::BoundSend => "Send".to_string(),
702                 ty::BoundSized => "Sized".to_string(),
703                 ty::BoundCopy => "Copy".to_string(),
704                 ty::BoundSync => "Sync".to_string(),
705             });
706         }
707         res.connect("+")
708     }
709 }
710
711 impl<'tcx> Repr<'tcx> for ty::ExistentialBounds {
712     fn repr(&self, tcx: &ctxt) -> String {
713         self.user_string(tcx)
714     }
715 }
716
717 impl<'tcx> Repr<'tcx> for ty::ParamBounds<'tcx> {
718     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
719         let mut res = Vec::new();
720         res.push(self.builtin_bounds.repr(tcx));
721         for t in self.trait_bounds.iter() {
722             res.push(t.repr(tcx));
723         }
724         res.connect("+")
725     }
726 }
727
728 impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> {
729     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
730         // when printing out the debug representation, we don't need
731         // to enumerate the `for<...>` etc because the debruijn index
732         // tells you everything you need to know.
733         let base = ty::item_path_str(tcx, self.def_id);
734         let trait_def = ty::lookup_trait_def(tcx, self.def_id);
735         format!("<{} : {}>",
736                 self.substs.self_ty().repr(tcx),
737                 parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics))
738     }
739 }
740
741 impl<'tcx> Repr<'tcx> for ty::TraitDef<'tcx> {
742     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
743         format!("TraitDef(generics={}, bounds={}, trait_ref={})",
744                 self.generics.repr(tcx),
745                 self.bounds.repr(tcx),
746                 self.trait_ref.repr(tcx))
747     }
748 }
749
750 impl<'tcx> Repr<'tcx> for ast::TraitItem {
751     fn repr(&self, _tcx: &ctxt) -> String {
752         match *self {
753             ast::RequiredMethod(ref data) => format!("RequiredMethod({}, id={})",
754                                                      data.ident, data.id),
755             ast::ProvidedMethod(ref data) => format!("ProvidedMethod(id={})",
756                                                      data.id),
757             ast::TypeTraitItem(ref data) => format!("TypeTraitItem({}, id={})",
758                                                      data.ty_param.ident, data.ty_param.id),
759         }
760     }
761 }
762
763 impl<'tcx> Repr<'tcx> for ast::Expr {
764     fn repr(&self, _tcx: &ctxt) -> String {
765         format!("expr({}: {})", self.id, pprust::expr_to_string(self))
766     }
767 }
768
769 impl<'tcx> Repr<'tcx> for ast::Path {
770     fn repr(&self, _tcx: &ctxt) -> String {
771         format!("path({})", pprust::path_to_string(self))
772     }
773 }
774
775 impl<'tcx> UserString<'tcx> for ast::Path {
776     fn user_string(&self, _tcx: &ctxt) -> String {
777         pprust::path_to_string(self)
778     }
779 }
780
781 impl<'tcx> Repr<'tcx> for ast::Ty {
782     fn repr(&self, _tcx: &ctxt) -> String {
783         format!("type({})", pprust::ty_to_string(self))
784     }
785 }
786
787 impl<'tcx> Repr<'tcx> for ast::Item {
788     fn repr(&self, tcx: &ctxt) -> String {
789         format!("item({})", tcx.map.node_to_string(self.id))
790     }
791 }
792
793 impl<'tcx> Repr<'tcx> for ast::Lifetime {
794     fn repr(&self, _tcx: &ctxt) -> String {
795         format!("lifetime({}: {})", self.id, pprust::lifetime_to_string(self))
796     }
797 }
798
799 impl<'tcx> Repr<'tcx> for ast::Stmt {
800     fn repr(&self, _tcx: &ctxt) -> String {
801         format!("stmt({}: {})",
802                 ast_util::stmt_id(self),
803                 pprust::stmt_to_string(self))
804     }
805 }
806
807 impl<'tcx> Repr<'tcx> for ast::Pat {
808     fn repr(&self, _tcx: &ctxt) -> String {
809         format!("pat({}: {})", self.id, pprust::pat_to_string(self))
810     }
811 }
812
813 impl<'tcx> Repr<'tcx> for ty::BoundRegion {
814     fn repr(&self, tcx: &ctxt) -> String {
815         match *self {
816             ty::BrAnon(id) => format!("BrAnon({})", id),
817             ty::BrNamed(id, name) => {
818                 format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
819             }
820             ty::BrFresh(id) => format!("BrFresh({})", id),
821             ty::BrEnv => "BrEnv".to_string()
822         }
823     }
824 }
825
826 impl<'tcx> Repr<'tcx> for ty::Region {
827     fn repr(&self, tcx: &ctxt) -> String {
828         match *self {
829             ty::ReEarlyBound(id, space, index, name) => {
830                 format!("ReEarlyBound({}, {}, {}, {})",
831                                id,
832                                space,
833                                index,
834                                token::get_name(name))
835             }
836
837             ty::ReLateBound(binder_id, ref bound_region) => {
838                 format!("ReLateBound({}, {})",
839                         binder_id,
840                         bound_region.repr(tcx))
841             }
842
843             ty::ReFree(ref fr) => fr.repr(tcx),
844
845             ty::ReScope(id) => {
846                 format!("ReScope({})", id)
847             }
848
849             ty::ReStatic => {
850                 "ReStatic".to_string()
851             }
852
853             ty::ReInfer(ReVar(ref vid)) => {
854                 format!("{}", vid)
855             }
856
857             ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
858                 format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
859             }
860
861             ty::ReEmpty => {
862                 "ReEmpty".to_string()
863             }
864         }
865     }
866 }
867
868 impl<'tcx> UserString<'tcx> for ty::Region {
869     fn user_string(&self, tcx: &ctxt) -> String {
870         region_to_string(tcx, "", false, *self)
871     }
872 }
873
874 impl<'tcx> Repr<'tcx> for ty::FreeRegion {
875     fn repr(&self, tcx: &ctxt) -> String {
876         format!("ReFree({}, {})",
877                 self.scope.node_id(),
878                 self.bound_region.repr(tcx))
879     }
880 }
881
882 impl<'tcx> Repr<'tcx> for ast::DefId {
883     fn repr(&self, tcx: &ctxt) -> String {
884         // Unfortunately, there seems to be no way to attempt to print
885         // a path for a def-id, so I'll just make a best effort for now
886         // and otherwise fallback to just printing the crate/node pair
887         if self.krate == ast::LOCAL_CRATE {
888             match tcx.map.find(self.node) {
889                 Some(ast_map::NodeItem(..)) |
890                 Some(ast_map::NodeForeignItem(..)) |
891                 Some(ast_map::NodeImplItem(..)) |
892                 Some(ast_map::NodeTraitItem(..)) |
893                 Some(ast_map::NodeVariant(..)) |
894                 Some(ast_map::NodeStructCtor(..)) => {
895                     return format!(
896                                 "{}:{}",
897                                 *self,
898                                 ty::item_path_str(tcx, *self))
899                 }
900                 _ => {}
901             }
902         }
903         return format!("{}", *self)
904     }
905 }
906
907 impl<'tcx> Repr<'tcx> for ty::Polytype<'tcx> {
908     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
909         format!("Polytype {{generics: {}, ty: {}}}",
910                 self.generics.repr(tcx),
911                 self.ty.repr(tcx))
912     }
913 }
914
915 impl<'tcx> Repr<'tcx> for ty::Generics<'tcx> {
916     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
917         format!("Generics(types: {}, regions: {})",
918                 self.types.repr(tcx),
919                 self.regions.repr(tcx))
920     }
921 }
922
923 impl<'tcx> Repr<'tcx> for ty::GenericBounds<'tcx> {
924     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
925         format!("GenericBounds(types: {}, regions: {})",
926                 self.types.repr(tcx),
927                 self.regions.repr(tcx))
928     }
929 }
930
931 impl<'tcx> Repr<'tcx> for ty::ItemVariances {
932     fn repr(&self, tcx: &ctxt) -> String {
933         format!("ItemVariances(types={}, \
934                 regions={})",
935                 self.types.repr(tcx),
936                 self.regions.repr(tcx))
937     }
938 }
939
940 impl<'tcx> Repr<'tcx> for ty::Variance {
941     fn repr(&self, _: &ctxt) -> String {
942         // The first `.to_string()` returns a &'static str (it is not an implementation
943         // of the ToString trait). Because of that, we need to call `.to_string()` again
944         // if we want to have a `String`.
945         let result: &'static str = (*self).to_string();
946         result.to_string()
947     }
948 }
949
950 impl<'tcx> Repr<'tcx> for ty::Method<'tcx> {
951     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
952         format!("method(name: {}, generics: {}, fty: {}, \
953                  explicit_self: {}, vis: {}, def_id: {})",
954                 self.name.repr(tcx),
955                 self.generics.repr(tcx),
956                 self.fty.repr(tcx),
957                 self.explicit_self.repr(tcx),
958                 self.vis.repr(tcx),
959                 self.def_id.repr(tcx))
960     }
961 }
962
963 impl<'tcx> Repr<'tcx> for ast::Name {
964     fn repr(&self, _tcx: &ctxt) -> String {
965         token::get_name(*self).get().to_string()
966     }
967 }
968
969 impl<'tcx> UserString<'tcx> for ast::Name {
970     fn user_string(&self, _tcx: &ctxt) -> String {
971         token::get_name(*self).get().to_string()
972     }
973 }
974
975 impl<'tcx> Repr<'tcx> for ast::Ident {
976     fn repr(&self, _tcx: &ctxt) -> String {
977         token::get_ident(*self).get().to_string()
978     }
979 }
980
981 impl<'tcx> Repr<'tcx> for ast::ExplicitSelf_ {
982     fn repr(&self, _tcx: &ctxt) -> String {
983         format!("{}", *self)
984     }
985 }
986
987 impl<'tcx> Repr<'tcx> for ast::Visibility {
988     fn repr(&self, _tcx: &ctxt) -> String {
989         format!("{}", *self)
990     }
991 }
992
993 impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> {
994     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
995         format!("BareFnTy {{fn_style: {}, abi: {}, sig: {}}}",
996                 self.fn_style,
997                 self.abi.to_string(),
998                 self.sig.repr(tcx))
999     }
1000 }
1001
1002 impl<'tcx> Repr<'tcx> for ty::FnSig<'tcx> {
1003     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1004         fn_sig_to_string(tcx, self)
1005     }
1006 }
1007
1008 impl<'tcx> Repr<'tcx> for ty::FnOutput<'tcx> {
1009     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1010         match *self {
1011             ty::FnConverging(ty) =>
1012                 format!("FnConverging({0})", ty.repr(tcx)),
1013             ty::FnDiverging =>
1014                 "FnDiverging".to_string()
1015         }
1016     }
1017 }
1018
1019 impl<'tcx> Repr<'tcx> for ty::MethodCallee<'tcx> {
1020     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1021         format!("MethodCallee {{origin: {}, ty: {}, {}}}",
1022                 self.origin.repr(tcx),
1023                 self.ty.repr(tcx),
1024                 self.substs.repr(tcx))
1025     }
1026 }
1027
1028 impl<'tcx> Repr<'tcx> for ty::MethodOrigin<'tcx> {
1029     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1030         match self {
1031             &ty::MethodStatic(def_id) => {
1032                 format!("MethodStatic({})", def_id.repr(tcx))
1033             }
1034             &ty::MethodStaticUnboxedClosure(def_id) => {
1035                 format!("MethodStaticUnboxedClosure({})", def_id.repr(tcx))
1036             }
1037             &ty::MethodTypeParam(ref p) => {
1038                 p.repr(tcx)
1039             }
1040             &ty::MethodTraitObject(ref p) => {
1041                 p.repr(tcx)
1042             }
1043         }
1044     }
1045 }
1046
1047 impl<'tcx> Repr<'tcx> for ty::MethodParam<'tcx> {
1048     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1049         format!("MethodParam({},{})",
1050                 self.trait_ref.repr(tcx),
1051                 self.method_num)
1052     }
1053 }
1054
1055 impl<'tcx> Repr<'tcx> for ty::MethodObject<'tcx> {
1056     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1057         format!("MethodObject({},{},{})",
1058                 self.trait_ref.repr(tcx),
1059                 self.method_num,
1060                 self.real_index)
1061     }
1062 }
1063
1064 impl<'tcx> Repr<'tcx> for ty::TraitStore {
1065     fn repr(&self, tcx: &ctxt) -> String {
1066         trait_store_to_string(tcx, *self)
1067     }
1068 }
1069
1070 impl<'tcx> Repr<'tcx> for ty::BuiltinBound {
1071     fn repr(&self, _tcx: &ctxt) -> String {
1072         format!("{}", *self)
1073     }
1074 }
1075
1076 impl<'tcx> UserString<'tcx> for ty::BuiltinBound {
1077     fn user_string(&self, _tcx: &ctxt) -> String {
1078         match *self {
1079             ty::BoundSend => "Send".to_string(),
1080             ty::BoundSized => "Sized".to_string(),
1081             ty::BoundCopy => "Copy".to_string(),
1082             ty::BoundSync => "Sync".to_string(),
1083         }
1084     }
1085 }
1086
1087 impl<'tcx> Repr<'tcx> for Span {
1088     fn repr(&self, tcx: &ctxt) -> String {
1089         tcx.sess.codemap().span_to_string(*self).to_string()
1090     }
1091 }
1092
1093 impl<'tcx, A:UserString<'tcx>> UserString<'tcx> for Rc<A> {
1094     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
1095         let this: &A = &**self;
1096         this.user_string(tcx)
1097     }
1098 }
1099
1100 impl<'tcx> UserString<'tcx> for ty::ParamBounds<'tcx> {
1101     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
1102         let mut result = Vec::new();
1103         let s = self.builtin_bounds.user_string(tcx);
1104         if !s.is_empty() {
1105             result.push(s);
1106         }
1107         for n in self.trait_bounds.iter() {
1108             result.push(n.user_string(tcx));
1109         }
1110         result.connect("+")
1111     }
1112 }
1113
1114 impl<'tcx> UserString<'tcx> for ty::ExistentialBounds {
1115     fn user_string(&self, tcx: &ctxt) -> String {
1116         if self.builtin_bounds.contains(&ty::BoundSend) &&
1117             self.region_bound == ty::ReStatic
1118         { // Region bound is implied by builtin bounds:
1119             return self.builtin_bounds.repr(tcx);
1120         }
1121
1122         let mut res = Vec::new();
1123
1124         let region_str = self.region_bound.user_string(tcx);
1125         if !region_str.is_empty() {
1126             res.push(region_str);
1127         }
1128
1129         for bound in self.builtin_bounds.iter() {
1130             res.push(bound.user_string(tcx));
1131         }
1132
1133         res.connect("+")
1134     }
1135 }
1136
1137 impl<'tcx> UserString<'tcx> for ty::BuiltinBounds {
1138     fn user_string(&self, tcx: &ctxt) -> String {
1139         self.iter()
1140             .map(|bb| bb.user_string(tcx))
1141             .collect::<Vec<String>>()
1142             .connect("+")
1143             .to_string()
1144     }
1145 }
1146
1147 impl<'tcx> UserString<'tcx> for ty::TraitRef<'tcx> {
1148     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
1149         // Replace any anonymous late-bound regions with named
1150         // variants, using gensym'd identifiers, so that we can
1151         // clearly differentiate between named and unnamed regions in
1152         // the output. We'll probably want to tweak this over time to
1153         // decide just how much information to give.
1154         let mut names = Vec::new();
1155         let (trait_ref, _) = ty::replace_late_bound_regions(tcx, self, |br, debruijn| {
1156             ty::ReLateBound(debruijn, match br {
1157                 ty::BrNamed(_, name) => {
1158                     names.push(token::get_name(name));
1159                     br
1160                 }
1161                 ty::BrAnon(_) |
1162                 ty::BrFresh(_) |
1163                 ty::BrEnv => {
1164                     let name = token::gensym("r");
1165                     names.push(token::get_name(name));
1166                     ty::BrNamed(ast_util::local_def(ast::DUMMY_NODE_ID), name)
1167                 }
1168             })
1169         });
1170         let names: Vec<_> = names.iter().map(|s| s.get()).collect();
1171
1172         // Let the base string be either `SomeTrait` for `for<'a,'b> SomeTrait`,
1173         // depending on whether there are bound regions.
1174         let path_str = ty::item_path_str(tcx, self.def_id);
1175         let base =
1176             if names.is_empty() {
1177                 path_str
1178             } else {
1179                 format!("for<{}> {}", names.connect(","), path_str)
1180             };
1181
1182         let trait_def = ty::lookup_trait_def(tcx, self.def_id);
1183         parameterized(tcx, base.as_slice(), &trait_ref.substs, &trait_def.generics)
1184     }
1185 }
1186
1187 impl<'tcx> UserString<'tcx> for Ty<'tcx> {
1188     fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
1189         ty_to_string(tcx, *self)
1190     }
1191 }
1192
1193 impl<'tcx> UserString<'tcx> for ast::Ident {
1194     fn user_string(&self, _tcx: &ctxt) -> String {
1195         token::get_name(self.name).get().to_string()
1196     }
1197 }
1198
1199 impl<'tcx> Repr<'tcx> for abi::Abi {
1200     fn repr(&self, _tcx: &ctxt) -> String {
1201         self.to_string()
1202     }
1203 }
1204
1205 impl<'tcx> UserString<'tcx> for abi::Abi {
1206     fn user_string(&self, _tcx: &ctxt) -> String {
1207         self.to_string()
1208     }
1209 }
1210
1211 impl<'tcx> Repr<'tcx> for ty::UpvarId {
1212     fn repr(&self, tcx: &ctxt) -> String {
1213         format!("UpvarId({};`{}`;{})",
1214                 self.var_id,
1215                 ty::local_var_name_str(tcx, self.var_id),
1216                 self.closure_expr_id)
1217     }
1218 }
1219
1220 impl<'tcx> Repr<'tcx> for ast::Mutability {
1221     fn repr(&self, _tcx: &ctxt) -> String {
1222         format!("{}", *self)
1223     }
1224 }
1225
1226 impl<'tcx> Repr<'tcx> for ty::BorrowKind {
1227     fn repr(&self, _tcx: &ctxt) -> String {
1228         format!("{}", *self)
1229     }
1230 }
1231
1232 impl<'tcx> Repr<'tcx> for ty::UpvarBorrow {
1233     fn repr(&self, tcx: &ctxt) -> String {
1234         format!("UpvarBorrow({}, {})",
1235                 self.kind.repr(tcx),
1236                 self.region.repr(tcx))
1237     }
1238 }
1239
1240 impl<'tcx> Repr<'tcx> for ty::IntVid {
1241     fn repr(&self, _tcx: &ctxt) -> String {
1242         format!("{}", self)
1243     }
1244 }
1245
1246 impl<'tcx> Repr<'tcx> for ty::FloatVid {
1247     fn repr(&self, _tcx: &ctxt) -> String {
1248         format!("{}", self)
1249     }
1250 }
1251
1252 impl<'tcx> Repr<'tcx> for ty::RegionVid {
1253     fn repr(&self, _tcx: &ctxt) -> String {
1254         format!("{}", self)
1255     }
1256 }
1257
1258 impl<'tcx> Repr<'tcx> for ty::TyVid {
1259     fn repr(&self, _tcx: &ctxt) -> String {
1260         format!("{}", self)
1261     }
1262 }
1263
1264 impl<'tcx> Repr<'tcx> for ty::IntVarValue {
1265     fn repr(&self, _tcx: &ctxt) -> String {
1266         format!("{}", *self)
1267     }
1268 }
1269
1270 impl<'tcx> Repr<'tcx> for ast::IntTy {
1271     fn repr(&self, _tcx: &ctxt) -> String {
1272         format!("{}", *self)
1273     }
1274 }
1275
1276 impl<'tcx> Repr<'tcx> for ast::UintTy {
1277     fn repr(&self, _tcx: &ctxt) -> String {
1278         format!("{}", *self)
1279     }
1280 }
1281
1282 impl<'tcx> Repr<'tcx> for ast::FloatTy {
1283     fn repr(&self, _tcx: &ctxt) -> String {
1284         format!("{}", *self)
1285     }
1286 }
1287
1288 impl<'tcx> Repr<'tcx> for ty::ExplicitSelfCategory {
1289     fn repr(&self, _: &ctxt) -> String {
1290         explicit_self_category_to_str(self).to_string()
1291     }
1292 }
1293
1294 impl<'tcx> UserString<'tcx> for ParamTy {
1295     fn user_string(&self, tcx: &ctxt) -> String {
1296         let id = self.idx;
1297         let did = self.def_id;
1298         let ident = match tcx.ty_param_defs.borrow().get(&did.node) {
1299             Some(def) => token::get_name(def.name).get().to_string(),
1300
1301             // This can only happen when a type mismatch error happens and
1302             // the actual type has more type parameters than the expected one.
1303             None => format!("<generic #{}>", id),
1304         };
1305         ident
1306     }
1307 }
1308
1309 impl<'tcx> Repr<'tcx> for ParamTy {
1310     fn repr(&self, tcx: &ctxt) -> String {
1311         let ident = self.user_string(tcx);
1312         format!("{}/{}.{}", ident, self.space, self.idx)
1313     }
1314 }
1315
1316 impl<'tcx, A:Repr<'tcx>, B:Repr<'tcx>> Repr<'tcx> for (A,B) {
1317     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1318         let &(ref a, ref b) = self;
1319         format!("({},{})", a.repr(tcx), b.repr(tcx))
1320     }
1321 }
1322
1323 impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for ty::Binder<T> {
1324     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1325         format!("Binder({})", self.value.repr(tcx))
1326     }
1327 }