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.
13 use middle::subst::{VecPerParamSpace,Subst};
15 use middle::ty::{BoundRegion, BrAnon, BrNamed};
16 use middle::ty::{ReEarlyBound, BrFresh, ctxt};
17 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
18 use middle::ty::{ReSkolemized, ReVar};
19 use middle::ty::{mt, t, ParamTy};
20 use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
21 use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
22 use middle::ty::{ty_nil, ty_param, ty_ptr, ty_rptr, ty_tup};
23 use middle::ty::{ty_unboxed_closure};
24 use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
26 use middle::typeck::infer::region_inference;
27 use middle::typeck::infer::unify::VarValue as VV;
28 use middle::typeck::infer::unify;
29 use middle::typeck::infer;
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_string(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 ReEarlyBound(_, _, _, name) => {
135 (format!("{}", token::get_name(name)), None)
138 // I believe these cases should not occur (except when debugging,
140 ty::ReInfer(_) | ty::ReLateBound(..) => {
141 (format!("lifetime {:?}", region), None)
145 fn explain_span(cx: &ctxt, heading: &str, span: Span)
146 -> (String, Option<Span>) {
147 let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
148 (format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
153 pub fn bound_region_ptr_to_string(cx: &ctxt, br: BoundRegion) -> String {
154 bound_region_to_string(cx, "", false, br)
157 pub fn bound_region_to_string(cx: &ctxt,
158 prefix: &str, space: bool,
159 br: BoundRegion) -> String {
160 let space_str = if space { " " } else { "" };
162 if cx.sess.verbose() {
163 return format!("{}{}{}", prefix, br.repr(cx), space_str)
167 BrNamed(_, name) => {
168 format!("{}{}{}", prefix, token::get_name(name), space_str)
170 BrAnon(_) => prefix.to_string(),
171 BrFresh(_) => prefix.to_string(),
175 // In general, if you are giving a region error message,
176 // you should use `explain_region()` or, better yet,
177 // `note_and_explain_region()`
178 pub fn region_ptr_to_string(cx: &ctxt, region: Region) -> String {
179 region_to_string(cx, "&", true, region)
182 pub fn region_to_string(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
183 let space_str = if space { " " } else { "" };
185 if cx.sess.verbose() {
186 return format!("{}{}{}", prefix, region.repr(cx), space_str)
189 // These printouts are concise. They do not contain all the information
190 // the user might want to diagnose an error, but there is basically no way
191 // to fit that into a short string. Hence the recommendation to use
192 // `explain_region()` or `note_and_explain_region()`.
194 ty::ReScope(_) => prefix.to_string(),
195 ty::ReEarlyBound(_, _, _, name) => {
196 token::get_name(name).get().to_string()
198 ty::ReLateBound(_, br) => bound_region_to_string(cx, prefix, space, br),
199 ty::ReFree(ref fr) => bound_region_to_string(cx, prefix, space, fr.bound_region),
200 ty::ReInfer(ReSkolemized(_, br)) => {
201 bound_region_to_string(cx, prefix, space, br)
203 ty::ReInfer(ReVar(_)) => prefix.to_string(),
204 ty::ReStatic => format!("{}'static{}", prefix, space_str),
205 ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
209 pub fn mutability_to_string(m: ast::Mutability) -> String {
211 ast::MutMutable => "mut ".to_string(),
212 ast::MutImmutable => "".to_string(),
216 pub fn mt_to_string(cx: &ctxt, m: &mt) -> String {
217 format!("{}{}", mutability_to_string(m.mutbl), ty_to_string(cx, m.ty))
220 pub fn trait_store_to_string(cx: &ctxt, s: ty::TraitStore) -> String {
222 ty::UniqTraitStore => "Box ".to_string(),
223 ty::RegionTraitStore(r, m) => {
224 format!("{}{}", region_ptr_to_string(cx, r), mutability_to_string(m))
229 pub fn vec_map_to_string<T>(ts: &[T], f: |t: &T| -> String) -> String {
230 let tstrs = ts.iter().map(f).collect::<Vec<String>>();
231 format!("[{}]", tstrs.connect(", "))
234 pub fn fn_sig_to_string(cx: &ctxt, typ: &ty::FnSig) -> String {
235 format!("fn{}{} -> {}", typ.binder_id, typ.inputs.repr(cx),
239 pub fn trait_ref_to_string(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
240 trait_ref.user_string(cx).to_string()
243 pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
244 fn fn_input_to_string(cx: &ctxt, input: ty::t) -> String {
245 ty_to_string(cx, input).to_string()
247 fn bare_fn_to_string(cx: &ctxt,
248 fn_style: ast::FnStyle,
250 ident: Option<ast::Ident>,
253 let mut s = String::new();
257 s.push_str(fn_style.to_string().as_slice());
262 if abi != abi::Rust {
263 s.push_str(format!("extern {} ", abi.to_string()).as_slice());
271 s.push_str(token::get_ident(i).get());
276 push_sig_to_string(cx, &mut s, '(', ')', sig);
281 fn closure_to_string(cx: &ctxt, cty: &ty::ClosureTy) -> String {
282 let mut s = String::new();
285 ty::UniqTraitStore => {}
286 ty::RegionTraitStore(region, _) => {
287 s.push_str(region_to_string(cx, "", true, region).as_slice());
294 s.push_str(cty.fn_style.to_string().as_slice());
300 ty::UniqTraitStore => {
301 assert_eq!(cty.onceness, ast::Once);
303 push_sig_to_string(cx, &mut s, '(', ')', &cty.sig);
305 ty::RegionTraitStore(..) => {
308 ast::Once => s.push_str("once ")
310 push_sig_to_string(cx, &mut s, '|', '|', &cty.sig);
314 if !cty.bounds.is_empty() {
316 s.push_str(cty.bounds.repr(cx).as_slice());
322 fn push_sig_to_string(cx: &ctxt,
328 let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_string(cx, *a)).collect();
329 s.push_str(strs.connect(", ").as_slice());
335 if ty::get(sig.output).sty != ty_nil {
337 if ty::type_is_bot(sig.output) {
340 s.push_str(ty_to_string(cx, sig.output).as_slice());
345 // if there is an id, print that instead of the structural type:
346 /*for def_id in ty::type_def_id(typ).iter() {
347 // note that this typedef cannot have type parameters
348 return ty::item_path_str(cx, *def_id);
351 // pretty print the structural type representation:
352 return match ty::get(typ).sty {
353 ty_nil => "()".to_string(),
354 ty_bot => "!".to_string(),
355 ty_bool => "bool".to_string(),
356 ty_char => "char".to_string(),
357 ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
358 ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
359 ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
360 ty_box(typ) => format!("Gc<{}>", ty_to_string(cx, typ)),
361 ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
363 format!("*{} {}", match tm.mutbl {
364 ast::MutMutable => "mut",
365 ast::MutImmutable => "const",
366 }, ty_to_string(cx, tm.ty))
368 ty_rptr(r, ref tm) => {
369 let mut buf = region_ptr_to_string(cx, r);
370 buf.push_str(mt_to_string(cx, tm).as_slice());
373 ty_tup(ref elems) => {
374 let strs: Vec<String> = elems.iter().map(|elem| ty_to_string(cx, *elem)).collect();
375 format!("({})", strs.connect(","))
377 ty_closure(ref f) => {
378 closure_to_string(cx, &**f)
380 ty_bare_fn(ref f) => {
381 bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
383 ty_infer(infer_ty) => infer_ty.to_string(),
384 ty_err => "[type error]".to_string(),
385 ty_param(ParamTy {idx: id, def_id: did, ..}) => {
386 let ident = match cx.ty_param_defs.borrow().find(&did.node) {
387 Some(def) => token::get_ident(def.ident).get().to_string(),
388 // This can only happen when a type mismatch error happens and
389 // the actual type has more type parameters than the expected one.
390 None => format!("<generic #{}>", id),
392 if !cx.sess.verbose() {
395 format!("{}:{:?}", ident, did)
398 ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
399 let base = ty::item_path_str(cx, did);
400 let generics = ty::lookup_item_type(cx, did).generics;
401 parameterized(cx, base.as_slice(), substs, &generics)
403 ty_trait(box ty::TyTrait {
404 def_id: did, ref substs, ref bounds
406 let base = ty::item_path_str(cx, did);
407 let trait_def = ty::lookup_trait_def(cx, did);
408 let ty = parameterized(cx, base.as_slice(),
409 substs, &trait_def.generics);
410 let bound_sep = if bounds.is_empty() { "" } else { ":" };
411 let bound_str = bounds.repr(cx);
417 ty_str => "str".to_string(),
418 ty_unboxed_closure(..) => "closure".to_string(),
419 ty_vec(ref mt, sz) => {
422 format!("[{}, .. {}]", mt_to_string(cx, mt), n)
424 None => format!("[{}]", ty_to_string(cx, mt.ty)),
430 pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
433 ty::StaticExplicitSelfCategory => "static",
434 ty::ByValueExplicitSelfCategory => "self",
435 ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
438 ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
439 ty::ByBoxExplicitSelfCategory => "Box<self>",
443 pub fn parameterized(cx: &ctxt,
445 substs: &subst::Substs,
446 generics: &ty::Generics)
449 let mut strs = Vec::new();
451 match substs.regions {
452 subst::ErasedRegions => { }
453 subst::NonerasedRegions(ref regions) => {
454 for &r in regions.iter() {
455 let s = region_to_string(cx, "", false, r);
459 // This happens when the value of the region
460 // parameter is not easily serialized. This may be
461 // because the user omitted it in the first place,
462 // or because it refers to some block in the code,
463 // etc. I'm not sure how best to serialize this.
464 strs.push(format!("'_"));
470 let tps = substs.types.get_slice(subst::TypeSpace);
471 let ty_params = generics.types.get_slice(subst::TypeSpace);
472 let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
473 let num_defaults = if has_defaults && !cx.sess.verbose() {
474 ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
476 Some(default) => default.subst(cx, substs) == actual,
484 for t in tps.slice_to(tps.len() - num_defaults).iter() {
485 strs.push(ty_to_string(cx, *t))
488 if cx.sess.verbose() {
489 for t in substs.types.get_slice(subst::SelfSpace).iter() {
490 strs.push(format!("for {}", t.repr(cx)));
495 format!("{}<{}>", base, strs.connect(","))
501 pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String {
502 let mut s = typ.repr(cx).to_string();
504 s = s.as_slice().slice(0u, 32u).to_string();
509 impl<T:Repr> Repr for Option<T> {
510 fn repr(&self, tcx: &ctxt) -> String {
512 &None => "None".to_string(),
513 &Some(ref t) => t.repr(tcx),
518 impl<T:Repr,U:Repr> Repr for Result<T,U> {
519 fn repr(&self, tcx: &ctxt) -> String {
521 &Ok(ref t) => t.repr(tcx),
522 &Err(ref u) => format!("Err({})", u.repr(tcx))
528 fn repr(&self, _tcx: &ctxt) -> String {
533 impl<T:Repr> Repr for Rc<T> {
534 fn repr(&self, tcx: &ctxt) -> String {
539 impl<T:Repr + 'static> Repr for Gc<T> {
540 fn repr(&self, tcx: &ctxt) -> String {
545 impl<T:Repr> Repr for Box<T> {
546 fn repr(&self, tcx: &ctxt) -> String {
551 fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> String {
552 vec_map_to_string(v, |t| t.repr(tcx))
555 impl<'a, T:Repr> Repr for &'a [T] {
556 fn repr(&self, tcx: &ctxt) -> String {
561 impl<T:Repr> Repr for OwnedSlice<T> {
562 fn repr(&self, tcx: &ctxt) -> String {
563 repr_vec(tcx, self.as_slice())
567 // This is necessary to handle types like Option<~[T]>, for which
568 // autoderef cannot convert the &[T] handler
569 impl<T:Repr> Repr for Vec<T> {
570 fn repr(&self, tcx: &ctxt) -> String {
571 repr_vec(tcx, self.as_slice())
575 impl Repr for def::Def {
576 fn repr(&self, _tcx: &ctxt) -> String {
577 format!("{:?}", *self)
581 impl Repr for ty::TypeParameterDef {
582 fn repr(&self, tcx: &ctxt) -> String {
583 format!("TypeParameterDef({:?}, {})", self.def_id,
584 self.bounds.repr(tcx))
588 impl Repr for ty::RegionParameterDef {
589 fn repr(&self, _tcx: &ctxt) -> String {
590 format!("RegionParameterDef({}, {:?})",
591 token::get_name(self.name),
596 impl Repr for ty::t {
597 fn repr(&self, tcx: &ctxt) -> String {
598 ty_to_string(tcx, *self)
602 impl Repr for ty::mt {
603 fn repr(&self, tcx: &ctxt) -> String {
604 mt_to_string(tcx, self)
608 impl Repr for subst::Substs {
609 fn repr(&self, tcx: &ctxt) -> String {
610 format!("Substs[types={}, regions={}]",
611 self.types.repr(tcx),
612 self.regions.repr(tcx))
616 impl<T:Repr> Repr for subst::VecPerParamSpace<T> {
617 fn repr(&self, tcx: &ctxt) -> String {
618 format!("[{};{};{}]",
619 self.get_slice(subst::TypeSpace).repr(tcx),
620 self.get_slice(subst::SelfSpace).repr(tcx),
621 self.get_slice(subst::FnSpace).repr(tcx))
625 impl Repr for ty::ItemSubsts {
626 fn repr(&self, tcx: &ctxt) -> String {
627 format!("ItemSubsts({})", self.substs.repr(tcx))
631 impl Repr for subst::RegionSubsts {
632 fn repr(&self, tcx: &ctxt) -> String {
634 subst::ErasedRegions => "erased".to_string(),
635 subst::NonerasedRegions(ref regions) => regions.repr(tcx)
640 impl Repr for ty::ParamBounds {
641 fn repr(&self, tcx: &ctxt) -> String {
642 let mut res = Vec::new();
643 for b in self.builtin_bounds.iter() {
645 ty::BoundStatic => "'static".to_string(),
646 ty::BoundSend => "Send".to_string(),
647 ty::BoundSized => "Sized".to_string(),
648 ty::BoundCopy => "Copy".to_string(),
649 ty::BoundSync => "Sync".to_string(),
652 for t in self.trait_bounds.iter() {
653 res.push(t.repr(tcx));
659 impl Repr for ty::TraitRef {
660 fn repr(&self, tcx: &ctxt) -> String {
661 trait_ref_to_string(tcx, self)
665 impl Repr for ast::Expr {
666 fn repr(&self, _tcx: &ctxt) -> String {
667 format!("expr({}: {})", self.id, pprust::expr_to_string(self))
671 impl Repr for ast::Path {
672 fn repr(&self, _tcx: &ctxt) -> String {
673 format!("path({})", pprust::path_to_string(self))
677 impl Repr for ast::Item {
678 fn repr(&self, tcx: &ctxt) -> String {
679 format!("item({})", tcx.map.node_to_string(self.id))
683 impl Repr for ast::Stmt {
684 fn repr(&self, _tcx: &ctxt) -> String {
685 format!("stmt({}: {})",
686 ast_util::stmt_id(self),
687 pprust::stmt_to_string(self))
691 impl Repr for ast::Pat {
692 fn repr(&self, _tcx: &ctxt) -> String {
693 format!("pat({}: {})", self.id, pprust::pat_to_string(self))
697 impl Repr for ty::BoundRegion {
698 fn repr(&self, tcx: &ctxt) -> String {
700 ty::BrAnon(id) => format!("BrAnon({})", id),
701 ty::BrNamed(id, name) => {
702 format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
704 ty::BrFresh(id) => format!("BrFresh({})", id),
709 impl Repr for ty::Region {
710 fn repr(&self, tcx: &ctxt) -> String {
712 ty::ReEarlyBound(id, space, index, name) => {
713 format!("ReEarlyBound({}, {}, {}, {})",
717 token::get_name(name))
720 ty::ReLateBound(binder_id, ref bound_region) => {
721 format!("ReLateBound({}, {})",
723 bound_region.repr(tcx))
726 ty::ReFree(ref fr) => {
727 format!("ReFree({}, {})",
729 fr.bound_region.repr(tcx))
733 format!("ReScope({})", id)
737 "ReStatic".to_string()
740 ty::ReInfer(ReVar(ref vid)) => {
741 format!("ReInfer({})", vid.index)
744 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
745 format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
749 "ReEmpty".to_string()
755 impl Repr for ast::DefId {
756 fn repr(&self, tcx: &ctxt) -> String {
757 // Unfortunately, there seems to be no way to attempt to print
758 // a path for a def-id, so I'll just make a best effort for now
759 // and otherwise fallback to just printing the crate/node pair
760 if self.krate == ast::LOCAL_CRATE {
762 match tcx.map.find(self.node) {
763 Some(ast_map::NodeItem(..)) |
764 Some(ast_map::NodeForeignItem(..)) |
765 Some(ast_map::NodeImplItem(..)) |
766 Some(ast_map::NodeTraitItem(..)) |
767 Some(ast_map::NodeVariant(..)) |
768 Some(ast_map::NodeStructCtor(..)) => {
772 ty::item_path_str(tcx, *self))
778 return format!("{:?}", *self)
782 impl Repr for ty::Polytype {
783 fn repr(&self, tcx: &ctxt) -> String {
784 format!("Polytype {{generics: {}, ty: {}}}",
785 self.generics.repr(tcx),
790 impl Repr for ty::Generics {
791 fn repr(&self, tcx: &ctxt) -> String {
792 format!("Generics(types: {}, regions: {})",
793 self.types.repr(tcx),
794 self.regions.repr(tcx))
798 impl Repr for ty::ItemVariances {
799 fn repr(&self, tcx: &ctxt) -> String {
800 format!("ItemVariances(types={}, \
802 self.types.repr(tcx),
803 self.regions.repr(tcx))
807 impl Repr for ty::Variance {
808 fn repr(&self, _: &ctxt) -> String {
809 // The first `.to_string()` returns a &'static str (it is not an implementation
810 // of the ToString trait). Because of that, we need to call `.to_string()` again
811 // if we want to have a `String`.
812 self.to_string().to_string()
816 impl Repr for ty::Method {
817 fn repr(&self, tcx: &ctxt) -> String {
818 format!("method(ident: {}, generics: {}, fty: {}, \
819 explicit_self: {}, vis: {}, def_id: {})",
820 self.ident.repr(tcx),
821 self.generics.repr(tcx),
823 self.explicit_self.repr(tcx),
825 self.def_id.repr(tcx))
829 impl Repr for ast::Name {
830 fn repr(&self, _tcx: &ctxt) -> String {
831 token::get_name(*self).get().to_string()
835 impl Repr for ast::Ident {
836 fn repr(&self, _tcx: &ctxt) -> String {
837 token::get_ident(*self).get().to_string()
841 impl Repr for ast::ExplicitSelf_ {
842 fn repr(&self, _tcx: &ctxt) -> String {
843 format!("{:?}", *self)
847 impl Repr for ast::Visibility {
848 fn repr(&self, _tcx: &ctxt) -> String {
849 format!("{:?}", *self)
853 impl Repr for ty::BareFnTy {
854 fn repr(&self, tcx: &ctxt) -> String {
855 format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
857 self.abi.to_string(),
862 impl Repr for ty::FnSig {
863 fn repr(&self, tcx: &ctxt) -> String {
864 fn_sig_to_string(tcx, self)
868 impl Repr for typeck::MethodCallee {
869 fn repr(&self, tcx: &ctxt) -> String {
870 format!("MethodCallee {{origin: {}, ty: {}, {}}}",
871 self.origin.repr(tcx),
873 self.substs.repr(tcx))
877 impl Repr for typeck::MethodOrigin {
878 fn repr(&self, tcx: &ctxt) -> String {
880 &typeck::MethodStatic(def_id) => {
881 format!("MethodStatic({})", def_id.repr(tcx))
883 &typeck::MethodStaticUnboxedClosure(def_id) => {
884 format!("MethodStaticUnboxedClosure({})", def_id.repr(tcx))
886 &typeck::MethodParam(ref p) => {
889 &typeck::MethodObject(ref p) => {
896 impl Repr for typeck::MethodParam {
897 fn repr(&self, tcx: &ctxt) -> String {
898 format!("MethodParam({},{:?},{:?},{:?})",
899 self.trait_id.repr(tcx),
906 impl Repr for typeck::MethodObject {
907 fn repr(&self, tcx: &ctxt) -> String {
908 format!("MethodObject({},{:?},{:?})",
909 self.trait_id.repr(tcx),
915 impl Repr for ty::TraitStore {
916 fn repr(&self, tcx: &ctxt) -> String {
917 trait_store_to_string(tcx, *self)
921 impl Repr for ty::BuiltinBound {
922 fn repr(&self, _tcx: &ctxt) -> String {
923 format!("{:?}", *self)
927 impl UserString for ty::BuiltinBound {
928 fn user_string(&self, _tcx: &ctxt) -> String {
930 ty::BoundStatic => "'static".to_string(),
931 ty::BoundSend => "Send".to_string(),
932 ty::BoundSized => "Sized".to_string(),
933 ty::BoundCopy => "Copy".to_string(),
934 ty::BoundSync => "Sync".to_string(),
939 impl Repr for ty::BuiltinBounds {
940 fn repr(&self, tcx: &ctxt) -> String {
941 self.user_string(tcx)
946 fn repr(&self, tcx: &ctxt) -> String {
947 tcx.sess.codemap().span_to_string(*self).to_string()
951 impl<A:UserString> UserString for Rc<A> {
952 fn user_string(&self, tcx: &ctxt) -> String {
953 let this: &A = &**self;
954 this.user_string(tcx)
958 impl UserString for ty::BuiltinBounds {
959 fn user_string(&self, tcx: &ctxt) -> String {
961 .map(|bb| bb.user_string(tcx))
962 .collect::<Vec<String>>()
968 impl UserString for ty::TraitRef {
969 fn user_string(&self, tcx: &ctxt) -> String {
970 let base = ty::item_path_str(tcx, self.def_id);
971 let trait_def = ty::lookup_trait_def(tcx, self.def_id);
972 parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
976 impl UserString for ty::t {
977 fn user_string(&self, tcx: &ctxt) -> String {
978 ty_to_string(tcx, *self)
982 impl UserString for ast::Ident {
983 fn user_string(&self, _tcx: &ctxt) -> String {
984 token::get_name(self.name).get().to_string()
988 impl Repr for abi::Abi {
989 fn repr(&self, _tcx: &ctxt) -> String {
994 impl UserString for abi::Abi {
995 fn user_string(&self, _tcx: &ctxt) -> String {
1000 impl Repr for ty::UpvarId {
1001 fn repr(&self, tcx: &ctxt) -> String {
1002 format!("UpvarId({};`{}`;{})",
1004 ty::local_var_name_str(tcx, self.var_id),
1005 self.closure_expr_id)
1009 impl Repr for ast::Mutability {
1010 fn repr(&self, _tcx: &ctxt) -> String {
1011 format!("{:?}", *self)
1015 impl Repr for ty::BorrowKind {
1016 fn repr(&self, _tcx: &ctxt) -> String {
1017 format!("{:?}", *self)
1021 impl Repr for ty::UpvarBorrow {
1022 fn repr(&self, tcx: &ctxt) -> String {
1023 format!("UpvarBorrow({}, {})",
1024 self.kind.repr(tcx),
1025 self.region.repr(tcx))
1029 impl Repr for ty::IntVid {
1030 fn repr(&self, _tcx: &ctxt) -> String {
1035 impl Repr for ty::FloatVid {
1036 fn repr(&self, _tcx: &ctxt) -> String {
1041 impl Repr for ty::RegionVid {
1042 fn repr(&self, _tcx: &ctxt) -> String {
1047 impl Repr for ty::TyVid {
1048 fn repr(&self, _tcx: &ctxt) -> String {
1053 impl Repr for ty::IntVarValue {
1054 fn repr(&self, _tcx: &ctxt) -> String {
1055 format!("{:?}", *self)
1059 impl Repr for ast::IntTy {
1060 fn repr(&self, _tcx: &ctxt) -> String {
1061 format!("{:?}", *self)
1065 impl Repr for ast::UintTy {
1066 fn repr(&self, _tcx: &ctxt) -> String {
1067 format!("{:?}", *self)
1071 impl Repr for ast::FloatTy {
1072 fn repr(&self, _tcx: &ctxt) -> String {
1073 format!("{:?}", *self)
1077 impl<T:Repr> Repr for infer::Bounds<T> {
1078 fn repr(&self, tcx: &ctxt) -> String {
1079 format!("({} <= {})",
1085 impl<K:Repr,V:Repr> Repr for VV<K,V> {
1086 fn repr(&self, tcx: &ctxt) -> String {
1088 unify::Redirect(ref k) =>
1089 format!("Redirect({})", k.repr(tcx)),
1090 unify::Root(ref v, r) =>
1091 format!("Root({}, {})", v.repr(tcx), r)
1096 impl Repr for region_inference::VarValue {
1097 fn repr(&self, tcx: &ctxt) -> String {
1099 infer::region_inference::NoValue =>
1101 infer::region_inference::Value(r) =>
1102 format!("Value({})", r.repr(tcx)),
1103 infer::region_inference::ErrorValue =>
1104 format!("ErrorValue"),
1109 impl Repr for ty::ExplicitSelfCategory {
1110 fn repr(&self, _: &ctxt) -> String {
1111 explicit_self_category_to_str(self).to_string()