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};
32 use syntax::codemap::{Span, Pos};
33 use syntax::parse::token;
34 use syntax::print::pprust;
35 use syntax::{ast, ast_util};
36 use syntax::owned_slice::OwnedSlice;
38 /// Produces a string suitable for debugging output.
40 fn repr(&self, tcx: &ctxt) -> String;
43 /// Produces a string suitable for showing to the user.
44 pub trait UserString {
45 fn user_string(&self, tcx: &ctxt) -> String;
48 pub fn note_and_explain_region(cx: &ctxt,
52 match explain_region_and_span(cx, region) {
53 (ref str, Some(span)) => {
56 format!("{}{}{}", prefix, *str, suffix).as_slice());
60 format!("{}{}{}", prefix, *str, suffix).as_slice());
65 pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
66 -> (String, Option<Span>) {
69 match cx.map.find(node_id) {
70 Some(ast_map::NodeBlock(ref blk)) => {
71 explain_span(cx, "block", blk.span)
73 Some(ast_map::NodeExpr(expr)) => {
75 ast::ExprCall(..) => explain_span(cx, "call", expr.span),
76 ast::ExprMethodCall(..) => {
77 explain_span(cx, "method call", expr.span)
79 ast::ExprMatch(..) => explain_span(cx, "match", expr.span),
80 _ => explain_span(cx, "expression", expr.span)
83 Some(ast_map::NodeStmt(stmt)) => {
84 explain_span(cx, "statement", stmt.span)
86 Some(ast_map::NodeItem(it)) if (match it.node {
87 ast::ItemFn(..) => true, _ => false}) => {
88 explain_span(cx, "function body", it.span)
91 // this really should not happen
92 (format!("unknown scope: {}. Please report a bug.", node_id), None)
98 let prefix = match fr.bound_region {
101 format!("the anonymous lifetime \\#{} defined on", idx + 1)
105 format!("the anonymous lifetime #{} defined on", idx + 1)
107 BrFresh(_) => "an anonymous lifetime defined on".to_string(),
109 format!("the lifetime {} as defined on",
110 bound_region_ptr_to_str(cx, fr.bound_region))
114 match cx.map.find(fr.scope_id) {
115 Some(ast_map::NodeBlock(ref blk)) => {
116 let (msg, opt_span) = explain_span(cx, "block", blk.span);
117 (format!("{} {}", prefix, msg), opt_span)
119 Some(ast_map::NodeItem(it)) if match it.node {
120 ast::ItemImpl(..) => true, _ => false} => {
121 let (msg, opt_span) = explain_span(cx, "impl", it.span);
122 (format!("{} {}", prefix, msg), opt_span)
125 // this really should not happen
126 (format!("{} node {}", prefix, fr.scope_id), None)
131 ReStatic => { ("the static lifetime".to_string(), None) }
133 ReEmpty => { ("the empty lifetime".to_string(), None) }
135 // I believe these cases should not occur (except when debugging,
137 ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
138 (format!("lifetime {:?}", region), None)
142 fn explain_span(cx: &ctxt, heading: &str, span: Span)
143 -> (String, Option<Span>) {
144 let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
145 (format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
150 pub fn bound_region_ptr_to_str(cx: &ctxt, br: BoundRegion) -> String {
151 bound_region_to_str(cx, "", false, br)
154 pub fn bound_region_to_str(cx: &ctxt,
155 prefix: &str, space: bool,
156 br: BoundRegion) -> String {
157 let space_str = if space { " " } else { "" };
159 if cx.sess.verbose() {
160 return format!("{}{}{}", prefix, br.repr(cx), space_str)
164 BrNamed(_, name) => {
165 format!("{}{}{}", prefix, token::get_name(name), space_str)
167 BrAnon(_) => prefix.to_string(),
168 BrFresh(_) => prefix.to_string(),
172 // In general, if you are giving a region error message,
173 // you should use `explain_region()` or, better yet,
174 // `note_and_explain_region()`
175 pub fn region_ptr_to_str(cx: &ctxt, region: Region) -> String {
176 region_to_str(cx, "&", true, region)
179 pub fn region_to_str(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
180 let space_str = if space { " " } else { "" };
182 if cx.sess.verbose() {
183 return format!("{}{}{}", prefix, region.repr(cx), space_str)
186 // These printouts are concise. They do not contain all the information
187 // the user might want to diagnose an error, but there is basically no way
188 // to fit that into a short string. Hence the recommendation to use
189 // `explain_region()` or `note_and_explain_region()`.
191 ty::ReScope(_) => prefix.to_string(),
192 ty::ReEarlyBound(_, _, _, name) => {
193 token::get_name(name).get().to_string()
195 ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
196 ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
197 ty::ReInfer(ReSkolemized(_, br)) => {
198 bound_region_to_str(cx, prefix, space, br)
200 ty::ReInfer(ReVar(_)) => prefix.to_string(),
201 ty::ReStatic => format!("{}'static{}", prefix, space_str),
202 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
206 pub fn mutability_to_str(m: ast::Mutability) -> String {
208 ast::MutMutable => "mut ".to_string(),
209 ast::MutImmutable => "".to_string(),
213 pub fn mt_to_str(cx: &ctxt, m: &mt) -> String {
214 format!("{}{}", mutability_to_str(m.mutbl), ty_to_str(cx, m.ty))
217 pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> String {
219 ty::UniqTraitStore => "Box ".to_string(),
220 ty::RegionTraitStore(r, m) => {
221 format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m))
226 pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> String) -> String {
227 let tstrs = ts.iter().map(f).collect::<Vec<String>>();
228 format!("[{}]", tstrs.connect(", "))
231 pub fn fn_sig_to_str(cx: &ctxt, typ: &ty::FnSig) -> String {
232 format!("fn{}{} -> {}", typ.binder_id, typ.inputs.repr(cx),
236 pub fn trait_ref_to_str(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
237 trait_ref.user_string(cx).to_string()
240 pub fn ty_to_str(cx: &ctxt, typ: t) -> String {
241 fn fn_input_to_str(cx: &ctxt, input: ty::t) -> String {
242 ty_to_str(cx, input).to_string()
244 fn bare_fn_to_str(cx: &ctxt,
245 fn_style: ast::FnStyle,
247 ident: Option<ast::Ident>,
250 let mut s = String::new();
254 s.push_str(fn_style.to_str().as_slice());
259 if abi != abi::Rust {
260 s.push_str(format!("extern {} ", abi.to_str()).as_slice());
268 s.push_str(token::get_ident(i).get());
273 push_sig_to_str(cx, &mut s, '(', ')', sig);
278 fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> String {
279 let mut s = String::new();
282 ty::UniqTraitStore => {}
283 ty::RegionTraitStore(region, _) => {
284 s.push_str(region_to_str(cx, "", true, region).as_slice());
291 s.push_str(cty.fn_style.to_str().as_slice());
297 ty::UniqTraitStore => {
298 assert_eq!(cty.onceness, ast::Once);
300 push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
302 ty::RegionTraitStore(..) => {
305 ast::Once => s.push_str("once ")
307 push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
311 if !cty.bounds.is_empty() {
313 s.push_str(cty.bounds.repr(cx).as_slice());
319 fn push_sig_to_str(cx: &ctxt,
325 let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
326 s.push_str(strs.connect(", ").as_slice());
332 if ty::get(sig.output).sty != ty_nil {
334 if ty::type_is_bot(sig.output) {
337 s.push_str(ty_to_str(cx, sig.output).as_slice());
342 // if there is an id, print that instead of the structural type:
343 /*for def_id in ty::type_def_id(typ).iter() {
344 // note that this typedef cannot have type parameters
345 return ty::item_path_str(cx, *def_id);
348 // pretty print the structural type representation:
349 return match ty::get(typ).sty {
350 ty_nil => "()".to_string(),
351 ty_bot => "!".to_string(),
352 ty_bool => "bool".to_string(),
353 ty_char => "char".to_string(),
354 ty_int(t) => ast_util::int_ty_to_str(t, None,
355 ast_util::AutoSuffix).to_string(),
356 ty_uint(t) => ast_util::uint_ty_to_str(t, None,
357 ast_util::AutoSuffix).to_string(),
358 ty_float(t) => ast_util::float_ty_to_str(t).to_string(),
359 ty_box(typ) => format!("@{}", ty_to_str(cx, typ)),
360 ty_uniq(typ) => format!("~{}", ty_to_str(cx, typ)),
361 ty_ptr(ref tm) => format!("*{}", mt_to_str(cx, tm)),
362 ty_rptr(r, ref tm) => {
363 let mut buf = region_ptr_to_str(cx, r);
364 buf.push_str(mt_to_str(cx, tm).as_slice());
367 ty_tup(ref elems) => {
368 let strs: Vec<String> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
369 format!("({})", strs.connect(","))
371 ty_closure(ref f) => {
372 closure_to_str(cx, *f)
374 ty_bare_fn(ref f) => {
375 bare_fn_to_str(cx, f.fn_style, f.abi, None, &f.sig)
377 ty_infer(infer_ty) => infer_ty.to_str(),
378 ty_err => "[type error]".to_string(),
379 ty_param(ParamTy {idx: id, def_id: did, ..}) => {
380 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
381 Some(def) => token::get_ident(def.ident).get().to_string(),
382 // This can only happen when a type mismatch error happens and
383 // the actual type has more type parameters than the expected one.
385 None => format!("<generic \\#{}>", id),
387 None => format!("<generic #{}>", id),
389 if !cx.sess.verbose() {
392 format!("{}:{:?}", ident, did)
395 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
396 let base = ty::item_path_str(cx, did);
397 let generics = ty::lookup_item_type(cx, did).generics;
398 parameterized(cx, base.as_slice(), substs, &generics)
400 ty_trait(box ty::TyTrait {
401 def_id: did, ref substs, store, ref bounds
403 let base = ty::item_path_str(cx, did);
404 let trait_def = ty::lookup_trait_def(cx, did);
405 let ty = parameterized(cx, base.as_slice(),
406 substs, &trait_def.generics);
407 let bound_sep = if bounds.is_empty() { "" } else { ":" };
408 let bound_str = bounds.repr(cx);
410 trait_store_to_str(cx, store),
415 ty_str => "str".to_string(),
416 ty_vec(ref mt, sz) => {
419 format!("[{}, .. {}]", mt_to_str(cx, mt), n)
421 None => format!("[{}]", ty_to_str(cx, mt.ty)),
427 pub fn parameterized(cx: &ctxt,
429 substs: &subst::Substs,
430 generics: &ty::Generics)
433 let mut strs = Vec::new();
435 match substs.regions {
436 subst::ErasedRegions => { }
437 subst::NonerasedRegions(ref regions) => {
438 for &r in regions.iter() {
439 let s = region_to_str(cx, "", false, r);
443 // This happens when the value of the region
444 // parameter is not easily serialized. This may be
445 // because the user omitted it in the first place,
446 // or because it refers to some block in the code,
447 // etc. I'm not sure how best to serialize this.
448 strs.push(format!("'_"));
454 let tps = substs.types.get_vec(subst::TypeSpace);
455 let ty_params = generics.types.get_vec(subst::TypeSpace);
456 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
457 let num_defaults = if has_defaults && !cx.sess.verbose() {
458 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
460 Some(default) => default.subst(cx, substs) == actual,
468 for t in tps.slice_to(tps.len() - num_defaults).iter() {
469 strs.push(ty_to_str(cx, *t))
472 if cx.sess.verbose() {
473 for t in substs.types.get_vec(subst::SelfSpace).iter() {
474 strs.push(format!("for {}", t.repr(cx)));
479 format!("{}<{}>", base, strs.connect(","))
485 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String {
486 let mut s = typ.repr(cx).to_string();
488 s = s.as_slice().slice(0u, 32u).to_string();
493 impl<T:Repr> Repr for Option<T> {
494 fn repr(&self, tcx: &ctxt) -> String {
496 &None => "None".to_string(),
497 &Some(ref t) => t.repr(tcx),
502 impl<T:Repr,U:Repr> Repr for Result<T,U> {
503 fn repr(&self, tcx: &ctxt) -> String {
505 &Ok(ref t) => t.repr(tcx),
506 &Err(ref u) => format!("Err({})", u.repr(tcx))
512 fn repr(&self, _tcx: &ctxt) -> String {
517 impl<T:Repr> Repr for Rc<T> {
518 fn repr(&self, tcx: &ctxt) -> String {
523 impl<T:Repr + 'static> Repr for Gc<T> {
524 fn repr(&self, tcx: &ctxt) -> String {
529 impl<T:Repr> Repr for Box<T> {
530 fn repr(&self, tcx: &ctxt) -> String {
535 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> String {
536 vec_map_to_str(v, |t| t.repr(tcx))
539 impl<'a, T:Repr> Repr for &'a [T] {
540 fn repr(&self, tcx: &ctxt) -> String {
545 impl<T:Repr> Repr for OwnedSlice<T> {
546 fn repr(&self, tcx: &ctxt) -> String {
547 repr_vec(tcx, self.as_slice())
551 // This is necessary to handle types like Option<~[T]>, for which
552 // autoderef cannot convert the &[T] handler
553 impl<T:Repr> Repr for Vec<T> {
554 fn repr(&self, tcx: &ctxt) -> String {
555 repr_vec(tcx, self.as_slice())
559 impl Repr for def::Def {
560 fn repr(&self, _tcx: &ctxt) -> String {
561 format!("{:?}", *self)
565 impl Repr for ty::TypeParameterDef {
566 fn repr(&self, tcx: &ctxt) -> String {
567 format!("TypeParameterDef({:?}, {})", self.def_id,
568 self.bounds.repr(tcx))
572 impl Repr for ty::RegionParameterDef {
573 fn repr(&self, _tcx: &ctxt) -> String {
574 format!("RegionParameterDef({}, {:?})",
575 token::get_name(self.name),
580 impl Repr for ty::t {
581 fn repr(&self, tcx: &ctxt) -> String {
582 ty_to_str(tcx, *self)
586 impl Repr for subst::Substs {
587 fn repr(&self, tcx: &ctxt) -> String {
588 format!("Substs[types={}, regions={}]",
589 self.types.repr(tcx),
590 self.regions.repr(tcx))
594 impl<T:Repr> Repr for subst::VecPerParamSpace<T> {
595 fn repr(&self, tcx: &ctxt) -> String {
596 format!("[{};{};{}]",
597 self.get_vec(subst::TypeSpace).repr(tcx),
598 self.get_vec(subst::SelfSpace).repr(tcx),
599 self.get_vec(subst::FnSpace).repr(tcx))
603 impl Repr for ty::ItemSubsts {
604 fn repr(&self, tcx: &ctxt) -> String {
605 format!("ItemSubsts({})", self.substs.repr(tcx))
609 impl Repr for subst::RegionSubsts {
610 fn repr(&self, tcx: &ctxt) -> String {
612 subst::ErasedRegions => "erased".to_string(),
613 subst::NonerasedRegions(ref regions) => regions.repr(tcx)
618 impl Repr for ty::ParamBounds {
619 fn repr(&self, tcx: &ctxt) -> String {
620 let mut res = Vec::new();
621 for b in self.builtin_bounds.iter() {
623 ty::BoundStatic => "'static".to_string(),
624 ty::BoundSend => "Send".to_string(),
625 ty::BoundSized => "Sized".to_string(),
626 ty::BoundCopy => "Copy".to_string(),
627 ty::BoundShare => "Share".to_string(),
630 for t in self.trait_bounds.iter() {
631 res.push(t.repr(tcx));
633 res.connect("+").to_string()
637 impl Repr for ty::TraitRef {
638 fn repr(&self, tcx: &ctxt) -> String {
639 trait_ref_to_str(tcx, self)
643 impl Repr for ast::Expr {
644 fn repr(&self, _tcx: &ctxt) -> String {
645 format!("expr({}: {})", self.id, pprust::expr_to_str(self))
649 impl Repr for ast::Path {
650 fn repr(&self, _tcx: &ctxt) -> String {
651 format!("path({})", pprust::path_to_str(self))
655 impl Repr for ast::Item {
656 fn repr(&self, tcx: &ctxt) -> String {
657 format!("item({})", tcx.map.node_to_str(self.id))
661 impl Repr for ast::Stmt {
662 fn repr(&self, _tcx: &ctxt) -> String {
663 format!("stmt({}: {})",
664 ast_util::stmt_id(self),
665 pprust::stmt_to_str(self))
669 impl Repr for ast::Pat {
670 fn repr(&self, _tcx: &ctxt) -> String {
671 format!("pat({}: {})", self.id, pprust::pat_to_str(self))
675 impl Repr for ty::BoundRegion {
676 fn repr(&self, tcx: &ctxt) -> String {
678 ty::BrAnon(id) => format!("BrAnon({})", id),
679 ty::BrNamed(id, name) => {
680 format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
682 ty::BrFresh(id) => format!("BrFresh({})", id),
687 impl Repr for ty::Region {
688 fn repr(&self, tcx: &ctxt) -> String {
690 ty::ReEarlyBound(id, space, index, name) => {
691 format!("ReEarlyBound({}, {}, {}, {})",
695 token::get_name(name))
698 ty::ReLateBound(binder_id, ref bound_region) => {
699 format!("ReLateBound({}, {})",
701 bound_region.repr(tcx))
704 ty::ReFree(ref fr) => {
705 format!("ReFree({}, {})",
707 fr.bound_region.repr(tcx))
711 format!("ReScope({})", id)
715 "ReStatic".to_string()
718 ty::ReInfer(ReVar(ref vid)) => {
719 format!("ReInfer({})", vid.id)
722 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
723 format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
727 "ReEmpty".to_string()
733 impl Repr for ast::DefId {
734 fn repr(&self, tcx: &ctxt) -> String {
735 // Unfortunately, there seems to be no way to attempt to print
736 // a path for a def-id, so I'll just make a best effort for now
737 // and otherwise fallback to just printing the crate/node pair
738 if self.krate == ast::LOCAL_CRATE {
740 match tcx.map.find(self.node) {
741 Some(ast_map::NodeItem(..)) |
742 Some(ast_map::NodeForeignItem(..)) |
743 Some(ast_map::NodeMethod(..)) |
744 Some(ast_map::NodeTraitMethod(..)) |
745 Some(ast_map::NodeVariant(..)) |
746 Some(ast_map::NodeStructCtor(..)) => {
750 ty::item_path_str(tcx, *self))
756 return format!("{:?}", *self)
760 impl Repr for ty::ty_param_bounds_and_ty {
762 fn repr(&self, tcx: &ctxt) -> String {
763 format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
764 self.generics.repr(tcx),
768 fn repr(&self, tcx: &ctxt) -> String {
769 format!("ty_param_bounds_and_ty {{generics: {}, ty: {}}}",
770 self.generics.repr(tcx),
775 impl Repr for ty::Generics {
776 fn repr(&self, tcx: &ctxt) -> String {
777 format!("Generics(types: {}, regions: {})",
778 self.types.repr(tcx),
779 self.regions.repr(tcx))
783 impl Repr for ty::ItemVariances {
784 fn repr(&self, tcx: &ctxt) -> String {
785 format!("ItemVariances(types={}, \
787 self.types.repr(tcx),
788 self.regions.repr(tcx))
792 impl Repr for ty::Variance {
793 fn repr(&self, _: &ctxt) -> String {
794 // The first `.to_str()` returns a &'static str (it is not an implementation
795 // of the ToStr trait). Because of that, we need to call `.to_str()` again
796 // if we want to have a `String`.
797 self.to_str().to_str()
801 impl Repr for ty::Method {
802 fn repr(&self, tcx: &ctxt) -> String {
803 format!("method(ident: {}, generics: {}, fty: {}, \
804 explicit_self: {}, vis: {}, def_id: {})",
805 self.ident.repr(tcx),
806 self.generics.repr(tcx),
808 self.explicit_self.repr(tcx),
810 self.def_id.repr(tcx))
814 impl Repr for ast::Name {
815 fn repr(&self, _tcx: &ctxt) -> String {
816 token::get_name(*self).get().to_string()
820 impl Repr for ast::Ident {
821 fn repr(&self, _tcx: &ctxt) -> String {
822 token::get_ident(*self).get().to_string()
826 impl Repr for ast::ExplicitSelf_ {
827 fn repr(&self, _tcx: &ctxt) -> String {
828 format!("{:?}", *self)
832 impl Repr for ast::Visibility {
833 fn repr(&self, _tcx: &ctxt) -> String {
834 format!("{:?}", *self)
838 impl Repr for ty::BareFnTy {
840 fn repr(&self, tcx: &ctxt) -> String {
841 format!("BareFnTy \\{fn_style: {:?}, abi: {}, sig: {}\\}",
847 fn repr(&self, tcx: &ctxt) -> String {
848 format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
855 impl Repr for ty::FnSig {
856 fn repr(&self, tcx: &ctxt) -> String {
857 fn_sig_to_str(tcx, self)
861 impl Repr for typeck::MethodCallee {
863 fn repr(&self, tcx: &ctxt) -> String {
864 format!("MethodCallee \\{origin: {}, ty: {}, {}\\}",
865 self.origin.repr(tcx),
867 self.substs.repr(tcx))
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::MethodParam(ref p) => {
887 &typeck::MethodObject(ref p) => {
894 impl Repr for typeck::MethodParam {
895 fn repr(&self, tcx: &ctxt) -> String {
896 format!("MethodParam({},{:?},{:?},{:?})",
897 self.trait_id.repr(tcx),
904 impl Repr for typeck::MethodObject {
905 fn repr(&self, tcx: &ctxt) -> String {
906 format!("MethodObject({},{:?},{:?})",
907 self.trait_id.repr(tcx),
914 impl Repr for ty::RegionVid {
915 fn repr(&self, _tcx: &ctxt) -> String {
916 format!("{:?}", *self)
920 impl Repr for ty::TraitStore {
921 fn repr(&self, tcx: &ctxt) -> String {
922 trait_store_to_str(tcx, *self)
926 impl Repr for ty::BuiltinBound {
927 fn repr(&self, _tcx: &ctxt) -> String {
928 format!("{:?}", *self)
932 impl UserString for ty::BuiltinBound {
933 fn user_string(&self, _tcx: &ctxt) -> String {
935 ty::BoundStatic => "'static".to_string(),
936 ty::BoundSend => "Send".to_string(),
937 ty::BoundSized => "Sized".to_string(),
938 ty::BoundCopy => "Copy".to_string(),
939 ty::BoundShare => "Share".to_string(),
944 impl Repr for ty::BuiltinBounds {
945 fn repr(&self, tcx: &ctxt) -> String {
946 self.user_string(tcx)
951 fn repr(&self, tcx: &ctxt) -> String {
952 tcx.sess.codemap().span_to_str(*self).to_string()
956 impl<A:UserString> UserString for Rc<A> {
957 fn user_string(&self, tcx: &ctxt) -> String {
958 let this: &A = &**self;
959 this.user_string(tcx)
963 impl UserString for ty::BuiltinBounds {
964 fn user_string(&self, tcx: &ctxt) -> String {
966 .map(|bb| bb.user_string(tcx))
967 .collect::<Vec<String>>()
973 impl UserString for ty::TraitRef {
974 fn user_string(&self, tcx: &ctxt) -> String {
975 let base = ty::item_path_str(tcx, self.def_id);
976 let trait_def = ty::lookup_trait_def(tcx, self.def_id);
977 parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
981 impl UserString for ty::t {
982 fn user_string(&self, tcx: &ctxt) -> String {
983 ty_to_str(tcx, *self)
987 impl UserString for ast::Ident {
988 fn user_string(&self, _tcx: &ctxt) -> String {
989 token::get_name(self.name).get().to_string()
993 impl Repr for abi::Abi {
994 fn repr(&self, _tcx: &ctxt) -> String {
999 impl UserString for abi::Abi {
1000 fn user_string(&self, _tcx: &ctxt) -> String {
1005 impl Repr for ty::UpvarId {
1006 fn repr(&self, tcx: &ctxt) -> String {
1007 format!("UpvarId({};`{}`;{})",
1009 ty::local_var_name_str(tcx, self.var_id),
1010 self.closure_expr_id)
1014 impl Repr for ast::Mutability {
1015 fn repr(&self, _tcx: &ctxt) -> String {
1016 format!("{:?}", *self)
1020 impl Repr for ty::BorrowKind {
1021 fn repr(&self, _tcx: &ctxt) -> String {
1022 format!("{:?}", *self)
1026 impl Repr for ty::UpvarBorrow {
1027 fn repr(&self, tcx: &ctxt) -> String {
1028 format!("UpvarBorrow({}, {})",
1029 self.kind.repr(tcx),
1030 self.region.repr(tcx))