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_unboxed_vec, ty_infer};
25 use syntax::abi::AbiSet;
27 use syntax::codemap::{Span, Pos};
28 use syntax::parse::token;
29 use syntax::print::pprust;
30 use syntax::{ast, ast_util};
32 use syntax::opt_vec::OptVec;
34 /// Produces a string suitable for debugging output.
36 fn repr(&self, tcx: ctxt) -> ~str;
39 /// Produces a string suitable for showing to the user.
40 pub trait UserString {
41 fn user_string(&self, tcx: ctxt) -> ~str;
44 pub fn note_and_explain_region(cx: ctxt,
48 match explain_region_and_span(cx, region) {
49 (ref str, Some(span)) => {
52 format!("{}{}{}", prefix, *str, suffix));
56 format!("{}{}{}", prefix, *str, suffix));
61 /// Returns a string like "the block at 27:31" that attempts to explain a
62 /// lifetime in a way it might plausibly be understood.
63 pub fn explain_region(cx: ctxt, region: ty::Region) -> ~str {
64 let (res, _) = explain_region_and_span(cx, region);
69 pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
70 -> (~str, 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),
103 let prefix = match fr.bound_region {
104 BrAnon(idx) => format!("the anonymous lifetime \\#{} defined on",
106 BrFresh(_) => format!("an anonymous lifetime defined on"),
107 _ => format!("the lifetime {} as defined on",
108 bound_region_ptr_to_str(cx, fr.bound_region))
111 match cx.map.find(fr.scope_id) {
112 Some(ast_map::NodeBlock(ref blk)) => {
113 let (msg, opt_span) = explain_span(cx, "block", blk.span);
114 (format!("{} {}", prefix, msg), opt_span)
116 Some(ast_map::NodeItem(it)) if match it.node {
117 ast::ItemImpl(..) => true, _ => false} => {
118 let (msg, opt_span) = explain_span(cx, "impl", it.span);
119 (format!("{} {}", prefix, msg), opt_span)
122 // this really should not happen
123 (format!("{} node {}", prefix, fr.scope_id), None)
128 ReStatic => { (~"the static lifetime", None) }
130 ReEmpty => { (~"the empty lifetime", None) }
132 // I believe these cases should not occur (except when debugging,
134 ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
135 (format!("lifetime {:?}", region), None)
139 fn explain_span(cx: ctxt, heading: &str, span: Span)
140 -> (~str, Option<Span>)
142 let lo = cx.sess.codemap.lookup_char_pos_adj(span.lo);
143 (format!("the {} at {}:{}", heading,
144 lo.line, lo.col.to_uint()), Some(span))
148 pub fn bound_region_ptr_to_str(cx: ctxt, br: BoundRegion) -> ~str {
149 bound_region_to_str(cx, "&", true, br)
152 pub fn bound_region_to_str(cx: ctxt,
153 prefix: &str, space: bool,
154 br: BoundRegion) -> ~str {
155 let space_str = if space { " " } else { "" };
157 if cx.sess.verbose() {
158 return format!("{}{}{}", prefix, br.repr(cx), space_str);
162 BrNamed(_, ident) => format!("{}'{}{}", prefix,
163 token::get_name(ident), space_str),
164 BrAnon(_) => prefix.to_str(),
165 BrFresh(_) => prefix.to_str(),
169 pub fn ReScope_id_to_str(cx: ctxt, node_id: ast::NodeId) -> ~str {
170 match cx.map.find(node_id) {
171 Some(ast_map::NodeBlock(ref blk)) => {
172 format!("<block at {}>",
173 cx.sess.codemap.span_to_str(blk.span))
175 Some(ast_map::NodeExpr(expr)) => {
177 ast::ExprCall(..) => {
178 format!("<call at {}>",
179 cx.sess.codemap.span_to_str(expr.span))
181 ast::ExprMatch(..) => {
182 format!("<match at {}>",
183 cx.sess.codemap.span_to_str(expr.span))
185 ast::ExprAssignOp(..) |
187 ast::ExprBinary(..) |
188 ast::ExprIndex(..) => {
189 format!("<method at {}>",
190 cx.sess.codemap.span_to_str(expr.span))
193 format!("<expression at {}>",
194 cx.sess.codemap.span_to_str(expr.span))
199 format!("<unknown-{}>", node_id)
201 _ => cx.sess.bug(format!("ReScope refers to {}", cx.map.node_to_str(node_id)))
205 // In general, if you are giving a region error message,
206 // you should use `explain_region()` or, better yet,
207 // `note_and_explain_region()`
208 pub fn region_ptr_to_str(cx: ctxt, region: Region) -> ~str {
209 region_to_str(cx, "&", true, region)
212 pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~str {
213 let space_str = if space { " " } else { "" };
215 if cx.sess.verbose() {
216 return format!("{}{}{}", prefix, region.repr(cx), space_str);
219 // These printouts are concise. They do not contain all the information
220 // the user might want to diagnose an error, but there is basically no way
221 // to fit that into a short string. Hence the recommendation to use
222 // `explain_region()` or `note_and_explain_region()`.
224 ty::ReScope(_) => prefix.to_str(),
225 ty::ReEarlyBound(_, _, ident) => token::get_name(ident).get().to_str(),
226 ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
227 ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
228 ty::ReInfer(ReSkolemized(_, br)) => {
229 bound_region_to_str(cx, prefix, space, br)
231 ty::ReInfer(ReVar(_)) => prefix.to_str(),
232 ty::ReStatic => format!("{}'static{}", prefix, space_str),
233 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str)
237 pub fn mutability_to_str(m: ast::Mutability) -> ~str {
239 ast::MutMutable => ~"mut ",
240 ast::MutImmutable => ~"",
244 pub fn mt_to_str(cx: ctxt, m: &mt) -> ~str {
245 mt_to_str_wrapped(cx, "", m, "")
248 pub fn mt_to_str_wrapped(cx: ctxt, before: &str, m: &mt, after: &str) -> ~str {
249 let mstr = mutability_to_str(m.mutbl);
250 return format!("{}{}{}{}", mstr, before, ty_to_str(cx, m.ty), after);
253 pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
255 ty::vstore_fixed(n) => format!("{}", n),
256 ty::vstore_uniq => ~"~",
257 ty::vstore_slice(r) => region_ptr_to_str(cx, r)
261 pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
263 ty::UniqTraitStore => ~"~",
264 ty::RegionTraitStore(r) => region_ptr_to_str(cx, r)
268 pub fn vstore_ty_to_str(cx: ctxt, mt: &mt, vs: ty::vstore) -> ~str {
270 ty::vstore_fixed(_) => {
271 format!("[{}, .. {}]", mt_to_str(cx, mt), vstore_to_str(cx, vs))
274 format!("{}{}", vstore_to_str(cx, vs), mt_to_str_wrapped(cx, "[", mt, "]"))
279 pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> ~str) -> ~str {
280 let tstrs = ts.map(f);
281 format!("[{}]", tstrs.connect(", "))
284 pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str {
285 vec_map_to_str(ts, |t| ty_to_str(cx, *t))
288 pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str {
289 format!("fn{}{} -> {}",
295 pub fn trait_ref_to_str(cx: ctxt, trait_ref: &ty::TraitRef) -> ~str {
296 trait_ref.user_string(cx)
299 pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
300 fn fn_input_to_str(cx: ctxt, input: ty::t) -> ~str {
303 fn bare_fn_to_str(cx: ctxt,
306 ident: Option<ast::Ident>,
309 let mut s = if abis.is_rust() {
312 format!("extern {} ", abis.to_str())
318 s.push_str(purity.to_str());
328 s.push_str(token::get_ident(i).get());
333 push_sig_to_str(cx, &mut s, '(', ')', sig);
337 fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str {
339 (cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
340 let is_borrowed_closure = cty.sigil == ast::BorrowedSigil;
342 let mut s = if is_proc || is_borrowed_closure {
348 match (cty.sigil, cty.region) {
349 (ast::ManagedSigil, ty::ReStatic) |
350 (ast::OwnedSigil, ty::ReStatic) => {}
353 s.push_str(region_to_str(cx, "", true, region));
360 s.push_str(cty.purity.to_str());
371 s.push_str(cty.onceness.to_str());
376 if !is_borrowed_closure {
381 if !is_borrowed_closure {
382 // Print bounds before `fn` if this is not a borrowed closure.
383 if !cty.bounds.is_empty() {
385 s.push_str(cty.bounds.repr(cx));
388 push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
390 // Print bounds after the signature if this is a borrowed closure.
391 push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
393 if is_borrowed_closure {
394 if !cty.bounds.is_empty() {
396 s.push_str(cty.bounds.repr(cx));
403 fn push_sig_to_str(cx: ctxt,
409 let strs = sig.inputs.map(|a| fn_input_to_str(cx, *a));
410 s.push_str(strs.connect(", "));
416 if ty::get(sig.output).sty != ty_nil {
418 if ty::type_is_bot(sig.output) {
421 s.push_str(ty_to_str(cx, sig.output));
426 // if there is an id, print that instead of the structural type:
427 /*for def_id in ty::type_def_id(typ).iter() {
428 // note that this typedef cannot have type parameters
429 return ty::item_path_str(cx, *def_id);
432 // pretty print the structural type representation:
433 return match ty::get(typ).sty {
438 ty_int(ast::TyI) => ~"int",
439 ty_int(t) => ast_util::int_ty_to_str(t),
440 ty_uint(ast::TyU) => ~"uint",
441 ty_uint(t) => ast_util::uint_ty_to_str(t),
442 ty_float(t) => ast_util::float_ty_to_str(t),
443 ty_box(typ) => ~"@" + ty_to_str(cx, typ),
444 ty_uniq(typ) => ~"~" + ty_to_str(cx, typ),
445 ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
446 ty_rptr(r, ref tm) => {
447 region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
449 ty_unboxed_vec(ref tm) => { format!("unboxed_vec<{}>", mt_to_str(cx, tm)) }
450 ty_tup(ref elems) => {
451 let strs = elems.map(|elem| ty_to_str(cx, *elem));
452 ~"(" + strs.connect(",") + ")"
454 ty_closure(ref f) => {
455 closure_to_str(cx, f)
457 ty_bare_fn(ref f) => {
458 bare_fn_to_str(cx, f.purity, f.abis, None, &f.sig)
460 ty_infer(infer_ty) => infer_ty.to_str(),
461 ty_err => ~"[type error]",
462 ty_param(param_ty {idx: id, def_id: did}) => {
463 let ty_param_defs = cx.ty_param_defs.borrow();
464 let param_def = ty_param_defs.get().find(&did.node);
465 let ident = match param_def {
466 Some(def) => token::get_ident(def.ident).get().to_str(),
467 // This should not happen...
468 None => format!("BUG[{:?}]", id)
470 if !cx.sess.verbose() {
473 format!("{}:{:?}", ident, did)
476 ty_self(..) => ~"Self",
477 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
478 let base = ty::item_path_str(cx, did);
479 parameterized(cx, base, &substs.regions, substs.tps, did, false)
481 ty_trait(did, ref substs, s, mutbl, ref bounds) => {
482 let base = ty::item_path_str(cx, did);
483 let ty = parameterized(cx, base, &substs.regions,
484 substs.tps, did, true);
485 let bound_sep = if bounds.is_empty() { "" } else { ":" };
486 let bound_str = bounds.repr(cx);
487 format!("{}{}{}{}{}", trait_store_to_str(cx, s), mutability_to_str(mutbl), ty,
488 bound_sep, bound_str)
490 ty_vec(ref mt, vs) => {
491 vstore_ty_to_str(cx, mt, vs)
493 ty_str(vs) => format!("{}{}", vstore_to_str(cx, vs), "str")
497 pub fn parameterized(cx: ctxt,
499 regions: &ty::RegionSubsts,
502 is_trait: bool) -> ~str {
506 ty::ErasedRegions => { }
507 ty::NonerasedRegions(ref regions) => {
508 for &r in regions.iter() {
509 strs.push(region_to_str(cx, "", false, r))
514 let generics = if is_trait {
515 ty::lookup_trait_def(cx, did).generics.clone()
517 ty::lookup_item_type(cx, did).generics
519 let ty_params = generics.type_param_defs();
520 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
521 let num_defaults = if has_defaults {
522 // We should have a borrowed version of substs instead of cloning.
523 let mut substs = ty::substs {
525 regions: regions.clone(),
528 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
531 Some(default) => ty::subst(cx, &substs, default) == actual,
539 for t in tps.slice_to(tps.len() - num_defaults).iter() {
540 strs.push(ty_to_str(cx, *t))
544 format!("{}<{}>", base, strs.connect(","))
550 pub fn ty_to_short_str(cx: ctxt, typ: t) -> ~str {
551 let mut s = encoder::encoded_ty(cx, typ);
552 if s.len() >= 32u { s = s.slice(0u, 32u).to_owned(); }
556 impl<T:Repr> Repr for Option<T> {
557 fn repr(&self, tcx: ctxt) -> ~str {
560 &Some(ref t) => t.repr(tcx),
565 impl<T:Repr,U:Repr> Repr for Result<T,U> {
566 fn repr(&self, tcx: ctxt) -> ~str {
568 &Ok(ref t) => t.repr(tcx),
569 &Err(ref u) => format!("Err({})", u.repr(tcx))
575 fn repr(&self, _tcx: ctxt) -> ~str {
580 impl<T:Repr> Repr for @T {
581 fn repr(&self, tcx: ctxt) -> ~str {
586 impl<T:Repr> Repr for ~T {
587 fn repr(&self, tcx: ctxt) -> ~str {
592 fn repr_vec<T:Repr>(tcx: ctxt, v: &[T]) -> ~str {
593 vec_map_to_str(v, |t| t.repr(tcx))
596 impl<'a, T:Repr> Repr for &'a [T] {
597 fn repr(&self, tcx: ctxt) -> ~str {
602 impl<T:Repr> Repr for OptVec<T> {
603 fn repr(&self, tcx: ctxt) -> ~str {
605 opt_vec::Empty => ~"[]",
606 opt_vec::Vec(ref v) => repr_vec(tcx, v.as_slice())
611 // This is necessary to handle types like Option<~[T]>, for which
612 // autoderef cannot convert the &[T] handler
613 impl<T:Repr> Repr for ~[T] {
614 fn repr(&self, tcx: ctxt) -> ~str {
619 impl Repr for ty::TypeParameterDef {
620 fn repr(&self, tcx: ctxt) -> ~str {
621 format!("TypeParameterDef({:?}, {})",
623 self.bounds.repr(tcx))
627 impl Repr for ty::RegionParameterDef {
628 fn repr(&self, _tcx: ctxt) -> ~str {
629 format!("RegionParameterDef({}, {:?})",
630 token::get_name(self.ident),
635 impl Repr for ty::t {
636 fn repr(&self, tcx: ctxt) -> ~str {
637 ty_to_str(tcx, *self)
641 impl Repr for ty::substs {
642 fn repr(&self, tcx: ctxt) -> ~str {
643 format!("substs(regions={}, self_ty={}, tps={})",
644 self.regions.repr(tcx),
645 self.self_ty.repr(tcx),
650 impl Repr for ty::RegionSubsts {
651 fn repr(&self, tcx: ctxt) -> ~str {
653 ty::ErasedRegions => ~"erased",
654 ty::NonerasedRegions(ref regions) => regions.repr(tcx)
659 impl Repr for ty::ParamBounds {
660 fn repr(&self, tcx: ctxt) -> ~str {
662 for b in self.builtin_bounds.iter() {
664 ty::BoundStatic => ~"'static",
665 ty::BoundSend => ~"Send",
666 ty::BoundFreeze => ~"Freeze",
667 ty::BoundSized => ~"Sized",
668 ty::BoundPod => ~"Pod",
671 for t in self.trait_bounds.iter() {
672 res.push(t.repr(tcx));
678 impl Repr for ty::TraitRef {
679 fn repr(&self, tcx: ctxt) -> ~str {
680 trait_ref_to_str(tcx, self)
684 impl Repr for ast::Expr {
685 fn repr(&self, _tcx: ctxt) -> ~str {
686 format!("expr({}: {})", self.id, pprust::expr_to_str(self))
690 impl Repr for ast::Item {
691 fn repr(&self, tcx: ctxt) -> ~str {
692 format!("item({})", tcx.map.node_to_str(self.id))
696 impl Repr for ast::Stmt {
697 fn repr(&self, _tcx: ctxt) -> ~str {
698 format!("stmt({}: {})",
699 ast_util::stmt_id(self),
700 pprust::stmt_to_str(self))
704 impl Repr for ast::Pat {
705 fn repr(&self, _tcx: ctxt) -> ~str {
706 format!("pat({}: {})",
708 pprust::pat_to_str(self))
712 impl Repr for ty::BoundRegion {
713 fn repr(&self, tcx: ctxt) -> ~str {
715 ty::BrAnon(id) => format!("BrAnon({})", id),
716 ty::BrNamed(id, ident) => format!("BrNamed({}, {})",
718 token::get_name(ident)),
719 ty::BrFresh(id) => format!("BrFresh({})", id),
724 impl Repr for ty::Region {
725 fn repr(&self, tcx: ctxt) -> ~str {
727 ty::ReEarlyBound(id, index, ident) => {
728 format!("ReEarlyBound({}, {}, {})",
729 id, index, token::get_name(ident))
732 ty::ReLateBound(binder_id, ref bound_region) => {
733 format!("ReLateBound({}, {})",
734 binder_id, bound_region.repr(tcx))
737 ty::ReFree(ref fr) => {
738 format!("ReFree({}, {})",
740 fr.bound_region.repr(tcx))
744 format!("ReScope({})", id)
751 ty::ReInfer(ReVar(ref vid)) => {
752 format!("ReInfer({})", vid.id)
755 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
756 format!("re_skolemized({}, {})",
757 id, bound_region.repr(tcx))
767 impl Repr for ast::DefId {
768 fn repr(&self, tcx: ctxt) -> ~str {
769 // Unfortunately, there seems to be no way to attempt to print
770 // a path for a def-id, so I'll just make a best effort for now
771 // and otherwise fallback to just printing the crate/node pair
772 if self.krate == ast::LOCAL_CRATE {
774 match tcx.map.find(self.node) {
775 Some(ast_map::NodeItem(..)) |
776 Some(ast_map::NodeForeignItem(..)) |
777 Some(ast_map::NodeMethod(..)) |
778 Some(ast_map::NodeTraitMethod(..)) |
779 Some(ast_map::NodeVariant(..)) |
780 Some(ast_map::NodeStructCtor(..)) => {
781 return format!("{:?}:{}",
783 ty::item_path_str(tcx, *self));
789 return format!("{:?}", *self);
793 impl Repr for ty::ty_param_bounds_and_ty {
794 fn repr(&self, tcx: ctxt) -> ~str {
795 format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
796 self.generics.repr(tcx),
801 impl Repr for ty::Generics {
802 fn repr(&self, tcx: ctxt) -> ~str {
803 format!("Generics(type_param_defs: {}, region_param_defs: {})",
804 self.type_param_defs().repr(tcx),
805 self.region_param_defs().repr(tcx))
809 impl Repr for ty::ItemVariances {
810 fn repr(&self, tcx: ctxt) -> ~str {
811 format!("IterVariances(self_param={}, type_params={}, region_params={})",
812 self.self_param.repr(tcx),
813 self.type_params.repr(tcx),
814 self.region_params.repr(tcx))
818 impl Repr for ty::Variance {
819 fn repr(&self, _: ctxt) -> ~str {
820 self.to_str().to_owned()
824 impl Repr for ty::Method {
825 fn repr(&self, tcx: ctxt) -> ~str {
826 format!("method(ident: {}, generics: {}, fty: {}, \
827 explicit_self: {}, vis: {}, def_id: {})",
828 self.ident.repr(tcx),
829 self.generics.repr(tcx),
831 self.explicit_self.repr(tcx),
833 self.def_id.repr(tcx))
837 impl Repr for ast::Ident {
838 fn repr(&self, _tcx: ctxt) -> ~str {
839 token::get_ident(*self).get().to_str()
843 impl Repr for ast::ExplicitSelf_ {
844 fn repr(&self, _tcx: ctxt) -> ~str {
845 format!("{:?}", *self)
849 impl Repr for ast::Visibility {
850 fn repr(&self, _tcx: ctxt) -> ~str {
851 format!("{:?}", *self)
855 impl Repr for ty::BareFnTy {
856 fn repr(&self, tcx: ctxt) -> ~str {
857 format!("BareFnTy \\{purity: {:?}, abis: {}, sig: {}\\}",
864 impl Repr for ty::FnSig {
865 fn repr(&self, tcx: ctxt) -> ~str {
866 fn_sig_to_str(tcx, self)
870 impl Repr for typeck::MethodCallee {
871 fn repr(&self, tcx: ctxt) -> ~str {
872 format!("MethodCallee \\{origin: {}, ty: {}, {}\\}",
873 self.origin.repr(tcx),
875 self.substs.repr(tcx))
879 impl Repr for typeck::MethodOrigin {
880 fn repr(&self, tcx: ctxt) -> ~str {
882 &typeck::MethodStatic(def_id) => {
883 format!("MethodStatic({})", def_id.repr(tcx))
885 &typeck::MethodParam(ref p) => {
888 &typeck::MethodObject(ref p) => {
895 impl Repr for typeck::MethodParam {
896 fn repr(&self, tcx: ctxt) -> ~str {
897 format!("MethodParam({},{:?},{:?},{:?})",
898 self.trait_id.repr(tcx),
905 impl Repr for typeck::MethodObject {
906 fn repr(&self, tcx: ctxt) -> ~str {
907 format!("MethodObject({},{:?},{:?})",
908 self.trait_id.repr(tcx),
915 impl Repr for ty::RegionVid {
916 fn repr(&self, _tcx: ctxt) -> ~str {
917 format!("{:?}", *self)
921 impl Repr for ty::TraitStore {
922 fn repr(&self, tcx: ctxt) -> ~str {
924 &ty::UniqTraitStore => ~"~Trait",
925 &ty::RegionTraitStore(r) => format!("&{} Trait", r.repr(tcx))
930 impl Repr for ty::vstore {
931 fn repr(&self, tcx: ctxt) -> ~str {
932 vstore_to_str(tcx, *self)
936 impl Repr for ty::BuiltinBound {
937 fn repr(&self, _tcx: ctxt) -> ~str {
938 format!("{:?}", *self)
942 impl UserString for ty::BuiltinBound {
943 fn user_string(&self, _tcx: ctxt) -> ~str {
945 ty::BoundStatic => ~"'static",
946 ty::BoundSend => ~"Send",
947 ty::BoundFreeze => ~"Freeze",
948 ty::BoundSized => ~"Sized",
949 ty::BoundPod => ~"Pod",
954 impl Repr for ty::BuiltinBounds {
955 fn repr(&self, tcx: ctxt) -> ~str {
956 self.user_string(tcx)
961 fn repr(&self, tcx: ctxt) -> ~str {
962 tcx.sess.codemap.span_to_str(*self)
966 impl<A:UserString> UserString for @A {
967 fn user_string(&self, tcx: ctxt) -> ~str {
968 let this: &A = &**self;
969 this.user_string(tcx)
973 impl UserString for ty::BuiltinBounds {
974 fn user_string(&self, tcx: ctxt) -> ~str {
975 if self.is_empty() { ~"<no-bounds>" } else {
976 let mut result = ~[];
977 for bb in self.iter() {
978 result.push(bb.user_string(tcx));
985 impl UserString for ty::TraitRef {
986 fn user_string(&self, tcx: ctxt) -> ~str {
987 let base = ty::item_path_str(tcx, self.def_id);
988 if tcx.sess.verbose() && self.substs.self_ty.is_some() {
989 let mut all_tps = self.substs.tps.clone();
990 for &t in self.substs.self_ty.iter() { all_tps.push(t); }
991 parameterized(tcx, base, &self.substs.regions,
992 all_tps, self.def_id, true)
994 parameterized(tcx, base, &self.substs.regions,
995 self.substs.tps, self.def_id, true)
1000 impl UserString for ty::t {
1001 fn user_string(&self, tcx: ctxt) -> ~str {
1002 ty_to_str(tcx, *self)
1006 impl Repr for AbiSet {
1007 fn repr(&self, _tcx: ctxt) -> ~str {
1012 impl UserString for AbiSet {
1013 fn user_string(&self, _tcx: ctxt) -> ~str {
1018 impl Repr for ty::UpvarId {
1019 fn repr(&self, tcx: ctxt) -> ~str {
1020 format!("UpvarId({};`{}`;{})",
1022 ty::local_var_name_str(tcx, self.var_id),
1023 self.closure_expr_id)
1027 impl Repr for ast::Mutability {
1028 fn repr(&self, _tcx: ctxt) -> ~str {
1029 format!("{:?}", *self)
1033 impl Repr for ty::BorrowKind {
1034 fn repr(&self, _tcx: ctxt) -> ~str {
1035 format!("{:?}", *self)
1039 impl Repr for ty::UpvarBorrow {
1040 fn repr(&self, tcx: ctxt) -> ~str {
1041 format!("UpvarBorrow({}, {})",
1042 self.kind.repr(tcx),
1043 self.region.repr(tcx))