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::subst::{self, Subst};
13 use middle::ty::{BoundRegion, BrAnon, BrNamed};
14 use middle::ty::{ReEarlyBound, BrFresh, ctxt};
15 use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
16 use middle::ty::{ReSkolemized, ReVar, BrEnv};
17 use middle::ty::{TyBool, TyChar, TyStruct, TyEnum};
18 use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
19 use middle::ty::{TyParam, TyRawPtr, TyRef, TyTuple};
20 use middle::ty::TyClosure;
21 use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
22 use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags};
23 use middle::ty_fold::{self, TypeFoldable};
27 use syntax::parse::token;
28 use syntax::{ast, ast_util};
30 pub fn verbose() -> bool {
31 ty::tls::with(|tcx| tcx.sess.verbose())
34 fn fn_sig(f: &mut fmt::Formatter,
40 let mut inputs = inputs.iter();
41 if let Some(&ty) = inputs.next() {
42 try!(write!(f, "{}", ty));
44 try!(write!(f, ", {}", ty));
47 try!(write!(f, ", ..."));
53 ty::FnConverging(ty) => {
55 try!(write!(f, " -> {}", ty));
65 fn parameterized<GG>(f: &mut fmt::Formatter,
66 substs: &subst::Substs,
68 projections: &[ty::ProjectionPredicate],
71 where GG: for<'tcx> FnOnce(&ty::ctxt<'tcx>) -> ty::Generics<'tcx>
73 let (fn_trait_kind, verbose) = try!(ty::tls::with(|tcx| {
74 try!(write!(f, "{}", tcx.item_path_str(did)));
75 Ok((tcx.lang_items.fn_trait_kind(did), tcx.sess.verbose()))
79 let mut start_or_continue = |f: &mut fmt::Formatter, start: &str, cont: &str| {
82 write!(f, "{}", start)
89 match substs.regions {
90 subst::ErasedRegions => {
91 try!(start_or_continue(f, "<", ", "));
92 try!(write!(f, ".."));
94 subst::NonerasedRegions(ref regions) => {
95 for region in regions {
96 try!(start_or_continue(f, "<", ", "));
97 try!(write!(f, "{:?}", region));
101 for &ty in &substs.types {
102 try!(start_or_continue(f, "<", ", "));
103 try!(write!(f, "{}", ty));
105 for projection in projections {
106 try!(start_or_continue(f, "<", ", "));
107 try!(write!(f, "{}={}",
108 projection.projection_ty.item_name,
111 return start_or_continue(f, "", ">");
114 if fn_trait_kind.is_some() && projections.len() == 1 {
115 let projection_ty = projections[0].ty;
116 if let TyTuple(ref args) = substs.types.get_slice(subst::TypeSpace)[0].sty {
117 return fn_sig(f, args, false, ty::FnConverging(projection_ty));
121 match substs.regions {
122 subst::ErasedRegions => { }
123 subst::NonerasedRegions(ref regions) => {
125 try!(start_or_continue(f, "<", ", "));
126 let s = r.to_string();
128 // This happens when the value of the region
129 // parameter is not easily serialized. This may be
130 // because the user omitted it in the first place,
131 // or because it refers to some block in the code,
132 // etc. I'm not sure how best to serialize this.
133 try!(write!(f, "'_"));
135 try!(write!(f, "{}", s));
141 // It is important to execute this conditionally, only if -Z
142 // verbose is false. Otherwise, debug logs can sometimes cause
143 // ICEs trying to fetch the generics early in the pipeline. This
144 // is kind of a hacky workaround in that -Z verbose is required to
146 let tps = substs.types.get_slice(subst::TypeSpace);
147 let num_defaults = ty::tls::with(|tcx| {
148 let generics = get_generics(tcx);
150 let has_self = substs.self_ty().is_some();
151 let ty_params = generics.types.get_slice(subst::TypeSpace);
152 if ty_params.last().map_or(false, |def| def.default.is_some()) {
153 let substs = tcx.lift(&substs);
154 ty_params.iter().zip(tps).rev().take_while(|&(def, &actual)| {
157 if !has_self && default.has_self_ty() {
158 // In an object type, there is no `Self`, and
159 // thus if the default value references Self,
160 // the user will be required to give an
161 // explicit value. We can't even do the
162 // substitution below to check without causing
166 let default = tcx.lift(&default);
167 substs.and_then(|substs| default.subst(tcx, substs)) == Some(actual)
178 for &ty in &tps[..tps.len() - num_defaults] {
179 try!(start_or_continue(f, "<", ", "));
180 try!(write!(f, "{}", ty));
183 for projection in projections {
184 try!(start_or_continue(f, "<", ", "));
185 try!(write!(f, "{}={}",
186 projection.projection_ty.item_name,
190 start_or_continue(f, "", ">")
193 fn in_binder<'tcx, T, U>(f: &mut fmt::Formatter,
194 tcx: &ty::ctxt<'tcx>,
195 original: &ty::Binder<T>,
196 lifted: Option<ty::Binder<U>>) -> fmt::Result
197 where T: fmt::Display, U: fmt::Display + TypeFoldable<'tcx>
199 // Replace any anonymous late-bound regions with named
200 // variants, using gensym'd identifiers, so that we can
201 // clearly differentiate between named and unnamed regions in
202 // the output. We'll probably want to tweak this over time to
203 // decide just how much information to give.
204 let value = if let Some(v) = lifted {
207 return write!(f, "{}", original.0);
210 let mut empty = true;
211 let mut start_or_continue = |f: &mut fmt::Formatter, start: &str, cont: &str| {
214 write!(f, "{}", start)
216 write!(f, "{}", cont)
220 let new_value = ty_fold::replace_late_bound_regions(tcx, &value, |br| {
221 let _ = start_or_continue(f, "for<", ", ");
222 ty::ReLateBound(ty::DebruijnIndex::new(1), match br {
223 ty::BrNamed(_, name) => {
224 let _ = write!(f, "{}", name);
230 let name = token::intern("'r");
231 let _ = write!(f, "{}", name);
232 ty::BrNamed(ast_util::local_def(ast::DUMMY_NODE_ID), name)
237 try!(start_or_continue(f, "", "> "));
238 write!(f, "{}", new_value)
241 /// This curious type is here to help pretty-print trait objects. In
242 /// a trait object, the projections are stored separately from the
243 /// main trait bound, but in fact we want to package them together
244 /// when printing out; they also have separate binders, but we want
245 /// them to share a binder when we print them out. (And the binder
246 /// pretty-printing logic is kind of clever and we don't want to
247 /// reproduce it.) So we just repackage up the structure somewhat.
249 /// Right now there is only one trait in an object that can have
250 /// projection bounds, so we just stuff them altogether. But in
251 /// reality we should eventually sort things out better.
252 #[derive(Clone, Debug)]
253 struct TraitAndProjections<'tcx>(ty::TraitRef<'tcx>, Vec<ty::ProjectionPredicate<'tcx>>);
255 impl<'tcx> TypeFoldable<'tcx> for TraitAndProjections<'tcx> {
256 fn fold_with<F:ty_fold::TypeFolder<'tcx>>(&self, folder: &mut F)
257 -> TraitAndProjections<'tcx> {
258 TraitAndProjections(self.0.fold_with(folder), self.1.fold_with(folder))
262 impl<'tcx> fmt::Display for TraitAndProjections<'tcx> {
263 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
264 let TraitAndProjections(ref trait_ref, ref projection_bounds) = *self;
265 parameterized(f, trait_ref.substs,
268 |tcx| tcx.lookup_trait_def(trait_ref.def_id).generics.clone())
272 impl<'tcx> fmt::Display for ty::TraitTy<'tcx> {
273 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
274 let bounds = &self.bounds;
276 // Generate the main trait ref, including associated types.
277 try!(ty::tls::with(|tcx| {
278 let principal = tcx.lift(&self.principal.0)
279 .expect("could not lift TraitRef for printing");
280 let projections = tcx.lift(&bounds.projection_bounds[..])
281 .expect("could not lift projections for printing");
282 let projections = projections.into_iter().map(|p| p.0).collect();
284 let tap = ty::Binder(TraitAndProjections(principal, projections));
285 in_binder(f, tcx, &ty::Binder(""), Some(tap))
289 for bound in &bounds.builtin_bounds {
290 try!(write!(f, " + {:?}", bound));
293 // FIXME: It'd be nice to compute from context when this bound
294 // is implied, but that's non-trivial -- we'd perhaps have to
295 // use thread-local data of some kind? There are also
296 // advantages to just showing the region, since it makes
297 // people aware that it's there.
298 let bound = bounds.region_bound.to_string();
299 if !bound.is_empty() {
300 try!(write!(f, " + {}", bound));
307 impl<'tcx> fmt::Debug for ty::TypeParameterDef<'tcx> {
308 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
309 write!(f, "TypeParameterDef({:?}, {:?}/{})",
310 self.def_id, self.space, self.index)
314 impl<'tcx> fmt::Debug for ty::TyS<'tcx> {
315 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
316 write!(f, "{}", *self)
320 impl<'tcx> fmt::Display for ty::TypeAndMut<'tcx> {
321 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
323 if self.mutbl == ast::MutMutable { "mut " } else { "" },
328 impl<'tcx> fmt::Debug for subst::Substs<'tcx> {
329 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
330 write!(f, "Substs[types={:?}, regions={:?}]",
331 self.types, self.regions)
335 impl<'tcx> fmt::Debug for ty::ItemSubsts<'tcx> {
336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
337 write!(f, "ItemSubsts({:?})", self.substs)
341 impl fmt::Debug for subst::RegionSubsts {
342 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
344 subst::ErasedRegions => write!(f, "erased"),
345 subst::NonerasedRegions(ref regions) => write!(f, "{:?}", regions)
350 impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
351 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
352 // when printing out the debug representation, we don't need
353 // to enumerate the `for<...>` etc because the debruijn index
354 // tells you everything you need to know.
355 match self.substs.self_ty() {
356 None => write!(f, "{}", *self),
357 Some(self_ty) => write!(f, "<{:?} as {}>", self_ty, *self)
362 impl<'tcx> fmt::Debug for ty::TraitDef<'tcx> {
363 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
364 write!(f, "TraitDef(generics={:?}, trait_ref={:?})",
365 self.generics, self.trait_ref)
369 impl<'tcx, 'container> fmt::Debug for ty::AdtDefData<'tcx, 'container> {
370 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
371 ty::tls::with(|tcx| {
372 write!(f, "{}", tcx.item_path_str(self.did))
377 impl fmt::Display for ty::BoundRegion {
378 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
380 return write!(f, "{:?}", *self);
384 BrNamed(_, name) => write!(f, "{}", name),
385 BrAnon(_) | BrFresh(_) | BrEnv => Ok(())
390 impl fmt::Debug for ty::Region {
391 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
393 ty::ReEarlyBound(ref data) => {
394 write!(f, "ReEarlyBound({}, {:?}, {}, {})",
401 ty::ReLateBound(binder_id, ref bound_region) => {
402 write!(f, "ReLateBound({:?}, {:?})",
407 ty::ReFree(ref fr) => write!(f, "{:?}", fr),
410 write!(f, "ReScope({:?})", id)
413 ty::ReStatic => write!(f, "ReStatic"),
415 ty::ReInfer(ReVar(ref vid)) => {
416 write!(f, "{:?}", vid)
419 ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
420 write!(f, "ReSkolemized({}, {:?})", id, bound_region)
423 ty::ReEmpty => write!(f, "ReEmpty")
428 impl fmt::Display for ty::Region {
429 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
431 return write!(f, "{:?}", *self);
434 // These printouts are concise. They do not contain all the information
435 // the user might want to diagnose an error, but there is basically no way
436 // to fit that into a short string. Hence the recommendation to use
437 // `explain_region()` or `note_and_explain_region()`.
439 ty::ReEarlyBound(ref data) => {
440 write!(f, "{}", data.name)
442 ty::ReLateBound(_, br) |
443 ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
444 ty::ReInfer(ReSkolemized(_, br)) => {
448 ty::ReInfer(ReVar(_)) => Ok(()),
449 ty::ReStatic => write!(f, "'static"),
450 ty::ReEmpty => write!(f, "'<empty>"),
455 impl fmt::Debug for ty::FreeRegion {
456 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
457 write!(f, "ReFree({:?}, {:?})",
458 self.scope, self.bound_region)
462 impl fmt::Debug for ty::ItemVariances {
463 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
464 write!(f, "ItemVariances(types={:?}, regions={:?})",
465 self.types, self.regions)
469 impl<'tcx> fmt::Debug for ty::GenericPredicates<'tcx> {
470 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
471 write!(f, "GenericPredicates({:?})", self.predicates)
475 impl<'tcx> fmt::Debug for ty::InstantiatedPredicates<'tcx> {
476 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
477 write!(f, "InstantiatedPredicates({:?})",
482 impl<'tcx> fmt::Debug for ty::ImplOrTraitItem<'tcx> {
483 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
484 try!(write!(f, "ImplOrTraitItem("));
486 ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
487 ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
488 ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
494 impl<'tcx> fmt::Display for ty::FnSig<'tcx> {
495 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
496 try!(write!(f, "fn"));
497 fn_sig(f, &self.inputs, self.variadic, self.output)
501 impl<'tcx> fmt::Debug for ty::ExistentialBounds<'tcx> {
502 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
503 let mut empty = true;
504 let mut maybe_continue = |f: &mut fmt::Formatter| {
513 let region_str = format!("{:?}", self.region_bound);
514 if !region_str.is_empty() {
515 try!(maybe_continue(f));
516 try!(write!(f, "{}", region_str));
519 for bound in &self.builtin_bounds {
520 try!(maybe_continue(f));
521 try!(write!(f, "{:?}", bound));
524 for projection_bound in &self.projection_bounds {
525 try!(maybe_continue(f));
526 try!(write!(f, "{:?}", projection_bound));
533 impl fmt::Display for ty::BuiltinBounds {
534 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
535 let mut bounds = self.iter();
536 if let Some(bound) = bounds.next() {
537 try!(write!(f, "{:?}", bound));
538 for bound in bounds {
539 try!(write!(f, " + {:?}", bound));
546 // The generic impl doesn't work yet because projections are not
547 // normalized under HRTB.
548 /*impl<T> fmt::Display for ty::Binder<T>
549 where T: fmt::Display + for<'a> ty::Lift<'a>,
550 for<'a> <T as ty::Lift<'a>>::Lifted: fmt::Display + TypeFoldable<'a>
552 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
553 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
557 impl<'tcx> fmt::Display for ty::Binder<ty::TraitRef<'tcx>> {
558 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
559 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
563 impl<'tcx> fmt::Display for ty::Binder<ty::TraitPredicate<'tcx>> {
564 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
565 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
569 impl<'tcx> fmt::Display for ty::Binder<ty::EquatePredicate<'tcx>> {
570 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
571 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
575 impl<'tcx> fmt::Display for ty::Binder<ty::ProjectionPredicate<'tcx>> {
576 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
577 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
581 impl<'tcx> fmt::Display for ty::Binder<ty::OutlivesPredicate<Ty<'tcx>, ty::Region>> {
582 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
583 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
587 impl fmt::Display for ty::Binder<ty::OutlivesPredicate<ty::Region, ty::Region>> {
588 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
589 ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
593 impl<'tcx> fmt::Display for ty::TraitRef<'tcx> {
594 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
595 parameterized(f, self.substs, self.def_id, &[],
596 |tcx| tcx.lookup_trait_def(self.def_id).generics.clone())
600 impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
601 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
603 TyBool => write!(f, "bool"),
604 TyChar => write!(f, "char"),
605 TyInt(t) => write!(f, "{}", ast_util::int_ty_to_string(t, None)),
606 TyUint(t) => write!(f, "{}", ast_util::uint_ty_to_string(t, None)),
607 TyFloat(t) => write!(f, "{}", ast_util::float_ty_to_string(t)),
608 TyBox(typ) => write!(f, "Box<{}>", typ),
609 TyRawPtr(ref tm) => {
610 write!(f, "*{} {}", match tm.mutbl {
611 ast::MutMutable => "mut",
612 ast::MutImmutable => "const",
615 TyRef(r, ref tm) => {
616 try!(write!(f, "&"));
617 let s = r.to_string();
618 try!(write!(f, "{}", s));
620 try!(write!(f, " "));
624 TyTuple(ref tys) => {
625 try!(write!(f, "("));
626 let mut tys = tys.iter();
627 if let Some(&ty) = tys.next() {
628 try!(write!(f, "{},", ty));
629 if let Some(&ty) = tys.next() {
630 try!(write!(f, " {}", ty));
632 try!(write!(f, ", {}", ty));
638 TyBareFn(opt_def_id, ref bare_fn) => {
639 if bare_fn.unsafety == ast::Unsafety::Unsafe {
640 try!(write!(f, "unsafe "));
643 if bare_fn.abi != abi::Rust {
644 try!(write!(f, "extern {} ", bare_fn.abi));
647 try!(write!(f, "{}", bare_fn.sig.0));
649 if let Some(def_id) = opt_def_id {
650 try!(write!(f, " {{{}}}", ty::tls::with(|tcx| {
651 tcx.item_path_str(def_id)
656 TyInfer(infer_ty) => write!(f, "{}", infer_ty),
657 TyError => write!(f, "[type error]"),
658 TyParam(ref param_ty) => write!(f, "{}", param_ty),
659 TyEnum(def, substs) | TyStruct(def, substs) => {
660 ty::tls::with(|tcx| {
661 if def.did.krate == ast::LOCAL_CRATE &&
662 !tcx.tcache.borrow().contains_key(&def.did) {
663 write!(f, "{}<..>", tcx.item_path_str(def.did))
665 parameterized(f, substs, def.did, &[],
666 |tcx| tcx.lookup_item_type(def.did).generics)
670 TyTrait(ref data) => write!(f, "{}", data),
671 ty::TyProjection(ref data) => write!(f, "{}", data),
672 TyStr => write!(f, "str"),
673 TyClosure(ref did, ref substs) => ty::tls::with(|tcx| {
674 try!(write!(f, "[closure"));
676 if did.krate == ast::LOCAL_CRATE {
677 try!(write!(f, "@{:?}", tcx.map.span(did.node)));
679 try!(tcx.with_freevars(did.node, |freevars| {
680 for (freevar, upvar_ty) in freevars.iter().zip(&substs.upvar_tys) {
681 let node_id = freevar.def.local_node_id();
685 tcx.local_var_name_str(node_id),
692 // cross-crate closure types should only be
693 // visible in trans bug reports, I imagine.
694 try!(write!(f, "@{:?}", did));
696 for (index, upvar_ty) in substs.upvar_tys.iter().enumerate() {
697 try!(write!(f, "{}{}:{}", sep, index, upvar_ty));
704 TyArray(ty, sz) => write!(f, "[{}; {}]", ty, sz),
705 TySlice(ty) => write!(f, "[{}]", ty)
710 impl<'tcx> fmt::Display for ty::TyS<'tcx> {
711 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
712 write!(f, "{}", self.sty)
716 impl fmt::Debug for ty::UpvarId {
717 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
718 write!(f, "UpvarId({};`{}`;{})",
720 ty::tls::with(|tcx| tcx.local_var_name_str(self.var_id)),
721 self.closure_expr_id)
725 impl fmt::Debug for ty::UpvarBorrow {
726 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
727 write!(f, "UpvarBorrow({:?}, {:?})",
728 self.kind, self.region)
732 impl fmt::Display for ty::InferTy {
733 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
734 let print_var_ids = verbose();
736 ty::TyVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
737 ty::IntVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
738 ty::FloatVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
739 ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => write!(f, "_"),
740 ty::FreshTy(v) => write!(f, "FreshTy({})", v),
741 ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
742 ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)
747 impl fmt::Display for ty::ExplicitSelfCategory {
748 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
749 f.write_str(match *self {
750 ty::StaticExplicitSelfCategory => "static",
751 ty::ByValueExplicitSelfCategory => "self",
752 ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
755 ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
756 ty::ByBoxExplicitSelfCategory => "Box<self>",
761 impl fmt::Display for ty::ParamTy {
762 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
763 write!(f, "{}", self.name)
767 impl fmt::Debug for ty::ParamTy {
768 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
769 write!(f, "{}/{:?}.{}", self, self.space, self.idx)
773 impl<'tcx, T, U> fmt::Display for ty::OutlivesPredicate<T,U>
774 where T: fmt::Display, U: fmt::Display
776 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
777 write!(f, "{} : {}", self.0, self.1)
781 impl<'tcx> fmt::Display for ty::EquatePredicate<'tcx> {
782 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
783 write!(f, "{} == {}", self.0, self.1)
787 impl<'tcx> fmt::Debug for ty::TraitPredicate<'tcx> {
788 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
789 write!(f, "TraitPredicate({:?})",
794 impl<'tcx> fmt::Display for ty::TraitPredicate<'tcx> {
795 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
797 self.trait_ref.self_ty(),
802 impl<'tcx> fmt::Debug for ty::ProjectionPredicate<'tcx> {
803 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
804 write!(f, "ProjectionPredicate({:?}, {:?})",
810 impl<'tcx> fmt::Display for ty::ProjectionPredicate<'tcx> {
811 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
812 write!(f, "{} == {}",
818 impl<'tcx> fmt::Display for ty::ProjectionTy<'tcx> {
819 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
820 write!(f, "{:?}::{}",
826 impl<'tcx> fmt::Display for ty::Predicate<'tcx> {
827 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
829 ty::Predicate::Trait(ref data) => write!(f, "{}", data),
830 ty::Predicate::Equate(ref predicate) => write!(f, "{}", predicate),
831 ty::Predicate::RegionOutlives(ref predicate) => write!(f, "{}", predicate),
832 ty::Predicate::TypeOutlives(ref predicate) => write!(f, "{}", predicate),
833 ty::Predicate::Projection(ref predicate) => write!(f, "{}", predicate),