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.
14 use middle::subst::{VecPerParamSpace,Subst};
15 use middle::ty::{ReSkolemized, ReVar};
16 use middle::ty::{BoundRegion, BrAnon, BrNamed};
17 use middle::ty::{BrFresh, ctxt};
18 use middle::ty::{mt, t, ParamTy};
19 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region,
21 use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
22 use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
23 use middle::ty::{ty_nil, ty_param, ty_ptr, ty_rptr, ty_tup};
24 use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
27 use middle::typeck::infer;
28 use middle::typeck::infer::unify;
29 use VV = middle::typeck::infer::unify::VarValue;
30 use middle::typeck::infer::region_inference;
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_str(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 // I believe these cases should not occur (except when debugging,
136 ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
137 (format!("lifetime {:?}", region), None)
141 fn explain_span(cx: &ctxt, heading: &str, span: Span)
142 -> (String, Option<Span>) {
143 let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
144 (format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
149 pub fn bound_region_ptr_to_str(cx: &ctxt, br: BoundRegion) -> String {
150 bound_region_to_str(cx, "", false, br)
153 pub fn bound_region_to_str(cx: &ctxt,
154 prefix: &str, space: bool,
155 br: BoundRegion) -> String {
156 let space_str = if space { " " } else { "" };
158 if cx.sess.verbose() {
159 return format!("{}{}{}", prefix, br.repr(cx), space_str)
163 BrNamed(_, name) => {
164 format!("{}{}{}", prefix, token::get_name(name), space_str)
166 BrAnon(_) => prefix.to_string(),
167 BrFresh(_) => prefix.to_string(),
171 // In general, if you are giving a region error message,
172 // you should use `explain_region()` or, better yet,
173 // `note_and_explain_region()`
174 pub fn region_ptr_to_str(cx: &ctxt, region: Region) -> String {
175 region_to_str(cx, "&", true, region)
178 pub fn region_to_str(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
179 let space_str = if space { " " } else { "" };
181 if cx.sess.verbose() {
182 return format!("{}{}{}", prefix, region.repr(cx), space_str)
185 // These printouts are concise. They do not contain all the information
186 // the user might want to diagnose an error, but there is basically no way
187 // to fit that into a short string. Hence the recommendation to use
188 // `explain_region()` or `note_and_explain_region()`.
190 ty::ReScope(_) => prefix.to_string(),
191 ty::ReEarlyBound(_, _, _, name) => {
192 token::get_name(name).get().to_string()
194 ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
195 ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
196 ty::ReInfer(ReSkolemized(_, br)) => {
197 bound_region_to_str(cx, prefix, space, br)
199 ty::ReInfer(ReVar(_)) => prefix.to_string(),
200 ty::ReStatic => format!("{}'static{}", prefix, space_str),
201 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
205 pub fn mutability_to_str(m: ast::Mutability) -> String {
207 ast::MutMutable => "mut ".to_string(),
208 ast::MutImmutable => "".to_string(),
212 pub fn mt_to_str(cx: &ctxt, m: &mt) -> String {
213 format!("{}{}", mutability_to_str(m.mutbl), ty_to_str(cx, m.ty))
216 pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> String {
218 ty::UniqTraitStore => "Box ".to_string(),
219 ty::RegionTraitStore(r, m) => {
220 format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m))
225 pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> String) -> String {
226 let tstrs = ts.iter().map(f).collect::<Vec<String>>();
227 format!("[{}]", tstrs.connect(", "))
230 pub fn fn_sig_to_str(cx: &ctxt, typ: &ty::FnSig) -> String {
231 format!("fn{}{} -> {}", typ.binder_id, typ.inputs.repr(cx),
235 pub fn trait_ref_to_str(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
236 trait_ref.user_string(cx).to_string()
239 pub fn ty_to_str(cx: &ctxt, typ: t) -> String {
240 fn fn_input_to_str(cx: &ctxt, input: ty::t) -> String {
241 ty_to_str(cx, input).to_string()
243 fn bare_fn_to_str(cx: &ctxt,
244 fn_style: ast::FnStyle,
246 ident: Option<ast::Ident>,
249 let mut s = String::new();
253 s.push_str(fn_style.to_str().as_slice());
258 if abi != abi::Rust {
259 s.push_str(format!("extern {} ", abi.to_str()).as_slice());
267 s.push_str(token::get_ident(i).get());
272 push_sig_to_str(cx, &mut s, '(', ')', sig);
277 fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> String {
278 let mut s = String::new();
281 ty::UniqTraitStore => {}
282 ty::RegionTraitStore(region, _) => {
283 s.push_str(region_to_str(cx, "", true, region).as_slice());
290 s.push_str(cty.fn_style.to_str().as_slice());
296 ty::UniqTraitStore => {
297 assert_eq!(cty.onceness, ast::Once);
299 push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
301 ty::RegionTraitStore(..) => {
304 ast::Once => s.push_str("once ")
306 push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
310 if !cty.bounds.is_empty() {
312 s.push_str(cty.bounds.repr(cx).as_slice());
318 fn push_sig_to_str(cx: &ctxt,
324 let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
325 s.push_str(strs.connect(", ").as_slice());
331 if ty::get(sig.output).sty != ty_nil {
333 if ty::type_is_bot(sig.output) {
336 s.push_str(ty_to_str(cx, sig.output).as_slice());
341 // if there is an id, print that instead of the structural type:
342 /*for def_id in ty::type_def_id(typ).iter() {
343 // note that this typedef cannot have type parameters
344 return ty::item_path_str(cx, *def_id);
347 // pretty print the structural type representation:
348 return match ty::get(typ).sty {
349 ty_nil => "()".to_string(),
350 ty_bot => "!".to_string(),
351 ty_bool => "bool".to_string(),
352 ty_char => "char".to_string(),
353 ty_int(t) => ast_util::int_ty_to_str(t, None,
354 ast_util::AutoSuffix).to_string(),
355 ty_uint(t) => ast_util::uint_ty_to_str(t, None,
356 ast_util::AutoSuffix).to_string(),
357 ty_float(t) => ast_util::float_ty_to_str(t).to_string(),
358 ty_box(typ) => format!("Gc<{}>", ty_to_str(cx, typ)),
359 ty_uniq(typ) => format!("Box<{}>", ty_to_str(cx, typ)),
360 ty_ptr(ref tm) => format!("*{}", mt_to_str(cx, tm)),
361 ty_rptr(r, ref tm) => {
362 let mut buf = region_ptr_to_str(cx, r);
363 buf.push_str(mt_to_str(cx, tm).as_slice());
366 ty_tup(ref elems) => {
367 let strs: Vec<String> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
368 format!("({})", strs.connect(","))
370 ty_closure(ref f) => {
371 closure_to_str(cx, *f)
373 ty_bare_fn(ref f) => {
374 bare_fn_to_str(cx, f.fn_style, f.abi, None, &f.sig)
376 ty_infer(infer_ty) => infer_ty.to_str(),
377 ty_err => "[type error]".to_string(),
378 ty_param(ParamTy {idx: id, def_id: did, ..}) => {
379 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
380 Some(def) => token::get_ident(def.ident).get().to_string(),
381 // This can only happen when a type mismatch error happens and
382 // the actual type has more type parameters than the expected one.
383 None => format!("<generic #{}>", id),
385 if !cx.sess.verbose() {
388 format!("{}:{:?}", ident, did)
391 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
392 let base = ty::item_path_str(cx, did);
393 let generics = ty::lookup_item_type(cx, did).generics;
394 parameterized(cx, base.as_slice(), substs, &generics)
396 ty_trait(box ty::TyTrait {
397 def_id: did, ref substs, ref bounds
399 let base = ty::item_path_str(cx, did);
400 let trait_def = ty::lookup_trait_def(cx, did);
401 let ty = parameterized(cx, base.as_slice(),
402 substs, &trait_def.generics);
403 let bound_sep = if bounds.is_empty() { "" } else { ":" };
404 let bound_str = bounds.repr(cx);
410 ty_str => "str".to_string(),
411 ty_vec(ref mt, sz) => {
414 format!("[{}, .. {}]", mt_to_str(cx, mt), n)
416 None => format!("[{}]", ty_to_str(cx, mt.ty)),
422 pub fn parameterized(cx: &ctxt,
424 substs: &subst::Substs,
425 generics: &ty::Generics)
428 let mut strs = Vec::new();
430 match substs.regions {
431 subst::ErasedRegions => { }
432 subst::NonerasedRegions(ref regions) => {
433 for &r in regions.iter() {
434 let s = region_to_str(cx, "", false, r);
438 // This happens when the value of the region
439 // parameter is not easily serialized. This may be
440 // because the user omitted it in the first place,
441 // or because it refers to some block in the code,
442 // etc. I'm not sure how best to serialize this.
443 strs.push(format!("'_"));
449 let tps = substs.types.get_vec(subst::TypeSpace);
450 let ty_params = generics.types.get_vec(subst::TypeSpace);
451 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
452 let num_defaults = if has_defaults && !cx.sess.verbose() {
453 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
455 Some(default) => default.subst(cx, substs) == actual,
463 for t in tps.slice_to(tps.len() - num_defaults).iter() {
464 strs.push(ty_to_str(cx, *t))
467 if cx.sess.verbose() {
468 for t in substs.types.get_vec(subst::SelfSpace).iter() {
469 strs.push(format!("for {}", t.repr(cx)));
474 format!("{}<{}>", base, strs.connect(","))
480 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String {
481 let mut s = typ.repr(cx).to_string();
483 s = s.as_slice().slice(0u, 32u).to_string();
488 impl<T:Repr> Repr for Option<T> {
489 fn repr(&self, tcx: &ctxt) -> String {
491 &None => "None".to_string(),
492 &Some(ref t) => t.repr(tcx),
497 impl<T:Repr,U:Repr> Repr for Result<T,U> {
498 fn repr(&self, tcx: &ctxt) -> String {
500 &Ok(ref t) => t.repr(tcx),
501 &Err(ref u) => format!("Err({})", u.repr(tcx))
507 fn repr(&self, _tcx: &ctxt) -> String {
512 impl<T:Repr> Repr for Rc<T> {
513 fn repr(&self, tcx: &ctxt) -> String {
518 impl<T:Repr + 'static> Repr for Gc<T> {
519 fn repr(&self, tcx: &ctxt) -> String {
524 impl<T:Repr> Repr for Box<T> {
525 fn repr(&self, tcx: &ctxt) -> String {
530 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> String {
531 vec_map_to_str(v, |t| t.repr(tcx))
534 impl<'a, T:Repr> Repr for &'a [T] {
535 fn repr(&self, tcx: &ctxt) -> String {
540 impl<T:Repr> Repr for OwnedSlice<T> {
541 fn repr(&self, tcx: &ctxt) -> String {
542 repr_vec(tcx, self.as_slice())
546 // This is necessary to handle types like Option<~[T]>, for which
547 // autoderef cannot convert the &[T] handler
548 impl<T:Repr> Repr for Vec<T> {
549 fn repr(&self, tcx: &ctxt) -> String {
550 repr_vec(tcx, self.as_slice())
554 impl Repr for def::Def {
555 fn repr(&self, _tcx: &ctxt) -> String {
556 format!("{:?}", *self)
560 impl Repr for ty::TypeParameterDef {
561 fn repr(&self, tcx: &ctxt) -> String {
562 format!("TypeParameterDef({:?}, {})", self.def_id,
563 self.bounds.repr(tcx))
567 impl Repr for ty::RegionParameterDef {
568 fn repr(&self, _tcx: &ctxt) -> String {
569 format!("RegionParameterDef({}, {:?})",
570 token::get_name(self.name),
575 impl Repr for ty::t {
576 fn repr(&self, tcx: &ctxt) -> String {
577 ty_to_str(tcx, *self)
581 impl Repr for ty::mt {
582 fn repr(&self, tcx: &ctxt) -> String {
587 impl Repr for subst::Substs {
588 fn repr(&self, tcx: &ctxt) -> String {
589 format!("Substs[types={}, regions={}]",
590 self.types.repr(tcx),
591 self.regions.repr(tcx))
595 impl<T:Repr> Repr for subst::VecPerParamSpace<T> {
596 fn repr(&self, tcx: &ctxt) -> String {
597 format!("[{};{};{}]",
598 self.get_vec(subst::TypeSpace).repr(tcx),
599 self.get_vec(subst::SelfSpace).repr(tcx),
600 self.get_vec(subst::FnSpace).repr(tcx))
604 impl Repr for ty::ItemSubsts {
605 fn repr(&self, tcx: &ctxt) -> String {
606 format!("ItemSubsts({})", self.substs.repr(tcx))
610 impl Repr for subst::RegionSubsts {
611 fn repr(&self, tcx: &ctxt) -> String {
613 subst::ErasedRegions => "erased".to_string(),
614 subst::NonerasedRegions(ref regions) => regions.repr(tcx)
619 impl Repr for ty::ParamBounds {
620 fn repr(&self, tcx: &ctxt) -> String {
621 let mut res = Vec::new();
622 for b in self.builtin_bounds.iter() {
624 ty::BoundStatic => "'static".to_string(),
625 ty::BoundSend => "Send".to_string(),
626 ty::BoundSized => "Sized".to_string(),
627 ty::BoundCopy => "Copy".to_string(),
628 ty::BoundShare => "Share".to_string(),
631 for t in self.trait_bounds.iter() {
632 res.push(t.repr(tcx));
634 res.connect("+").to_string()
638 impl Repr for ty::TraitRef {
639 fn repr(&self, tcx: &ctxt) -> String {
640 trait_ref_to_str(tcx, self)
644 impl Repr for ast::Expr {
645 fn repr(&self, _tcx: &ctxt) -> String {
646 format!("expr({}: {})", self.id, pprust::expr_to_str(self))
650 impl Repr for ast::Path {
651 fn repr(&self, _tcx: &ctxt) -> String {
652 format!("path({})", pprust::path_to_str(self))
656 impl Repr for ast::Item {
657 fn repr(&self, tcx: &ctxt) -> String {
658 format!("item({})", tcx.map.node_to_str(self.id))
662 impl Repr for ast::Stmt {
663 fn repr(&self, _tcx: &ctxt) -> String {
664 format!("stmt({}: {})",
665 ast_util::stmt_id(self),
666 pprust::stmt_to_str(self))
670 impl Repr for ast::Pat {
671 fn repr(&self, _tcx: &ctxt) -> String {
672 format!("pat({}: {})", self.id, pprust::pat_to_str(self))
676 impl Repr for ty::BoundRegion {
677 fn repr(&self, tcx: &ctxt) -> String {
679 ty::BrAnon(id) => format!("BrAnon({})", id),
680 ty::BrNamed(id, name) => {
681 format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
683 ty::BrFresh(id) => format!("BrFresh({})", id),
688 impl Repr for ty::Region {
689 fn repr(&self, tcx: &ctxt) -> String {
691 ty::ReEarlyBound(id, space, index, name) => {
692 format!("ReEarlyBound({}, {}, {}, {})",
696 token::get_name(name))
699 ty::ReLateBound(binder_id, ref bound_region) => {
700 format!("ReLateBound({}, {})",
702 bound_region.repr(tcx))
705 ty::ReFree(ref fr) => {
706 format!("ReFree({}, {})",
708 fr.bound_region.repr(tcx))
712 format!("ReScope({})", id)
716 "ReStatic".to_string()
719 ty::ReInfer(ReVar(ref vid)) => {
720 format!("ReInfer({})", vid.index)
723 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
724 format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
728 "ReEmpty".to_string()
734 impl Repr for ast::DefId {
735 fn repr(&self, tcx: &ctxt) -> String {
736 // Unfortunately, there seems to be no way to attempt to print
737 // a path for a def-id, so I'll just make a best effort for now
738 // and otherwise fallback to just printing the crate/node pair
739 if self.krate == ast::LOCAL_CRATE {
741 match tcx.map.find(self.node) {
742 Some(ast_map::NodeItem(..)) |
743 Some(ast_map::NodeForeignItem(..)) |
744 Some(ast_map::NodeMethod(..)) |
745 Some(ast_map::NodeTraitMethod(..)) |
746 Some(ast_map::NodeVariant(..)) |
747 Some(ast_map::NodeStructCtor(..)) => {
751 ty::item_path_str(tcx, *self))
757 return format!("{:?}", *self)
761 impl Repr for ty::Polytype {
762 fn repr(&self, tcx: &ctxt) -> String {
763 format!("Polytype {{generics: {}, ty: {}}}",
764 self.generics.repr(tcx),
769 impl Repr for ty::Generics {
770 fn repr(&self, tcx: &ctxt) -> String {
771 format!("Generics(types: {}, regions: {})",
772 self.types.repr(tcx),
773 self.regions.repr(tcx))
777 impl Repr for ty::ItemVariances {
778 fn repr(&self, tcx: &ctxt) -> String {
779 format!("ItemVariances(types={}, \
781 self.types.repr(tcx),
782 self.regions.repr(tcx))
786 impl Repr for ty::Variance {
787 fn repr(&self, _: &ctxt) -> String {
788 // The first `.to_str()` returns a &'static str (it is not an implementation
789 // of the ToStr trait). Because of that, we need to call `.to_str()` again
790 // if we want to have a `String`.
791 self.to_str().to_str()
795 impl Repr for ty::Method {
796 fn repr(&self, tcx: &ctxt) -> String {
797 format!("method(ident: {}, generics: {}, fty: {}, \
798 explicit_self: {}, vis: {}, def_id: {})",
799 self.ident.repr(tcx),
800 self.generics.repr(tcx),
802 self.explicit_self.repr(tcx),
804 self.def_id.repr(tcx))
808 impl Repr for ast::Name {
809 fn repr(&self, _tcx: &ctxt) -> String {
810 token::get_name(*self).get().to_string()
814 impl Repr for ast::Ident {
815 fn repr(&self, _tcx: &ctxt) -> String {
816 token::get_ident(*self).get().to_string()
820 impl Repr for ast::ExplicitSelf_ {
821 fn repr(&self, _tcx: &ctxt) -> String {
822 format!("{:?}", *self)
826 impl Repr for ast::Visibility {
827 fn repr(&self, _tcx: &ctxt) -> String {
828 format!("{:?}", *self)
832 impl Repr for ty::BareFnTy {
833 fn repr(&self, tcx: &ctxt) -> String {
834 format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
841 impl Repr for ty::FnSig {
842 fn repr(&self, tcx: &ctxt) -> String {
843 fn_sig_to_str(tcx, self)
847 impl Repr for typeck::MethodCallee {
848 fn repr(&self, tcx: &ctxt) -> String {
849 format!("MethodCallee {{origin: {}, ty: {}, {}}}",
850 self.origin.repr(tcx),
852 self.substs.repr(tcx))
856 impl Repr for typeck::MethodOrigin {
857 fn repr(&self, tcx: &ctxt) -> String {
859 &typeck::MethodStatic(def_id) => {
860 format!("MethodStatic({})", def_id.repr(tcx))
862 &typeck::MethodParam(ref p) => {
865 &typeck::MethodObject(ref p) => {
872 impl Repr for typeck::MethodParam {
873 fn repr(&self, tcx: &ctxt) -> String {
874 format!("MethodParam({},{:?},{:?},{:?})",
875 self.trait_id.repr(tcx),
882 impl Repr for typeck::MethodObject {
883 fn repr(&self, tcx: &ctxt) -> String {
884 format!("MethodObject({},{:?},{:?})",
885 self.trait_id.repr(tcx),
891 impl Repr for ty::TraitStore {
892 fn repr(&self, tcx: &ctxt) -> String {
893 trait_store_to_str(tcx, *self)
897 impl Repr for ty::BuiltinBound {
898 fn repr(&self, _tcx: &ctxt) -> String {
899 format!("{:?}", *self)
903 impl UserString for ty::BuiltinBound {
904 fn user_string(&self, _tcx: &ctxt) -> String {
906 ty::BoundStatic => "'static".to_string(),
907 ty::BoundSend => "Send".to_string(),
908 ty::BoundSized => "Sized".to_string(),
909 ty::BoundCopy => "Copy".to_string(),
910 ty::BoundShare => "Share".to_string(),
915 impl Repr for ty::BuiltinBounds {
916 fn repr(&self, tcx: &ctxt) -> String {
917 self.user_string(tcx)
922 fn repr(&self, tcx: &ctxt) -> String {
923 tcx.sess.codemap().span_to_str(*self).to_string()
927 impl<A:UserString> UserString for Rc<A> {
928 fn user_string(&self, tcx: &ctxt) -> String {
929 let this: &A = &**self;
930 this.user_string(tcx)
934 impl UserString for ty::BuiltinBounds {
935 fn user_string(&self, tcx: &ctxt) -> String {
937 .map(|bb| bb.user_string(tcx))
938 .collect::<Vec<String>>()
944 impl UserString for ty::TraitRef {
945 fn user_string(&self, tcx: &ctxt) -> String {
946 let base = ty::item_path_str(tcx, self.def_id);
947 let trait_def = ty::lookup_trait_def(tcx, self.def_id);
948 parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
952 impl UserString for ty::t {
953 fn user_string(&self, tcx: &ctxt) -> String {
954 ty_to_str(tcx, *self)
958 impl UserString for ast::Ident {
959 fn user_string(&self, _tcx: &ctxt) -> String {
960 token::get_name(self.name).get().to_string()
964 impl Repr for abi::Abi {
965 fn repr(&self, _tcx: &ctxt) -> String {
970 impl UserString for abi::Abi {
971 fn user_string(&self, _tcx: &ctxt) -> String {
976 impl Repr for ty::UpvarId {
977 fn repr(&self, tcx: &ctxt) -> String {
978 format!("UpvarId({};`{}`;{})",
980 ty::local_var_name_str(tcx, self.var_id),
981 self.closure_expr_id)
985 impl Repr for ast::Mutability {
986 fn repr(&self, _tcx: &ctxt) -> String {
987 format!("{:?}", *self)
991 impl Repr for ty::BorrowKind {
992 fn repr(&self, _tcx: &ctxt) -> String {
993 format!("{:?}", *self)
997 impl Repr for ty::UpvarBorrow {
998 fn repr(&self, tcx: &ctxt) -> String {
999 format!("UpvarBorrow({}, {})",
1000 self.kind.repr(tcx),
1001 self.region.repr(tcx))
1005 impl Repr for ty::IntVid {
1006 fn repr(&self, _tcx: &ctxt) -> String {
1011 impl Repr for ty::FloatVid {
1012 fn repr(&self, _tcx: &ctxt) -> String {
1017 impl Repr for ty::RegionVid {
1018 fn repr(&self, _tcx: &ctxt) -> String {
1023 impl Repr for ty::TyVid {
1024 fn repr(&self, _tcx: &ctxt) -> String {
1029 impl Repr for ty::IntVarValue {
1030 fn repr(&self, _tcx: &ctxt) -> String {
1031 format!("{:?}", *self)
1035 impl Repr for ast::IntTy {
1036 fn repr(&self, _tcx: &ctxt) -> String {
1037 format!("{:?}", *self)
1041 impl Repr for ast::UintTy {
1042 fn repr(&self, _tcx: &ctxt) -> String {
1043 format!("{:?}", *self)
1047 impl Repr for ast::FloatTy {
1048 fn repr(&self, _tcx: &ctxt) -> String {
1049 format!("{:?}", *self)
1053 impl<T:Repr> Repr for infer::Bounds<T> {
1054 fn repr(&self, tcx: &ctxt) -> String {
1055 format!("({} <= {})",
1061 impl<K:Repr,V:Repr> Repr for VV<K,V> {
1062 fn repr(&self, tcx: &ctxt) -> String {
1064 unify::Redirect(ref k) =>
1065 format!("Redirect({})", k.repr(tcx)),
1066 unify::Root(ref v, r) =>
1067 format!("Root({}, {})", v.repr(tcx), r)
1072 impl Repr for region_inference::VarValue {
1073 fn repr(&self, tcx: &ctxt) -> String {
1075 infer::region_inference::NoValue =>
1077 infer::region_inference::Value(r) =>
1078 format!("Value({})", r.repr(tcx)),
1079 infer::region_inference::ErrorValue =>
1080 format!("ErrorValue"),