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.
13 use middle::subst::{VecPerParamSpace,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};
19 use middle::ty::{mt, t, ParamTy};
20 use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, 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_nil, 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};
26 use middle::typeck::infer::region_inference;
27 use middle::typeck::infer::unify::VarValue as VV;
28 use middle::typeck::infer::unify;
29 use middle::typeck::infer;
36 use syntax::codemap::{Span, Pos};
37 use syntax::parse::token;
38 use syntax::print::pprust;
39 use syntax::{ast, ast_util};
40 use syntax::owned_slice::OwnedSlice;
42 /// Produces a string suitable for debugging output.
44 fn repr(&self, tcx: &ctxt) -> String;
47 /// Produces a string suitable for showing to the user.
48 pub trait UserString {
49 fn user_string(&self, tcx: &ctxt) -> String;
52 pub fn note_and_explain_region(cx: &ctxt,
56 match explain_region_and_span(cx, region) {
57 (ref str, Some(span)) => {
60 format!("{}{}{}", prefix, *str, suffix).as_slice());
64 format!("{}{}{}", prefix, *str, suffix).as_slice());
69 pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
70 -> (String, Option<Span>) {
73 match cx.map.find(node_id) {
74 Some(ast_map::NodeBlock(ref blk)) => {
75 explain_span(cx, "block", blk.span)
77 Some(ast_map::NodeExpr(expr)) => {
79 ast::ExprCall(..) => explain_span(cx, "call", expr.span),
80 ast::ExprMethodCall(..) => {
81 explain_span(cx, "method call", expr.span)
83 ast::ExprMatch(..) => explain_span(cx, "match", expr.span),
84 _ => explain_span(cx, "expression", expr.span)
87 Some(ast_map::NodeStmt(stmt)) => {
88 explain_span(cx, "statement", stmt.span)
90 Some(ast_map::NodeItem(it)) if (match it.node {
91 ast::ItemFn(..) => true, _ => false}) => {
92 explain_span(cx, "function body", it.span)
95 // this really should not happen
96 (format!("unknown scope: {}. Please report a bug.", node_id), None)
102 let prefix = match fr.bound_region {
104 format!("the anonymous lifetime #{} defined on", idx + 1)
106 BrFresh(_) => "an anonymous lifetime defined on".to_string(),
108 format!("the lifetime {} as defined on",
109 bound_region_ptr_to_string(cx, fr.bound_region))
113 match cx.map.find(fr.scope_id) {
114 Some(ast_map::NodeBlock(ref blk)) => {
115 let (msg, opt_span) = explain_span(cx, "block", blk.span);
116 (format!("{} {}", prefix, msg), opt_span)
118 Some(ast_map::NodeItem(it)) if match it.node {
119 ast::ItemImpl(..) => true, _ => false} => {
120 let (msg, opt_span) = explain_span(cx, "impl", it.span);
121 (format!("{} {}", prefix, msg), opt_span)
124 // this really should not happen
125 (format!("{} node {}", prefix, fr.scope_id), None)
130 ReStatic => { ("the static lifetime".to_string(), None) }
132 ReEmpty => { ("the empty lifetime".to_string(), None) }
134 ReEarlyBound(_, _, _, name) => {
135 (format!("{}", token::get_name(name)), None)
138 // I believe these cases should not occur (except when debugging,
140 ty::ReInfer(_) | ty::ReLateBound(..) => {
141 (format!("lifetime {:?}", region), None)
145 fn explain_span(cx: &ctxt, heading: &str, span: Span)
146 -> (String, Option<Span>) {
147 let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
148 (format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
153 pub fn bound_region_ptr_to_string(cx: &ctxt, br: BoundRegion) -> String {
154 bound_region_to_string(cx, "", false, br)
157 pub fn bound_region_to_string(cx: &ctxt,
158 prefix: &str, space: bool,
159 br: BoundRegion) -> String {
160 let space_str = if space { " " } else { "" };
162 if cx.sess.verbose() {
163 return format!("{}{}{}", prefix, br.repr(cx), space_str)
167 BrNamed(_, name) => {
168 format!("{}{}{}", prefix, token::get_name(name), space_str)
170 BrAnon(_) => prefix.to_string(),
171 BrFresh(_) => prefix.to_string(),
175 // In general, if you are giving a region error message,
176 // you should use `explain_region()` or, better yet,
177 // `note_and_explain_region()`
178 pub fn region_ptr_to_string(cx: &ctxt, region: Region) -> String {
179 region_to_string(cx, "&", true, region)
182 pub fn region_to_string(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
183 let space_str = if space { " " } else { "" };
185 if cx.sess.verbose() {
186 return format!("{}{}{}", prefix, region.repr(cx), space_str)
189 // These printouts are concise. They do not contain all the information
190 // the user might want to diagnose an error, but there is basically no way
191 // to fit that into a short string. Hence the recommendation to use
192 // `explain_region()` or `note_and_explain_region()`.
194 ty::ReScope(_) => prefix.to_string(),
195 ty::ReEarlyBound(_, _, _, name) => {
196 token::get_name(name).get().to_string()
198 ty::ReLateBound(_, br) => bound_region_to_string(cx, prefix, space, br),
199 ty::ReFree(ref fr) => bound_region_to_string(cx, prefix, space, fr.bound_region),
200 ty::ReInfer(ReSkolemized(_, br)) => {
201 bound_region_to_string(cx, prefix, space, br)
203 ty::ReInfer(ReVar(_)) => prefix.to_string(),
204 ty::ReStatic => format!("{}'static{}", prefix, space_str),
205 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
209 pub fn mutability_to_string(m: ast::Mutability) -> String {
211 ast::MutMutable => "mut ".to_string(),
212 ast::MutImmutable => "".to_string(),
216 pub fn mt_to_string(cx: &ctxt, m: &mt) -> String {
217 format!("{}{}", mutability_to_string(m.mutbl), ty_to_string(cx, m.ty))
220 pub fn trait_store_to_string(cx: &ctxt, s: ty::TraitStore) -> String {
222 ty::UniqTraitStore => "Box ".to_string(),
223 ty::RegionTraitStore(r, m) => {
224 format!("{}{}", region_ptr_to_string(cx, r), mutability_to_string(m))
229 pub fn vec_map_to_string<T>(ts: &[T], f: |t: &T| -> String) -> String {
230 let tstrs = ts.iter().map(f).collect::<Vec<String>>();
231 format!("[{}]", tstrs.connect(", "))
234 pub fn fn_sig_to_string(cx: &ctxt, typ: &ty::FnSig) -> String {
235 format!("fn{}{} -> {}", typ.binder_id, typ.inputs.repr(cx),
239 pub fn trait_ref_to_string(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
240 trait_ref.user_string(cx).to_string()
243 pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
244 fn fn_input_to_string(cx: &ctxt, input: ty::t) -> String {
245 ty_to_string(cx, input).to_string()
247 fn bare_fn_to_string(cx: &ctxt,
248 fn_style: ast::FnStyle,
250 ident: Option<ast::Ident>,
253 let mut s = String::new();
257 s.push_str(fn_style.to_string().as_slice());
262 if abi != abi::Rust {
263 s.push_str(format!("extern {} ", abi.to_string()).as_slice());
271 s.push_str(token::get_ident(i).get());
276 push_sig_to_string(cx, &mut s, '(', ')', sig);
281 fn closure_to_string(cx: &ctxt, cty: &ty::ClosureTy) -> String {
282 let mut s = String::new();
285 ty::UniqTraitStore => {}
286 ty::RegionTraitStore(region, _) => {
287 s.push_str(region_to_string(cx, "", true, region).as_slice());
294 s.push_str(cty.fn_style.to_string().as_slice());
300 ty::UniqTraitStore => {
301 assert_eq!(cty.onceness, ast::Once);
303 push_sig_to_string(cx, &mut s, '(', ')', &cty.sig);
305 ty::RegionTraitStore(..) => {
308 ast::Once => s.push_str("once ")
310 push_sig_to_string(cx, &mut s, '|', '|', &cty.sig);
314 if !cty.bounds.is_empty() {
316 s.push_str(cty.bounds.repr(cx).as_slice());
322 fn push_sig_to_string(cx: &ctxt,
328 let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_string(cx, *a)).collect();
329 s.push_str(strs.connect(", ").as_slice());
335 if ty::get(sig.output).sty != ty_nil {
337 if ty::type_is_bot(sig.output) {
340 s.push_str(ty_to_string(cx, sig.output).as_slice());
345 // if there is an id, print that instead of the structural type:
346 /*for def_id in ty::type_def_id(typ).iter() {
347 // note that this typedef cannot have type parameters
348 return ty::item_path_str(cx, *def_id);
351 // pretty print the structural type representation:
352 return match ty::get(typ).sty {
353 ty_nil => "()".to_string(),
354 ty_bot => "!".to_string(),
355 ty_bool => "bool".to_string(),
356 ty_char => "char".to_string(),
357 ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
358 ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
359 ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
360 ty_box(typ) => format!("Gc<{}>", ty_to_string(cx, typ)),
361 ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
363 format!("*{} {}", match tm.mutbl {
364 ast::MutMutable => "mut",
365 ast::MutImmutable => "const",
366 }, ty_to_string(cx, tm.ty))
368 ty_rptr(r, ref tm) => {
369 let mut buf = region_ptr_to_string(cx, r);
370 buf.push_str(mt_to_string(cx, tm).as_slice());
373 ty_open(typ) => format!("opened<{}>", ty_to_string(cx, typ)),
374 ty_tup(ref elems) => {
375 let strs: Vec<String> = elems.iter().map(|elem| ty_to_string(cx, *elem)).collect();
376 format!("({})", strs.connect(","))
378 ty_closure(ref f) => {
379 closure_to_string(cx, &**f)
381 ty_bare_fn(ref f) => {
382 bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
384 ty_infer(infer_ty) => infer_ty.to_string(),
385 ty_err => "[type error]".to_string(),
386 ty_param(ParamTy {idx: id, def_id: did, ..}) => {
387 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
388 Some(def) => token::get_ident(def.ident).get().to_string(),
389 // This can only happen when a type mismatch error happens and
390 // the actual type has more type parameters than the expected one.
391 None => format!("<generic #{}>", id),
393 if !cx.sess.verbose() {
396 format!("{}:{:?}", ident, did)
399 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
400 let base = ty::item_path_str(cx, did);
401 let generics = ty::lookup_item_type(cx, did).generics;
402 parameterized(cx, base.as_slice(), substs, &generics)
404 ty_trait(box ty::TyTrait {
405 def_id: did, ref substs, ref bounds
407 let base = ty::item_path_str(cx, did);
408 let trait_def = ty::lookup_trait_def(cx, did);
409 let ty = parameterized(cx, base.as_slice(),
410 substs, &trait_def.generics);
411 let bound_sep = if bounds.is_empty() { "" } else { "+" };
412 let bound_str = bounds.repr(cx);
418 ty_str => "str".to_string(),
419 ty_unboxed_closure(..) => "closure".to_string(),
423 format!("[{}, .. {}]", ty_to_string(cx, t), n)
425 None => format!("[{}]", ty_to_string(cx, t)),
431 pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
434 ty::StaticExplicitSelfCategory => "static",
435 ty::ByValueExplicitSelfCategory => "self",
436 ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
439 ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
440 ty::ByBoxExplicitSelfCategory => "Box<self>",
444 pub fn parameterized(cx: &ctxt,
446 substs: &subst::Substs,
447 generics: &ty::Generics)
450 let mut strs = Vec::new();
452 match substs.regions {
453 subst::ErasedRegions => { }
454 subst::NonerasedRegions(ref regions) => {
455 for &r in regions.iter() {
456 let s = region_to_string(cx, "", false, r);
460 // This happens when the value of the region
461 // parameter is not easily serialized. This may be
462 // because the user omitted it in the first place,
463 // or because it refers to some block in the code,
464 // etc. I'm not sure how best to serialize this.
465 strs.push(format!("'_"));
471 let tps = substs.types.get_slice(subst::TypeSpace);
472 let ty_params = generics.types.get_slice(subst::TypeSpace);
473 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
474 let num_defaults = if has_defaults && !cx.sess.verbose() {
475 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
477 Some(default) => default.subst(cx, substs) == actual,
485 for t in tps.slice_to(tps.len() - num_defaults).iter() {
486 strs.push(ty_to_string(cx, *t))
489 if cx.sess.verbose() {
490 for t in substs.types.get_slice(subst::SelfSpace).iter() {
491 strs.push(format!("for {}", t.repr(cx)));
496 format!("{}<{}>", base, strs.connect(","))
502 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String {
503 let mut s = typ.repr(cx).to_string();
505 s = s.as_slice().slice(0u, 32u).to_string();
510 impl<T:Repr> Repr for Option<T> {
511 fn repr(&self, tcx: &ctxt) -> String {
513 &None => "None".to_string(),
514 &Some(ref t) => t.repr(tcx),
519 impl<T:Repr,U:Repr> Repr for Result<T,U> {
520 fn repr(&self, tcx: &ctxt) -> String {
522 &Ok(ref t) => t.repr(tcx),
523 &Err(ref u) => format!("Err({})", u.repr(tcx))
529 fn repr(&self, _tcx: &ctxt) -> String {
534 impl<T:Repr> Repr for Rc<T> {
535 fn repr(&self, tcx: &ctxt) -> String {
540 impl<T:Repr + 'static> Repr for Gc<T> {
541 fn repr(&self, tcx: &ctxt) -> String {
546 impl<T:Repr> Repr for Box<T> {
547 fn repr(&self, tcx: &ctxt) -> String {
552 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> String {
553 vec_map_to_string(v, |t| t.repr(tcx))
556 impl<'a, T:Repr> Repr for &'a [T] {
557 fn repr(&self, tcx: &ctxt) -> String {
562 impl<T:Repr> Repr for OwnedSlice<T> {
563 fn repr(&self, tcx: &ctxt) -> String {
564 repr_vec(tcx, self.as_slice())
568 // This is necessary to handle types like Option<~[T]>, for which
569 // autoderef cannot convert the &[T] handler
570 impl<T:Repr> Repr for Vec<T> {
571 fn repr(&self, tcx: &ctxt) -> String {
572 repr_vec(tcx, self.as_slice())
576 impl Repr for def::Def {
577 fn repr(&self, _tcx: &ctxt) -> String {
578 format!("{:?}", *self)
582 impl Repr for ty::TypeParameterDef {
583 fn repr(&self, tcx: &ctxt) -> String {
584 format!("TypeParameterDef({:?}, {})", self.def_id,
585 self.bounds.repr(tcx))
589 impl Repr for ty::RegionParameterDef {
590 fn repr(&self, _tcx: &ctxt) -> String {
591 format!("RegionParameterDef({}, {:?})",
592 token::get_name(self.name),
597 impl Repr for ty::t {
598 fn repr(&self, tcx: &ctxt) -> String {
599 ty_to_string(tcx, *self)
603 impl Repr for ty::mt {
604 fn repr(&self, tcx: &ctxt) -> String {
605 mt_to_string(tcx, self)
609 impl Repr for subst::Substs {
610 fn repr(&self, tcx: &ctxt) -> String {
611 format!("Substs[types={}, regions={}]",
612 self.types.repr(tcx),
613 self.regions.repr(tcx))
617 impl<T:Repr> Repr for subst::VecPerParamSpace<T> {
618 fn repr(&self, tcx: &ctxt) -> String {
619 format!("[{};{};{}]",
620 self.get_slice(subst::TypeSpace).repr(tcx),
621 self.get_slice(subst::SelfSpace).repr(tcx),
622 self.get_slice(subst::FnSpace).repr(tcx))
626 impl Repr for ty::ItemSubsts {
627 fn repr(&self, tcx: &ctxt) -> String {
628 format!("ItemSubsts({})", self.substs.repr(tcx))
632 impl Repr for subst::RegionSubsts {
633 fn repr(&self, tcx: &ctxt) -> String {
635 subst::ErasedRegions => "erased".to_string(),
636 subst::NonerasedRegions(ref regions) => regions.repr(tcx)
641 impl Repr for ty::ParamBounds {
642 fn repr(&self, tcx: &ctxt) -> String {
643 let mut res = Vec::new();
644 for b in self.builtin_bounds.iter() {
646 ty::BoundStatic => "'static".to_string(),
647 ty::BoundSend => "Send".to_string(),
648 ty::BoundSized => "Sized".to_string(),
649 ty::BoundCopy => "Copy".to_string(),
650 ty::BoundSync => "Sync".to_string(),
653 for t in self.trait_bounds.iter() {
654 res.push(t.repr(tcx));
660 impl Repr for ty::TraitRef {
661 fn repr(&self, tcx: &ctxt) -> String {
662 trait_ref_to_string(tcx, self)
666 impl Repr for ast::Expr {
667 fn repr(&self, _tcx: &ctxt) -> String {
668 format!("expr({}: {})", self.id, pprust::expr_to_string(self))
672 impl Repr for ast::Path {
673 fn repr(&self, _tcx: &ctxt) -> String {
674 format!("path({})", pprust::path_to_string(self))
678 impl Repr for ast::Item {
679 fn repr(&self, tcx: &ctxt) -> String {
680 format!("item({})", tcx.map.node_to_string(self.id))
684 impl Repr for ast::Stmt {
685 fn repr(&self, _tcx: &ctxt) -> String {
686 format!("stmt({}: {})",
687 ast_util::stmt_id(self),
688 pprust::stmt_to_string(self))
692 impl Repr for ast::Pat {
693 fn repr(&self, _tcx: &ctxt) -> String {
694 format!("pat({}: {})", self.id, pprust::pat_to_string(self))
698 impl Repr for ty::BoundRegion {
699 fn repr(&self, tcx: &ctxt) -> String {
701 ty::BrAnon(id) => format!("BrAnon({})", id),
702 ty::BrNamed(id, name) => {
703 format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
705 ty::BrFresh(id) => format!("BrFresh({})", id),
710 impl Repr for ty::Region {
711 fn repr(&self, tcx: &ctxt) -> String {
713 ty::ReEarlyBound(id, space, index, name) => {
714 format!("ReEarlyBound({}, {}, {}, {})",
718 token::get_name(name))
721 ty::ReLateBound(binder_id, ref bound_region) => {
722 format!("ReLateBound({}, {})",
724 bound_region.repr(tcx))
727 ty::ReFree(ref fr) => {
728 format!("ReFree({}, {})",
730 fr.bound_region.repr(tcx))
734 format!("ReScope({})", id)
738 "ReStatic".to_string()
741 ty::ReInfer(ReVar(ref vid)) => {
742 format!("ReInfer({})", vid.index)
745 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
746 format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
750 "ReEmpty".to_string()
756 impl Repr for ast::DefId {
757 fn repr(&self, tcx: &ctxt) -> String {
758 // Unfortunately, there seems to be no way to attempt to print
759 // a path for a def-id, so I'll just make a best effort for now
760 // and otherwise fallback to just printing the crate/node pair
761 if self.krate == ast::LOCAL_CRATE {
763 match tcx.map.find(self.node) {
764 Some(ast_map::NodeItem(..)) |
765 Some(ast_map::NodeForeignItem(..)) |
766 Some(ast_map::NodeImplItem(..)) |
767 Some(ast_map::NodeTraitItem(..)) |
768 Some(ast_map::NodeVariant(..)) |
769 Some(ast_map::NodeStructCtor(..)) => {
773 ty::item_path_str(tcx, *self))
779 return format!("{:?}", *self)
783 impl Repr for ty::Polytype {
784 fn repr(&self, tcx: &ctxt) -> String {
785 format!("Polytype {{generics: {}, ty: {}}}",
786 self.generics.repr(tcx),
791 impl Repr for ty::Generics {
792 fn repr(&self, tcx: &ctxt) -> String {
793 format!("Generics(types: {}, regions: {})",
794 self.types.repr(tcx),
795 self.regions.repr(tcx))
799 impl Repr for ty::ItemVariances {
800 fn repr(&self, tcx: &ctxt) -> String {
801 format!("ItemVariances(types={}, \
803 self.types.repr(tcx),
804 self.regions.repr(tcx))
808 impl Repr for ty::Variance {
809 fn repr(&self, _: &ctxt) -> String {
810 // The first `.to_string()` returns a &'static str (it is not an implementation
811 // of the ToString trait). Because of that, we need to call `.to_string()` again
812 // if we want to have a `String`.
813 self.to_string().to_string()
817 impl Repr for ty::Method {
818 fn repr(&self, tcx: &ctxt) -> String {
819 format!("method(ident: {}, generics: {}, fty: {}, \
820 explicit_self: {}, vis: {}, def_id: {})",
821 self.ident.repr(tcx),
822 self.generics.repr(tcx),
824 self.explicit_self.repr(tcx),
826 self.def_id.repr(tcx))
830 impl Repr for ast::Name {
831 fn repr(&self, _tcx: &ctxt) -> String {
832 token::get_name(*self).get().to_string()
836 impl Repr for ast::Ident {
837 fn repr(&self, _tcx: &ctxt) -> String {
838 token::get_ident(*self).get().to_string()
842 impl Repr for ast::ExplicitSelf_ {
843 fn repr(&self, _tcx: &ctxt) -> String {
844 format!("{:?}", *self)
848 impl Repr for ast::Visibility {
849 fn repr(&self, _tcx: &ctxt) -> String {
850 format!("{:?}", *self)
854 impl Repr for ty::BareFnTy {
855 fn repr(&self, tcx: &ctxt) -> String {
856 format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
858 self.abi.to_string(),
863 impl Repr for ty::FnSig {
864 fn repr(&self, tcx: &ctxt) -> String {
865 fn_sig_to_string(tcx, self)
869 impl Repr for typeck::MethodCallee {
870 fn repr(&self, tcx: &ctxt) -> String {
871 format!("MethodCallee {{origin: {}, ty: {}, {}}}",
872 self.origin.repr(tcx),
874 self.substs.repr(tcx))
878 impl Repr for typeck::MethodOrigin {
879 fn repr(&self, tcx: &ctxt) -> String {
881 &typeck::MethodStatic(def_id) => {
882 format!("MethodStatic({})", def_id.repr(tcx))
884 &typeck::MethodStaticUnboxedClosure(def_id) => {
885 format!("MethodStaticUnboxedClosure({})", def_id.repr(tcx))
887 &typeck::MethodParam(ref p) => {
890 &typeck::MethodObject(ref p) => {
897 impl Repr for typeck::MethodParam {
898 fn repr(&self, tcx: &ctxt) -> String {
899 format!("MethodParam({},{:?},{:?},{:?})",
900 self.trait_id.repr(tcx),
907 impl Repr for typeck::MethodObject {
908 fn repr(&self, tcx: &ctxt) -> String {
909 format!("MethodObject({},{:?},{:?})",
910 self.trait_id.repr(tcx),
916 impl Repr for ty::TraitStore {
917 fn repr(&self, tcx: &ctxt) -> String {
918 trait_store_to_string(tcx, *self)
922 impl Repr for ty::BuiltinBound {
923 fn repr(&self, _tcx: &ctxt) -> String {
924 format!("{:?}", *self)
928 impl UserString for ty::BuiltinBound {
929 fn user_string(&self, _tcx: &ctxt) -> String {
931 ty::BoundStatic => "'static".to_string(),
932 ty::BoundSend => "Send".to_string(),
933 ty::BoundSized => "Sized".to_string(),
934 ty::BoundCopy => "Copy".to_string(),
935 ty::BoundSync => "Sync".to_string(),
940 impl Repr for ty::BuiltinBounds {
941 fn repr(&self, tcx: &ctxt) -> String {
942 self.user_string(tcx)
947 fn repr(&self, tcx: &ctxt) -> String {
948 tcx.sess.codemap().span_to_string(*self).to_string()
952 impl<A:UserString> UserString for Rc<A> {
953 fn user_string(&self, tcx: &ctxt) -> String {
954 let this: &A = &**self;
955 this.user_string(tcx)
959 impl UserString for ty::BuiltinBounds {
960 fn user_string(&self, tcx: &ctxt) -> String {
962 .map(|bb| bb.user_string(tcx))
963 .collect::<Vec<String>>()
969 impl UserString for ty::TraitRef {
970 fn user_string(&self, tcx: &ctxt) -> String {
971 let base = ty::item_path_str(tcx, self.def_id);
972 let trait_def = ty::lookup_trait_def(tcx, self.def_id);
973 parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
977 impl UserString for ty::t {
978 fn user_string(&self, tcx: &ctxt) -> String {
979 ty_to_string(tcx, *self)
983 impl UserString for ast::Ident {
984 fn user_string(&self, _tcx: &ctxt) -> String {
985 token::get_name(self.name).get().to_string()
989 impl Repr for abi::Abi {
990 fn repr(&self, _tcx: &ctxt) -> String {
995 impl UserString for abi::Abi {
996 fn user_string(&self, _tcx: &ctxt) -> String {
1001 impl Repr for ty::UpvarId {
1002 fn repr(&self, tcx: &ctxt) -> String {
1003 format!("UpvarId({};`{}`;{})",
1005 ty::local_var_name_str(tcx, self.var_id),
1006 self.closure_expr_id)
1010 impl Repr for ast::Mutability {
1011 fn repr(&self, _tcx: &ctxt) -> String {
1012 format!("{:?}", *self)
1016 impl Repr for ty::BorrowKind {
1017 fn repr(&self, _tcx: &ctxt) -> String {
1018 format!("{:?}", *self)
1022 impl Repr for ty::UpvarBorrow {
1023 fn repr(&self, tcx: &ctxt) -> String {
1024 format!("UpvarBorrow({}, {})",
1025 self.kind.repr(tcx),
1026 self.region.repr(tcx))
1030 impl Repr for ty::IntVid {
1031 fn repr(&self, _tcx: &ctxt) -> String {
1036 impl Repr for ty::FloatVid {
1037 fn repr(&self, _tcx: &ctxt) -> String {
1042 impl Repr for ty::RegionVid {
1043 fn repr(&self, _tcx: &ctxt) -> String {
1048 impl Repr for ty::TyVid {
1049 fn repr(&self, _tcx: &ctxt) -> String {
1054 impl Repr for ty::IntVarValue {
1055 fn repr(&self, _tcx: &ctxt) -> String {
1056 format!("{:?}", *self)
1060 impl Repr for ast::IntTy {
1061 fn repr(&self, _tcx: &ctxt) -> String {
1062 format!("{:?}", *self)
1066 impl Repr for ast::UintTy {
1067 fn repr(&self, _tcx: &ctxt) -> String {
1068 format!("{:?}", *self)
1072 impl Repr for ast::FloatTy {
1073 fn repr(&self, _tcx: &ctxt) -> String {
1074 format!("{:?}", *self)
1078 impl<T:Repr> Repr for infer::Bounds<T> {
1079 fn repr(&self, tcx: &ctxt) -> String {
1080 format!("({} <= {})",
1086 impl<K:Repr,V:Repr> Repr for VV<K,V> {
1087 fn repr(&self, tcx: &ctxt) -> String {
1089 unify::Redirect(ref k) =>
1090 format!("Redirect({})", k.repr(tcx)),
1091 unify::Root(ref v, r) =>
1092 format!("Root({}, {})", v.repr(tcx), r)
1097 impl Repr for region_inference::VarValue {
1098 fn repr(&self, tcx: &ctxt) -> String {
1100 infer::region_inference::NoValue =>
1102 infer::region_inference::Value(r) =>
1103 format!("Value({})", r.repr(tcx)),
1104 infer::region_inference::ErrorValue =>
1105 format!("ErrorValue"),
1110 impl Repr for ty::ExplicitSelfCategory {
1111 fn repr(&self, _: &ctxt) -> String {
1112 explicit_self_category_to_str(self).to_string()