1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use metadata::encoder;
13 use middle::ty::{ReSkolemized, ReVar};
14 use middle::ty::{BoundRegion, BrAnon, BrNamed};
15 use middle::ty::{BrFresh, ctxt};
16 use middle::ty::{mt, t, param_ty};
17 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region,
19 use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
20 use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
21 use middle::ty::{ty_nil, ty_param, ty_ptr, ty_rptr, ty_self, ty_tup};
22 use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
26 use std::strbuf::StrBuf;
29 use syntax::codemap::{Span, Pos};
30 use syntax::parse::token;
31 use syntax::print::pprust;
32 use syntax::{ast, ast_util};
33 use syntax::owned_slice::OwnedSlice;
35 /// Produces a string suitable for debugging output.
37 fn repr(&self, tcx: &ctxt) -> ~str;
40 /// Produces a string suitable for showing to the user.
41 pub trait UserString {
42 fn user_string(&self, tcx: &ctxt) -> ~str;
45 pub fn note_and_explain_region(cx: &ctxt,
49 match explain_region_and_span(cx, region) {
50 (ref str, Some(span)) => {
53 format!("{}{}{}", prefix, *str, suffix));
57 format!("{}{}{}", prefix, *str, suffix));
62 pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
63 -> (~str, Option<Span>) {
66 match cx.map.find(node_id) {
67 Some(ast_map::NodeBlock(ref blk)) => {
68 explain_span(cx, "block", blk.span)
70 Some(ast_map::NodeExpr(expr)) => {
72 ast::ExprCall(..) => explain_span(cx, "call", expr.span),
73 ast::ExprMethodCall(..) => {
74 explain_span(cx, "method call", expr.span)
76 ast::ExprMatch(..) => explain_span(cx, "match", expr.span),
77 _ => explain_span(cx, "expression", expr.span)
80 Some(ast_map::NodeStmt(stmt)) => {
81 explain_span(cx, "statement", stmt.span)
83 Some(ast_map::NodeItem(it)) if (match it.node {
84 ast::ItemFn(..) => true, _ => false}) => {
85 explain_span(cx, "function body", it.span)
88 // this really should not happen
89 (format!("unknown scope: {}. Please report a bug.", node_id),
96 let prefix = match fr.bound_region {
97 BrAnon(idx) => format!("the anonymous lifetime \\#{} defined on",
99 BrFresh(_) => format!("an anonymous lifetime defined on"),
100 _ => format!("the lifetime {} as defined on",
101 bound_region_ptr_to_str(cx, fr.bound_region))
104 match cx.map.find(fr.scope_id) {
105 Some(ast_map::NodeBlock(ref blk)) => {
106 let (msg, opt_span) = explain_span(cx, "block", blk.span);
107 (format!("{} {}", prefix, msg), opt_span)
109 Some(ast_map::NodeItem(it)) if match it.node {
110 ast::ItemImpl(..) => true, _ => false} => {
111 let (msg, opt_span) = explain_span(cx, "impl", it.span);
112 (format!("{} {}", prefix, msg), opt_span)
115 // this really should not happen
116 (format!("{} node {}", prefix, fr.scope_id), None)
121 ReStatic => { (~"the static lifetime", None) }
123 ReEmpty => { (~"the empty lifetime", None) }
125 // I believe these cases should not occur (except when debugging,
127 ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
128 (format!("lifetime {:?}", region), None)
132 fn explain_span(cx: &ctxt, heading: &str, span: Span)
133 -> (~str, Option<Span>) {
134 let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
135 (format!("the {} at {}:{}", heading,
136 lo.line, lo.col.to_uint()), Some(span))
140 pub fn bound_region_ptr_to_str(cx: &ctxt, br: BoundRegion) -> ~str {
141 bound_region_to_str(cx, "&", true, br)
144 pub fn bound_region_to_str(cx: &ctxt,
145 prefix: &str, space: bool,
146 br: BoundRegion) -> ~str {
147 let space_str = if space { " " } else { "" };
149 if cx.sess.verbose() {
150 return format!("{}{}{}", prefix, br.repr(cx), space_str);
154 BrNamed(_, name) => format!("{}'{}{}", prefix,
155 token::get_name(name), space_str),
156 BrAnon(_) => prefix.to_str(),
157 BrFresh(_) => prefix.to_str(),
161 // In general, if you are giving a region error message,
162 // you should use `explain_region()` or, better yet,
163 // `note_and_explain_region()`
164 pub fn region_ptr_to_str(cx: &ctxt, region: Region) -> ~str {
165 region_to_str(cx, "&", true, region)
168 pub fn region_to_str(cx: &ctxt, prefix: &str, space: bool, region: Region) -> ~str {
169 let space_str = if space { " " } else { "" };
171 if cx.sess.verbose() {
172 return format!("{}{}{}", prefix, region.repr(cx), space_str);
175 // These printouts are concise. They do not contain all the information
176 // the user might want to diagnose an error, but there is basically no way
177 // to fit that into a short string. Hence the recommendation to use
178 // `explain_region()` or `note_and_explain_region()`.
180 ty::ReScope(_) => prefix.to_str(),
181 ty::ReEarlyBound(_, _, name) => token::get_name(name).get().to_str(),
182 ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
183 ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
184 ty::ReInfer(ReSkolemized(_, br)) => {
185 bound_region_to_str(cx, prefix, space, br)
187 ty::ReInfer(ReVar(_)) => prefix.to_str(),
188 ty::ReStatic => format!("{}'static{}", prefix, space_str),
189 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str)
193 pub fn mutability_to_str(m: ast::Mutability) -> ~str {
195 ast::MutMutable => ~"mut ",
196 ast::MutImmutable => ~"",
200 pub fn mt_to_str(cx: &ctxt, m: &mt) -> ~str {
201 mt_to_str_wrapped(cx, "", m, "")
204 pub fn mt_to_str_wrapped(cx: &ctxt, before: &str, m: &mt, after: &str) -> ~str {
205 let mstr = mutability_to_str(m.mutbl);
206 return format!("{}{}{}{}", mstr, before, ty_to_str(cx, m.ty), after);
209 pub fn vstore_to_str(cx: &ctxt, vs: ty::vstore) -> ~str {
211 ty::vstore_fixed(n) => format!("{}", n),
212 ty::vstore_uniq => ~"~",
213 ty::vstore_slice(r) => region_ptr_to_str(cx, r)
217 pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> ~str {
219 ty::UniqTraitStore => ~"~",
220 ty::RegionTraitStore(r) => region_ptr_to_str(cx, r)
224 pub fn vstore_ty_to_str(cx: &ctxt, mt: &mt, vs: ty::vstore) -> ~str {
226 ty::vstore_fixed(_) => {
227 format!("[{}, .. {}]", mt_to_str(cx, mt), vstore_to_str(cx, vs))
230 format!("{}{}", vstore_to_str(cx, vs), mt_to_str_wrapped(cx, "[", mt, "]"))
235 pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> ~str) -> ~str {
236 let tstrs = ts.iter().map(f).collect::<Vec<~str>>();
237 format!("[{}]", tstrs.connect(", "))
240 pub fn fn_sig_to_str(cx: &ctxt, typ: &ty::FnSig) -> ~str {
241 format!("fn{}{} -> {}",
247 pub fn trait_ref_to_str(cx: &ctxt, trait_ref: &ty::TraitRef) -> ~str {
248 trait_ref.user_string(cx)
251 pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
252 fn fn_input_to_str(cx: &ctxt, input: ty::t) -> ~str {
255 fn bare_fn_to_str(cx: &ctxt,
258 ident: Option<ast::Ident>,
261 let mut s = if abi == abi::Rust {
264 StrBuf::from_owned_str(format!("extern {} ", abi.to_str()))
270 s.push_str(purity.to_str());
280 s.push_str(token::get_ident(i).get());
285 push_sig_to_str(cx, &mut s, '(', ')', sig);
290 fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> ~str {
292 (cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
293 let is_borrowed_closure = cty.sigil == ast::BorrowedSigil;
295 let mut s = if is_proc || is_borrowed_closure {
298 StrBuf::from_owned_str(cty.sigil.to_str())
301 match (cty.sigil, cty.region) {
302 (ast::ManagedSigil, ty::ReStatic) |
303 (ast::OwnedSigil, ty::ReStatic) => {}
306 s.push_str(region_to_str(cx, "", true, region));
313 s.push_str(cty.purity.to_str());
324 s.push_str(cty.onceness.to_str());
329 if !is_borrowed_closure {
334 if !is_borrowed_closure {
335 // Print bounds before `fn` if this is not a borrowed closure.
336 if !cty.bounds.is_empty() {
338 s.push_str(cty.bounds.repr(cx));
341 push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
343 // Print bounds after the signature if this is a borrowed closure.
344 push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
346 if is_borrowed_closure {
347 if !cty.bounds.is_empty() {
349 s.push_str(cty.bounds.repr(cx));
357 fn push_sig_to_str(cx: &ctxt,
363 let strs: Vec<~str> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
364 s.push_str(strs.connect(", "));
370 if ty::get(sig.output).sty != ty_nil {
372 if ty::type_is_bot(sig.output) {
375 s.push_str(ty_to_str(cx, sig.output));
380 // if there is an id, print that instead of the structural type:
381 /*for def_id in ty::type_def_id(typ).iter() {
382 // note that this typedef cannot have type parameters
383 return ty::item_path_str(cx, *def_id);
386 // pretty print the structural type representation:
387 return match ty::get(typ).sty {
392 ty_int(ast::TyI) => ~"int",
393 ty_int(t) => ast_util::int_ty_to_str(t),
394 ty_uint(ast::TyU) => ~"uint",
395 ty_uint(t) => ast_util::uint_ty_to_str(t),
396 ty_float(t) => ast_util::float_ty_to_str(t),
397 ty_box(typ) => ~"@" + ty_to_str(cx, typ),
398 ty_uniq(typ) => ~"~" + ty_to_str(cx, typ),
399 ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
400 ty_rptr(r, ref tm) => {
401 region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
403 ty_tup(ref elems) => {
404 let strs: Vec<~str> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
405 ~"(" + strs.connect(",") + ")"
407 ty_closure(ref f) => {
408 closure_to_str(cx, *f)
410 ty_bare_fn(ref f) => {
411 bare_fn_to_str(cx, f.purity, f.abi, None, &f.sig)
413 ty_infer(infer_ty) => infer_ty.to_str(),
414 ty_err => ~"[type error]",
415 ty_param(param_ty {idx: id, def_id: did}) => {
416 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
417 Some(def) => token::get_ident(def.ident).get().to_str(),
418 // This should not happen...
419 None => format!("BUG[{:?}]", id)
421 if !cx.sess.verbose() {
424 format!("{}:{:?}", ident, did)
427 ty_self(..) => ~"Self",
428 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
429 let base = ty::item_path_str(cx, did);
433 substs.tps.as_slice(),
437 ty_trait(~ty::TyTrait {
438 def_id: did, ref substs, store: s, mutability: mutbl, ref bounds
440 let base = ty::item_path_str(cx, did);
441 let ty = parameterized(cx, base, &substs.regions,
442 substs.tps.as_slice(), did, true);
443 let bound_sep = if bounds.is_empty() { "" } else { ":" };
444 let bound_str = bounds.repr(cx);
445 format!("{}{}{}{}{}", trait_store_to_str(cx, s), mutability_to_str(mutbl), ty,
446 bound_sep, bound_str)
448 ty_vec(ref mt, vs) => {
449 vstore_ty_to_str(cx, mt, vs)
451 ty_str(vs) => format!("{}{}", vstore_to_str(cx, vs), "str")
455 pub fn parameterized(cx: &ctxt,
457 regions: &ty::RegionSubsts,
460 is_trait: bool) -> ~str {
462 let mut strs = Vec::new();
464 ty::ErasedRegions => { }
465 ty::NonerasedRegions(ref regions) => {
466 for &r in regions.iter() {
467 strs.push(region_to_str(cx, "", false, r))
472 let generics = if is_trait {
473 ty::lookup_trait_def(cx, did).generics.clone()
475 ty::lookup_item_type(cx, did).generics
477 let ty_params = generics.type_param_defs();
478 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
479 let num_defaults = if has_defaults {
480 // We should have a borrowed version of substs instead of cloning.
481 let mut substs = ty::substs {
482 tps: Vec::from_slice(tps),
483 regions: regions.clone(),
486 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
489 Some(default) => ty::subst(cx, &substs, default) == actual,
497 for t in tps.slice_to(tps.len() - num_defaults).iter() {
498 strs.push(ty_to_str(cx, *t))
502 format!("{}<{}>", base, strs.connect(","))
508 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> ~str {
509 let mut s = encoder::encoded_ty(cx, typ);
510 if s.len() >= 32u { s = s.slice(0u, 32u).to_owned(); }
514 impl<T:Repr> Repr for Option<T> {
515 fn repr(&self, tcx: &ctxt) -> ~str {
518 &Some(ref t) => t.repr(tcx),
523 impl<T:Repr,U:Repr> Repr for Result<T,U> {
524 fn repr(&self, tcx: &ctxt) -> ~str {
526 &Ok(ref t) => t.repr(tcx),
527 &Err(ref u) => format!("Err({})", u.repr(tcx))
533 fn repr(&self, _tcx: &ctxt) -> ~str {
538 impl<T:Repr> Repr for @T {
539 fn repr(&self, tcx: &ctxt) -> ~str {
544 impl<T:Repr> Repr for ~T {
545 fn repr(&self, tcx: &ctxt) -> ~str {
550 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> ~str {
551 vec_map_to_str(v, |t| t.repr(tcx))
554 impl<'a, T:Repr> Repr for &'a [T] {
555 fn repr(&self, tcx: &ctxt) -> ~str {
560 impl<T:Repr> Repr for OwnedSlice<T> {
561 fn repr(&self, tcx: &ctxt) -> ~str {
562 repr_vec(tcx, self.as_slice())
566 // This is necessary to handle types like Option<~[T]>, for which
567 // autoderef cannot convert the &[T] handler
568 impl<T:Repr> Repr for Vec<T> {
569 fn repr(&self, tcx: &ctxt) -> ~str {
570 repr_vec(tcx, self.as_slice())
574 impl Repr for ty::TypeParameterDef {
575 fn repr(&self, tcx: &ctxt) -> ~str {
576 format!("TypeParameterDef({:?}, {})",
578 self.bounds.repr(tcx))
582 impl Repr for ty::RegionParameterDef {
583 fn repr(&self, _tcx: &ctxt) -> ~str {
584 format!("RegionParameterDef({}, {:?})",
585 token::get_name(self.name),
590 impl Repr for ty::t {
591 fn repr(&self, tcx: &ctxt) -> ~str {
592 ty_to_str(tcx, *self)
596 impl Repr for ty::substs {
597 fn repr(&self, tcx: &ctxt) -> ~str {
598 format!("substs(regions={}, self_ty={}, tps={})",
599 self.regions.repr(tcx),
600 self.self_ty.repr(tcx),
605 impl Repr for ty::RegionSubsts {
606 fn repr(&self, tcx: &ctxt) -> ~str {
608 ty::ErasedRegions => ~"erased",
609 ty::NonerasedRegions(ref regions) => regions.repr(tcx)
614 impl Repr for ty::ParamBounds {
615 fn repr(&self, tcx: &ctxt) -> ~str {
616 let mut res = Vec::new();
617 for b in self.builtin_bounds.iter() {
619 ty::BoundStatic => ~"'static",
620 ty::BoundSend => ~"Send",
621 ty::BoundSized => ~"Sized",
622 ty::BoundCopy => ~"Pod",
623 ty::BoundShare => ~"Share",
626 for t in self.trait_bounds.iter() {
627 res.push(t.repr(tcx));
633 impl Repr for ty::TraitRef {
634 fn repr(&self, tcx: &ctxt) -> ~str {
635 trait_ref_to_str(tcx, self)
639 impl Repr for ast::Expr {
640 fn repr(&self, _tcx: &ctxt) -> ~str {
641 format!("expr({}: {})", self.id, pprust::expr_to_str(self))
645 impl Repr for ast::Item {
646 fn repr(&self, tcx: &ctxt) -> ~str {
647 format!("item({})", tcx.map.node_to_str(self.id))
651 impl Repr for ast::Stmt {
652 fn repr(&self, _tcx: &ctxt) -> ~str {
653 format!("stmt({}: {})",
654 ast_util::stmt_id(self),
655 pprust::stmt_to_str(self))
659 impl Repr for ast::Pat {
660 fn repr(&self, _tcx: &ctxt) -> ~str {
661 format!("pat({}: {})",
663 pprust::pat_to_str(self))
667 impl Repr for ty::BoundRegion {
668 fn repr(&self, tcx: &ctxt) -> ~str {
670 ty::BrAnon(id) => format!("BrAnon({})", id),
671 ty::BrNamed(id, name) => format!("BrNamed({}, {})",
673 token::get_name(name)),
674 ty::BrFresh(id) => format!("BrFresh({})", id),
679 impl Repr for ty::Region {
680 fn repr(&self, tcx: &ctxt) -> ~str {
682 ty::ReEarlyBound(id, index, name) => {
683 format!("ReEarlyBound({}, {}, {})",
684 id, index, token::get_name(name))
687 ty::ReLateBound(binder_id, ref bound_region) => {
688 format!("ReLateBound({}, {})",
689 binder_id, bound_region.repr(tcx))
692 ty::ReFree(ref fr) => {
693 format!("ReFree({}, {})",
695 fr.bound_region.repr(tcx))
699 format!("ReScope({})", id)
706 ty::ReInfer(ReVar(ref vid)) => {
707 format!("ReInfer({})", vid.id)
710 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
711 format!("re_skolemized({}, {})",
712 id, bound_region.repr(tcx))
722 impl Repr for ast::DefId {
723 fn repr(&self, tcx: &ctxt) -> ~str {
724 // Unfortunately, there seems to be no way to attempt to print
725 // a path for a def-id, so I'll just make a best effort for now
726 // and otherwise fallback to just printing the crate/node pair
727 if self.krate == ast::LOCAL_CRATE {
729 match tcx.map.find(self.node) {
730 Some(ast_map::NodeItem(..)) |
731 Some(ast_map::NodeForeignItem(..)) |
732 Some(ast_map::NodeMethod(..)) |
733 Some(ast_map::NodeTraitMethod(..)) |
734 Some(ast_map::NodeVariant(..)) |
735 Some(ast_map::NodeStructCtor(..)) => {
736 return format!("{:?}:{}",
738 ty::item_path_str(tcx, *self));
744 return format!("{:?}", *self);
748 impl Repr for ty::ty_param_bounds_and_ty {
749 fn repr(&self, tcx: &ctxt) -> ~str {
750 format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
751 self.generics.repr(tcx),
756 impl Repr for ty::Generics {
757 fn repr(&self, tcx: &ctxt) -> ~str {
758 format!("Generics(type_param_defs: {}, region_param_defs: {})",
759 self.type_param_defs().repr(tcx),
760 self.region_param_defs().repr(tcx))
764 impl Repr for ty::ItemVariances {
765 fn repr(&self, tcx: &ctxt) -> ~str {
766 format!("IterVariances(self_param={}, type_params={}, region_params={})",
767 self.self_param.repr(tcx),
768 self.type_params.repr(tcx),
769 self.region_params.repr(tcx))
773 impl Repr for ty::Variance {
774 fn repr(&self, _: &ctxt) -> ~str {
775 self.to_str().to_owned()
779 impl Repr for ty::Method {
780 fn repr(&self, tcx: &ctxt) -> ~str {
781 format!("method(ident: {}, generics: {}, fty: {}, \
782 explicit_self: {}, vis: {}, def_id: {})",
783 self.ident.repr(tcx),
784 self.generics.repr(tcx),
786 self.explicit_self.repr(tcx),
788 self.def_id.repr(tcx))
792 impl Repr for ast::Name {
793 fn repr(&self, _tcx: &ctxt) -> ~str {
794 token::get_name(*self).get().to_str()
798 impl Repr for ast::Ident {
799 fn repr(&self, _tcx: &ctxt) -> ~str {
800 token::get_ident(*self).get().to_str()
804 impl Repr for ast::ExplicitSelf_ {
805 fn repr(&self, _tcx: &ctxt) -> ~str {
806 format!("{:?}", *self)
810 impl Repr for ast::Visibility {
811 fn repr(&self, _tcx: &ctxt) -> ~str {
812 format!("{:?}", *self)
816 impl Repr for ty::BareFnTy {
817 fn repr(&self, tcx: &ctxt) -> ~str {
818 format!("BareFnTy \\{purity: {:?}, abi: {}, sig: {}\\}",
825 impl Repr for ty::FnSig {
826 fn repr(&self, tcx: &ctxt) -> ~str {
827 fn_sig_to_str(tcx, self)
831 impl Repr for typeck::MethodCallee {
832 fn repr(&self, tcx: &ctxt) -> ~str {
833 format!("MethodCallee \\{origin: {}, ty: {}, {}\\}",
834 self.origin.repr(tcx),
836 self.substs.repr(tcx))
840 impl Repr for typeck::MethodOrigin {
841 fn repr(&self, tcx: &ctxt) -> ~str {
843 &typeck::MethodStatic(def_id) => {
844 format!("MethodStatic({})", def_id.repr(tcx))
846 &typeck::MethodParam(ref p) => {
849 &typeck::MethodObject(ref p) => {
856 impl Repr for typeck::MethodParam {
857 fn repr(&self, tcx: &ctxt) -> ~str {
858 format!("MethodParam({},{:?},{:?},{:?})",
859 self.trait_id.repr(tcx),
866 impl Repr for typeck::MethodObject {
867 fn repr(&self, tcx: &ctxt) -> ~str {
868 format!("MethodObject({},{:?},{:?})",
869 self.trait_id.repr(tcx),
876 impl Repr for ty::RegionVid {
877 fn repr(&self, _tcx: &ctxt) -> ~str {
878 format!("{:?}", *self)
882 impl Repr for ty::TraitStore {
883 fn repr(&self, tcx: &ctxt) -> ~str {
885 &ty::UniqTraitStore => ~"~Trait",
886 &ty::RegionTraitStore(r) => format!("&{} Trait", r.repr(tcx))
891 impl Repr for ty::vstore {
892 fn repr(&self, tcx: &ctxt) -> ~str {
893 vstore_to_str(tcx, *self)
897 impl Repr for ty::BuiltinBound {
898 fn repr(&self, _tcx: &ctxt) -> ~str {
899 format!("{:?}", *self)
903 impl UserString for ty::BuiltinBound {
904 fn user_string(&self, _tcx: &ctxt) -> ~str {
906 ty::BoundStatic => ~"'static",
907 ty::BoundSend => ~"Send",
908 ty::BoundSized => ~"Sized",
909 ty::BoundCopy => ~"Pod",
910 ty::BoundShare => ~"Share",
915 impl Repr for ty::BuiltinBounds {
916 fn repr(&self, tcx: &ctxt) -> ~str {
917 self.user_string(tcx)
922 fn repr(&self, tcx: &ctxt) -> ~str {
923 tcx.sess.codemap().span_to_str(*self)
927 impl<A:UserString> UserString for @A {
928 fn user_string(&self, tcx: &ctxt) -> ~str {
929 let this: &A = &**self;
930 this.user_string(tcx)
934 impl UserString for ty::BuiltinBounds {
935 fn user_string(&self, tcx: &ctxt) -> ~str {
936 if self.is_empty() { ~"<no-bounds>" } else {
937 let mut result = Vec::new();
938 for bb in self.iter() {
939 result.push(bb.user_string(tcx));
946 impl UserString for ty::TraitRef {
947 fn user_string(&self, tcx: &ctxt) -> ~str {
948 let base = ty::item_path_str(tcx, self.def_id);
949 if tcx.sess.verbose() && self.substs.self_ty.is_some() {
950 let mut all_tps = self.substs.tps.clone();
951 for &t in self.substs.self_ty.iter() { all_tps.push(t); }
952 parameterized(tcx, base, &self.substs.regions,
953 all_tps.as_slice(), self.def_id, true)
955 parameterized(tcx, base, &self.substs.regions,
956 self.substs.tps.as_slice(), self.def_id, true)
961 impl UserString for ty::t {
962 fn user_string(&self, tcx: &ctxt) -> ~str {
963 ty_to_str(tcx, *self)
967 impl UserString for ast::Ident {
968 fn user_string(&self, _tcx: &ctxt) -> ~str {
969 token::get_name(self.name).get().to_owned()
973 impl Repr for abi::Abi {
974 fn repr(&self, _tcx: &ctxt) -> ~str {
979 impl UserString for abi::Abi {
980 fn user_string(&self, _tcx: &ctxt) -> ~str {
985 impl Repr for ty::UpvarId {
986 fn repr(&self, tcx: &ctxt) -> ~str {
987 format!("UpvarId({};`{}`;{})",
989 ty::local_var_name_str(tcx, self.var_id),
990 self.closure_expr_id)
994 impl Repr for ast::Mutability {
995 fn repr(&self, _tcx: &ctxt) -> ~str {
996 format!("{:?}", *self)
1000 impl Repr for ty::BorrowKind {
1001 fn repr(&self, _tcx: &ctxt) -> ~str {
1002 format!("{:?}", *self)
1006 impl Repr for ty::UpvarBorrow {
1007 fn repr(&self, tcx: &ctxt) -> ~str {
1008 format!("UpvarBorrow({}, {})",
1009 self.kind.repr(tcx),
1010 self.region.repr(tcx))