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 middle::ty::{ReSkolemized, ReVar};
13 use middle::ty::{BoundRegion, BrAnon, BrNamed};
14 use middle::ty::{BrFresh, ctxt};
15 use middle::ty::{mt, t, param_ty};
16 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region,
18 use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
19 use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
20 use middle::ty::{ty_nil, ty_param, ty_ptr, ty_rptr, ty_self, ty_tup};
21 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".to_owned(), None) }
123 ReEmpty => { ("the empty lifetime".to_owned(), 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 ".to_owned(),
196 ast::MutImmutable => "".to_owned(),
200 pub fn mt_to_str(cx: &ctxt, m: &mt) -> ~str {
201 format!("{}{}", mutability_to_str(m.mutbl), ty_to_str(cx, m.ty))
204 pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> ~str {
206 ty::UniqTraitStore => "Box ".to_owned(),
207 ty::RegionTraitStore(r, m) => {
208 format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m))
213 pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> ~str) -> ~str {
214 let tstrs = ts.iter().map(f).collect::<Vec<~str>>();
215 format!("[{}]", tstrs.connect(", "))
218 pub fn fn_sig_to_str(cx: &ctxt, typ: &ty::FnSig) -> ~str {
219 format!("fn{}{} -> {}",
225 pub fn trait_ref_to_str(cx: &ctxt, trait_ref: &ty::TraitRef) -> ~str {
226 trait_ref.user_string(cx)
229 pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
230 fn fn_input_to_str(cx: &ctxt, input: ty::t) -> ~str {
233 fn bare_fn_to_str(cx: &ctxt,
234 fn_style: ast::FnStyle,
236 ident: Option<ast::Ident>,
239 let mut s = if abi == abi::Rust {
242 StrBuf::from_owned_str(format!("extern {} ", abi.to_str()))
248 s.push_str(fn_style.to_str());
258 s.push_str(token::get_ident(i).get());
263 push_sig_to_str(cx, &mut s, '(', ')', sig);
268 fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> ~str {
269 let mut s = StrBuf::new();
272 ty::UniqTraitStore => {}
273 ty::RegionTraitStore(region, _) => {
274 s.push_str(region_to_str(cx, "", true, region));
281 s.push_str(cty.fn_style.to_str());
287 ty::UniqTraitStore => {
288 assert_eq!(cty.onceness, ast::Once);
290 push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
292 ty::RegionTraitStore(..) => {
295 ast::Once => s.push_str("once ")
297 push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
301 if !cty.bounds.is_empty() {
303 s.push_str(cty.bounds.repr(cx));
309 fn push_sig_to_str(cx: &ctxt,
315 let strs: Vec<~str> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
316 s.push_str(strs.connect(", "));
322 if ty::get(sig.output).sty != ty_nil {
324 if ty::type_is_bot(sig.output) {
327 s.push_str(ty_to_str(cx, sig.output));
332 // if there is an id, print that instead of the structural type:
333 /*for def_id in ty::type_def_id(typ).iter() {
334 // note that this typedef cannot have type parameters
335 return ty::item_path_str(cx, *def_id);
338 // pretty print the structural type representation:
339 return match ty::get(typ).sty {
340 ty_nil => "()".to_owned(),
341 ty_bot => "!".to_owned(),
342 ty_bool => "bool".to_owned(),
343 ty_char => "char".to_owned(),
344 ty_int(t) => ast_util::int_ty_to_str(t, None),
345 ty_uint(t) => ast_util::uint_ty_to_str(t, None),
346 ty_float(t) => ast_util::float_ty_to_str(t),
347 ty_box(typ) => "@".to_owned() + ty_to_str(cx, typ),
348 ty_uniq(typ) => "~".to_owned() + ty_to_str(cx, typ),
349 ty_ptr(ref tm) => "*".to_owned() + mt_to_str(cx, tm),
350 ty_rptr(r, ref tm) => {
351 region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
353 ty_tup(ref elems) => {
354 let strs: Vec<~str> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
355 "(".to_owned() + strs.connect(",") + ")"
357 ty_closure(ref f) => {
358 closure_to_str(cx, *f)
360 ty_bare_fn(ref f) => {
361 bare_fn_to_str(cx, f.fn_style, f.abi, None, &f.sig)
363 ty_infer(infer_ty) => infer_ty.to_str(),
364 ty_err => "[type error]".to_owned(),
365 ty_param(param_ty {idx: id, def_id: did}) => {
366 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
367 Some(def) => token::get_ident(def.ident).get().to_str(),
368 // This can only happen when a type mismatch error happens and
369 // the actual type has more type parameters than the expected one.
370 None => format!("<generic \\#{}>", id)
372 if !cx.sess.verbose() {
375 format!("{}:{:?}", ident, did)
378 ty_self(..) => "Self".to_owned(),
379 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
380 let base = ty::item_path_str(cx, did);
384 substs.tps.as_slice(),
388 ty_trait(box ty::TyTrait {
389 def_id: did, ref substs, store, ref bounds
391 let base = ty::item_path_str(cx, did);
392 let ty = parameterized(cx, base, &substs.regions,
393 substs.tps.as_slice(), did, true);
394 let bound_sep = if bounds.is_empty() { "" } else { ":" };
395 let bound_str = bounds.repr(cx);
396 format!("{}{}{}{}", trait_store_to_str(cx, store), ty, bound_sep, bound_str)
398 ty_str => "str".to_owned(),
399 ty_vec(ref mt, sz) => {
401 Some(n) => format!("[{}, .. {}]", mt_to_str(cx, mt), n),
402 None => format!("[{}]", ty_to_str(cx, mt.ty)),
408 pub fn parameterized(cx: &ctxt,
410 regions: &ty::RegionSubsts,
413 is_trait: bool) -> ~str {
415 let mut strs = Vec::new();
417 ty::ErasedRegions => { }
418 ty::NonerasedRegions(ref regions) => {
419 for &r in regions.iter() {
420 strs.push(region_to_str(cx, "", false, r))
425 let generics = if is_trait {
426 ty::lookup_trait_def(cx, did).generics.clone()
428 ty::lookup_item_type(cx, did).generics
430 let ty_params = generics.type_param_defs();
431 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
432 let num_defaults = if has_defaults {
433 // We should have a borrowed version of substs instead of cloning.
434 let mut substs = ty::substs {
435 tps: Vec::from_slice(tps),
436 regions: regions.clone(),
439 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
442 Some(default) => ty::subst(cx, &substs, default) == actual,
450 for t in tps.slice_to(tps.len() - num_defaults).iter() {
451 strs.push(ty_to_str(cx, *t))
455 format!("{}<{}>", base, strs.connect(","))
461 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> ~str {
462 let mut s = typ.repr(cx);
463 if s.len() >= 32u { s = s.slice(0u, 32u).to_owned(); }
467 impl<T:Repr> Repr for Option<T> {
468 fn repr(&self, tcx: &ctxt) -> ~str {
470 &None => "None".to_owned(),
471 &Some(ref t) => t.repr(tcx),
476 impl<T:Repr,U:Repr> Repr for Result<T,U> {
477 fn repr(&self, tcx: &ctxt) -> ~str {
479 &Ok(ref t) => t.repr(tcx),
480 &Err(ref u) => format!("Err({})", u.repr(tcx))
486 fn repr(&self, _tcx: &ctxt) -> ~str {
491 impl<T:Repr> Repr for Rc<T> {
492 fn repr(&self, tcx: &ctxt) -> ~str {
497 impl<T:Repr> Repr for @T {
498 fn repr(&self, tcx: &ctxt) -> ~str {
503 impl<T:Repr> Repr for Box<T> {
504 fn repr(&self, tcx: &ctxt) -> ~str {
509 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> ~str {
510 vec_map_to_str(v, |t| t.repr(tcx))
513 impl<'a, T:Repr> Repr for &'a [T] {
514 fn repr(&self, tcx: &ctxt) -> ~str {
519 impl<T:Repr> Repr for OwnedSlice<T> {
520 fn repr(&self, tcx: &ctxt) -> ~str {
521 repr_vec(tcx, self.as_slice())
525 // This is necessary to handle types like Option<~[T]>, for which
526 // autoderef cannot convert the &[T] handler
527 impl<T:Repr> Repr for Vec<T> {
528 fn repr(&self, tcx: &ctxt) -> ~str {
529 repr_vec(tcx, self.as_slice())
533 impl Repr for ty::TypeParameterDef {
534 fn repr(&self, tcx: &ctxt) -> ~str {
535 format!("TypeParameterDef({:?}, {})",
537 self.bounds.repr(tcx))
541 impl Repr for ty::RegionParameterDef {
542 fn repr(&self, _tcx: &ctxt) -> ~str {
543 format!("RegionParameterDef({}, {:?})",
544 token::get_name(self.name),
549 impl Repr for ty::t {
550 fn repr(&self, tcx: &ctxt) -> ~str {
551 ty_to_str(tcx, *self)
555 impl Repr for ty::substs {
556 fn repr(&self, tcx: &ctxt) -> ~str {
557 format!("substs(regions={}, self_ty={}, tps={})",
558 self.regions.repr(tcx),
559 self.self_ty.repr(tcx),
564 impl Repr for ty::RegionSubsts {
565 fn repr(&self, tcx: &ctxt) -> ~str {
567 ty::ErasedRegions => "erased".to_owned(),
568 ty::NonerasedRegions(ref regions) => regions.repr(tcx)
573 impl Repr for ty::ParamBounds {
574 fn repr(&self, tcx: &ctxt) -> ~str {
575 let mut res = Vec::new();
576 for b in self.builtin_bounds.iter() {
578 ty::BoundStatic => "'static".to_owned(),
579 ty::BoundSend => "Send".to_owned(),
580 ty::BoundSized => "Sized".to_owned(),
581 ty::BoundCopy => "Pod".to_owned(),
582 ty::BoundShare => "Share".to_owned(),
585 for t in self.trait_bounds.iter() {
586 res.push(t.repr(tcx));
592 impl Repr for ty::TraitRef {
593 fn repr(&self, tcx: &ctxt) -> ~str {
594 trait_ref_to_str(tcx, self)
598 impl Repr for ast::Expr {
599 fn repr(&self, _tcx: &ctxt) -> ~str {
600 format!("expr({}: {})", self.id, pprust::expr_to_str(self))
604 impl Repr for ast::Item {
605 fn repr(&self, tcx: &ctxt) -> ~str {
606 format!("item({})", tcx.map.node_to_str(self.id))
610 impl Repr for ast::Stmt {
611 fn repr(&self, _tcx: &ctxt) -> ~str {
612 format!("stmt({}: {})",
613 ast_util::stmt_id(self),
614 pprust::stmt_to_str(self))
618 impl Repr for ast::Pat {
619 fn repr(&self, _tcx: &ctxt) -> ~str {
620 format!("pat({}: {})",
622 pprust::pat_to_str(self))
626 impl Repr for ty::BoundRegion {
627 fn repr(&self, tcx: &ctxt) -> ~str {
629 ty::BrAnon(id) => format!("BrAnon({})", id),
630 ty::BrNamed(id, name) => format!("BrNamed({}, {})",
632 token::get_name(name)),
633 ty::BrFresh(id) => format!("BrFresh({})", id),
638 impl Repr for ty::Region {
639 fn repr(&self, tcx: &ctxt) -> ~str {
641 ty::ReEarlyBound(id, index, name) => {
642 format!("ReEarlyBound({}, {}, {})",
643 id, index, token::get_name(name))
646 ty::ReLateBound(binder_id, ref bound_region) => {
647 format!("ReLateBound({}, {})",
648 binder_id, bound_region.repr(tcx))
651 ty::ReFree(ref fr) => {
652 format!("ReFree({}, {})",
654 fr.bound_region.repr(tcx))
658 format!("ReScope({})", id)
665 ty::ReInfer(ReVar(ref vid)) => {
666 format!("ReInfer({})", vid.id)
669 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
670 format!("re_skolemized({}, {})",
671 id, bound_region.repr(tcx))
681 impl Repr for ast::DefId {
682 fn repr(&self, tcx: &ctxt) -> ~str {
683 // Unfortunately, there seems to be no way to attempt to print
684 // a path for a def-id, so I'll just make a best effort for now
685 // and otherwise fallback to just printing the crate/node pair
686 if self.krate == ast::LOCAL_CRATE {
688 match tcx.map.find(self.node) {
689 Some(ast_map::NodeItem(..)) |
690 Some(ast_map::NodeForeignItem(..)) |
691 Some(ast_map::NodeMethod(..)) |
692 Some(ast_map::NodeTraitMethod(..)) |
693 Some(ast_map::NodeVariant(..)) |
694 Some(ast_map::NodeStructCtor(..)) => {
695 return format!("{:?}:{}",
697 ty::item_path_str(tcx, *self));
703 return format!("{:?}", *self);
707 impl Repr for ty::ty_param_bounds_and_ty {
708 fn repr(&self, tcx: &ctxt) -> ~str {
709 format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
710 self.generics.repr(tcx),
715 impl Repr for ty::Generics {
716 fn repr(&self, tcx: &ctxt) -> ~str {
717 format!("Generics(type_param_defs: {}, region_param_defs: {})",
718 self.type_param_defs().repr(tcx),
719 self.region_param_defs().repr(tcx))
723 impl Repr for ty::ItemVariances {
724 fn repr(&self, tcx: &ctxt) -> ~str {
725 format!("IterVariances(self_param={}, type_params={}, region_params={})",
726 self.self_param.repr(tcx),
727 self.type_params.repr(tcx),
728 self.region_params.repr(tcx))
732 impl Repr for ty::Variance {
733 fn repr(&self, _: &ctxt) -> ~str {
734 self.to_str().to_owned()
738 impl Repr for ty::Method {
739 fn repr(&self, tcx: &ctxt) -> ~str {
740 format!("method(ident: {}, generics: {}, fty: {}, \
741 explicit_self: {}, vis: {}, def_id: {})",
742 self.ident.repr(tcx),
743 self.generics.repr(tcx),
745 self.explicit_self.repr(tcx),
747 self.def_id.repr(tcx))
751 impl Repr for ast::Name {
752 fn repr(&self, _tcx: &ctxt) -> ~str {
753 token::get_name(*self).get().to_str()
757 impl Repr for ast::Ident {
758 fn repr(&self, _tcx: &ctxt) -> ~str {
759 token::get_ident(*self).get().to_str()
763 impl Repr for ast::ExplicitSelf_ {
764 fn repr(&self, _tcx: &ctxt) -> ~str {
765 format!("{:?}", *self)
769 impl Repr for ast::Visibility {
770 fn repr(&self, _tcx: &ctxt) -> ~str {
771 format!("{:?}", *self)
775 impl Repr for ty::BareFnTy {
776 fn repr(&self, tcx: &ctxt) -> ~str {
777 format!("BareFnTy \\{fn_style: {:?}, abi: {}, sig: {}\\}",
784 impl Repr for ty::FnSig {
785 fn repr(&self, tcx: &ctxt) -> ~str {
786 fn_sig_to_str(tcx, self)
790 impl Repr for typeck::MethodCallee {
791 fn repr(&self, tcx: &ctxt) -> ~str {
792 format!("MethodCallee \\{origin: {}, ty: {}, {}\\}",
793 self.origin.repr(tcx),
795 self.substs.repr(tcx))
799 impl Repr for typeck::MethodOrigin {
800 fn repr(&self, tcx: &ctxt) -> ~str {
802 &typeck::MethodStatic(def_id) => {
803 format!("MethodStatic({})", def_id.repr(tcx))
805 &typeck::MethodParam(ref p) => {
808 &typeck::MethodObject(ref p) => {
815 impl Repr for typeck::MethodParam {
816 fn repr(&self, tcx: &ctxt) -> ~str {
817 format!("MethodParam({},{:?},{:?},{:?})",
818 self.trait_id.repr(tcx),
825 impl Repr for typeck::MethodObject {
826 fn repr(&self, tcx: &ctxt) -> ~str {
827 format!("MethodObject({},{:?},{:?})",
828 self.trait_id.repr(tcx),
835 impl Repr for ty::RegionVid {
836 fn repr(&self, _tcx: &ctxt) -> ~str {
837 format!("{:?}", *self)
841 impl Repr for ty::TraitStore {
842 fn repr(&self, tcx: &ctxt) -> ~str {
843 trait_store_to_str(tcx, *self)
847 impl Repr for ty::BuiltinBound {
848 fn repr(&self, _tcx: &ctxt) -> ~str {
849 format!("{:?}", *self)
853 impl UserString for ty::BuiltinBound {
854 fn user_string(&self, _tcx: &ctxt) -> ~str {
856 ty::BoundStatic => "'static".to_owned(),
857 ty::BoundSend => "Send".to_owned(),
858 ty::BoundSized => "Sized".to_owned(),
859 ty::BoundCopy => "Pod".to_owned(),
860 ty::BoundShare => "Share".to_owned(),
865 impl Repr for ty::BuiltinBounds {
866 fn repr(&self, tcx: &ctxt) -> ~str {
867 self.user_string(tcx)
872 fn repr(&self, tcx: &ctxt) -> ~str {
873 tcx.sess.codemap().span_to_str(*self)
877 impl<A:UserString> UserString for Rc<A> {
878 fn user_string(&self, tcx: &ctxt) -> ~str {
879 let this: &A = &**self;
880 this.user_string(tcx)
884 impl UserString for ty::BuiltinBounds {
885 fn user_string(&self, tcx: &ctxt) -> ~str {
886 if self.is_empty() { "<no-bounds>".to_owned() } else {
887 let mut result = Vec::new();
888 for bb in self.iter() {
889 result.push(bb.user_string(tcx));
896 impl UserString for ty::TraitRef {
897 fn user_string(&self, tcx: &ctxt) -> ~str {
898 let base = ty::item_path_str(tcx, self.def_id);
899 if tcx.sess.verbose() && self.substs.self_ty.is_some() {
900 let mut all_tps = self.substs.tps.clone();
901 for &t in self.substs.self_ty.iter() { all_tps.push(t); }
902 parameterized(tcx, base, &self.substs.regions,
903 all_tps.as_slice(), self.def_id, true)
905 parameterized(tcx, base, &self.substs.regions,
906 self.substs.tps.as_slice(), self.def_id, true)
911 impl UserString for ty::t {
912 fn user_string(&self, tcx: &ctxt) -> ~str {
913 ty_to_str(tcx, *self)
917 impl UserString for ast::Ident {
918 fn user_string(&self, _tcx: &ctxt) -> ~str {
919 token::get_name(self.name).get().to_owned()
923 impl Repr for abi::Abi {
924 fn repr(&self, _tcx: &ctxt) -> ~str {
929 impl UserString for abi::Abi {
930 fn user_string(&self, _tcx: &ctxt) -> ~str {
935 impl Repr for ty::UpvarId {
936 fn repr(&self, tcx: &ctxt) -> ~str {
937 format!("UpvarId({};`{}`;{})",
939 ty::local_var_name_str(tcx, self.var_id),
940 self.closure_expr_id)
944 impl Repr for ast::Mutability {
945 fn repr(&self, _tcx: &ctxt) -> ~str {
946 format!("{:?}", *self)
950 impl Repr for ty::BorrowKind {
951 fn repr(&self, _tcx: &ctxt) -> ~str {
952 format!("{:?}", *self)
956 impl Repr for ty::UpvarBorrow {
957 fn repr(&self, tcx: &ctxt) -> ~str {
958 format!("UpvarBorrow({}, {})",
960 self.region.repr(tcx))