1 use crate::hir::def::Namespace;
2 use crate::hir::def_id::DefId;
3 use crate::ty::subst::{Kind, Subst, SubstsRef, UnpackedKind};
4 use crate::ty::{self, ParamConst, Ty, TypeFoldable};
5 use crate::ty::print::{FmtPrinter, PrettyPrinter, PrintCx, Print, Printer};
6 use crate::mir::interpret::ConstValue;
8 use std::fmt::{self, Write as _};
12 use rustc_target::spec::abi::Abi;
13 use syntax::ast::CRATE_NODE_ID;
14 use syntax::symbol::{Symbol, InternedString};
17 macro_rules! gen_display_debug_body {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
21 $with(&cx.tcx.lift(self).expect("could not lift for printing"), cx)?;
27 macro_rules! gen_display_debug {
28 ( ($($x:tt)+) $target:ty, display yes ) => {
29 impl<$($x)+> fmt::Display for $target {
30 gen_display_debug_body! { Print::print_display }
33 ( () $target:ty, display yes ) => {
34 impl fmt::Display for $target {
35 gen_display_debug_body! { Print::print_display }
38 ( ($($x:tt)+) $target:ty, debug yes ) => {
39 impl<$($x)+> fmt::Debug for $target {
40 gen_display_debug_body! { Print::print_debug }
43 ( () $target:ty, debug yes ) => {
44 impl fmt::Debug for $target {
45 gen_display_debug_body! { Print::print_debug }
48 ( $generic:tt $target:ty, $t:ident no ) => {};
50 macro_rules! gen_print_impl {
51 ( ($($x:tt)+) $target:ty, ($self:ident, $cx:ident) $disp:block $dbg:block ) => {
52 impl<$($x)+, P: PrettyPrinter> Print<'tcx, P> for $target {
54 type Error = fmt::Error;
55 fn print(&$self, $cx: PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error> {
59 define_scoped_cx!($cx);
61 if $cx.config.is_debug $dbg
68 ( () $target:ty, ($self:ident, $cx:ident) $disp:block $dbg:block ) => {
69 impl<P: PrettyPrinter> Print<'tcx, P> for $target {
71 type Error = fmt::Error;
72 fn print(&$self, $cx: PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error> {
76 define_scoped_cx!($cx);
78 if $cx.config.is_debug $dbg
85 ( $generic:tt $target:ty,
86 $vars:tt $gendisp:ident $disp:block $gendbg:ident $dbg:block ) => {
87 gen_print_impl! { $generic $target, $vars $disp $dbg }
88 gen_display_debug! { $generic $target, display $gendisp }
89 gen_display_debug! { $generic $target, debug $gendbg }
92 macro_rules! define_print {
93 ( $generic:tt $target:ty,
94 $vars:tt { display $disp:block debug $dbg:block } ) => {
95 gen_print_impl! { $generic $target, $vars yes $disp yes $dbg }
97 ( $generic:tt $target:ty,
98 $vars:tt { debug $dbg:block display $disp:block } ) => {
99 gen_print_impl! { $generic $target, $vars yes $disp yes $dbg }
101 ( $generic:tt $target:ty,
102 $vars:tt { debug $dbg:block } ) => {
103 gen_print_impl! { $generic $target, $vars no {
104 bug!(concat!("display not implemented for ", stringify!($target)));
107 ( $generic:tt $target:ty,
108 ($self:ident, $cx:ident) { display $disp:block } ) => {
109 gen_print_impl! { $generic $target, ($self, $cx) yes $disp no {
110 write!($cx.printer, "{:?}", $self)?
114 macro_rules! define_print_multi {
115 ( [ $($generic:tt $target:ty),* ] $vars:tt $def:tt ) => {
116 $(define_print! { $generic $target, $vars $def })*
121 scoped_cx!() = scoped_cx!().nest($closure)?
124 macro_rules! print_inner {
125 (write ($($data:expr),+)) => {
126 write!(scoped_cx!().printer, $($data),+)?
128 ($kind:ident ($data:expr)) => {
129 nest!(|cx| $data.$kind(cx))
133 ($($kind:ident $data:tt),+) => {
135 $(print_inner!($kind $data));+
139 macro_rules! define_scoped_cx {
141 #[allow(unused_macros)]
142 macro_rules! scoped_cx {
148 impl<P: PrettyPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
154 ) -> Result<P, fmt::Error> {
155 define_scoped_cx!(self);
158 let mut inputs = inputs.iter();
159 if let Some(&ty) = inputs.next() {
160 p!(print_display(ty));
162 p!(write(", "), print_display(ty));
169 if !output.is_unit() {
170 p!(write(" -> "), print_display(output));
176 fn in_binder<T>(mut self, value: &ty::Binder<T>) -> Result<P, fmt::Error>
177 where T: Print<'tcx, P, Output = P, Error = fmt::Error> + TypeFoldable<'tcx>
179 fn name_by_region_index(index: usize) -> InternedString {
181 0 => Symbol::intern("'r"),
182 1 => Symbol::intern("'s"),
183 i => Symbol::intern(&format!("'t{}", i-2)),
187 // Replace any anonymous late-bound regions with named
188 // variants, using gensym'd identifiers, so that we can
189 // clearly differentiate between named and unnamed regions in
190 // the output. We'll probably want to tweak this over time to
191 // decide just how much information to give.
192 if self.config.binder_depth == 0 {
193 self.prepare_late_bound_region_info(value);
196 let mut empty = true;
197 let mut start_or_continue = |cx: &mut Self, start: &str, cont: &str| {
198 write!(cx.printer, "{}", if empty {
206 // NOTE(eddyb) this must be below `start_or_continue`'s definition
207 // as that also has a `define_scoped_cx` and that kind of shadowing
208 // is disallowed (name resolution thinks `scoped_cx!` is ambiguous).
209 define_scoped_cx!(self);
211 let old_region_index = self.config.region_index;
212 let mut region_index = old_region_index;
213 let new_value = self.tcx.replace_late_bound_regions(value, |br| {
214 let _ = start_or_continue(&mut self, "for<", ", ");
216 ty::BrNamed(_, name) => {
217 let _ = write!(self.printer, "{}", name);
224 let name = name_by_region_index(region_index);
226 if !self.is_name_used(&name) {
230 let _ = write!(self.printer, "{}", name);
231 ty::BrNamed(self.tcx.hir().local_def_id(CRATE_NODE_ID), name)
234 self.tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br))
236 start_or_continue(&mut self, "", "> ")?;
238 // Push current state to gcx, and restore after writing new_value.
239 self.config.binder_depth += 1;
240 self.config.region_index = region_index;
241 let result = new_value.print_display(PrintCx {
243 printer: self.printer,
246 self.config.region_index = old_region_index;
247 self.config.binder_depth -= 1;
251 fn is_name_used(&self, name: &InternedString) -> bool {
252 match self.config.used_region_names {
253 Some(ref names) => names.contains(name),
259 pub fn parameterized<F: fmt::Write>(
262 substs: SubstsRef<'_>,
265 PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
266 let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
267 cx.print_def_path(did, Some(substs), ns, iter::empty())?;
273 ('tcx) &'tcx ty::List<ty::ExistentialPredicate<'tcx>>, (self, cx) {
275 // Generate the main trait ref, including associated types.
276 let mut first = true;
278 if let Some(principal) = self.principal() {
279 let mut resugared_principal = false;
281 // Special-case `Fn(...) -> ...` and resugar it.
282 let fn_trait_kind = cx.tcx.lang_items().fn_trait_kind(principal.def_id);
283 if !cx.config.is_verbose && fn_trait_kind.is_some() {
284 if let ty::Tuple(ref args) = principal.substs.type_at(0).sty {
285 let mut projections = self.projection_bounds();
286 if let (Some(proj), None) = (projections.next(), projections.next()) {
287 nest!(|cx| cx.print_def_path(
293 nest!(|cx| cx.fn_sig(args, false, proj.ty));
294 resugared_principal = true;
299 if !resugared_principal {
300 // Use a type that can't appear in defaults of type parameters.
301 let dummy_self = cx.tcx.mk_infer(ty::FreshTy(0));
302 let principal = principal.with_self_ty(cx.tcx, dummy_self);
303 nest!(|cx| cx.print_def_path(
305 Some(principal.substs),
307 self.projection_bounds(),
314 // FIXME(eddyb) avoid printing twice (needed to ensure
315 // that the auto traits are sorted *and* printed via cx).
316 let mut auto_traits: Vec<_> = self.auto_traits().map(|did| {
317 (cx.tcx.def_path_str(did), did)
320 // The auto traits come ordered by `DefPathHash`. While
321 // `DefPathHash` is *stable* in the sense that it depends on
322 // neither the host nor the phase of the moon, it depends
323 // "pseudorandomly" on the compiler version and the target.
325 // To avoid that causing instabilities in compiletest
326 // output, sort the auto-traits alphabetically.
329 for (_, def_id) in auto_traits {
335 nest!(|cx| cx.print_def_path(
346 impl fmt::Debug for ty::GenericParamDef {
347 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
348 let type_name = match self.kind {
349 ty::GenericParamDefKind::Lifetime => "Lifetime",
350 ty::GenericParamDefKind::Type { .. } => "Type",
351 ty::GenericParamDefKind::Const => "Const",
353 write!(f, "{}({}, {:?}, {})",
361 impl fmt::Debug for ty::TraitDef {
362 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
363 PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
375 impl fmt::Debug for ty::AdtDef {
376 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
377 PrintCx::with_tls_tcx(FmtPrinter::new(f), |cx| {
389 impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
390 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
391 write!(f, "ClosureUpvar({:?},{:?})",
397 impl fmt::Debug for ty::UpvarId {
398 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
399 PrintCx::with_tls_tcx(FmtPrinter::new(f), |mut cx| {
400 define_scoped_cx!(cx);
401 p!(write("UpvarId({:?};`{}`;{:?})",
402 self.var_path.hir_id,
403 cx.tcx.hir().name_by_hir_id(self.var_path.hir_id),
404 self.closure_expr_id));
410 impl<'tcx> fmt::Debug for ty::UpvarBorrow<'tcx> {
411 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
412 write!(f, "UpvarBorrow({:?}, {:?})",
413 self.kind, self.region)
418 ('tcx) &'tcx ty::List<Ty<'tcx>>, (self, cx) {
421 let mut tys = self.iter();
422 if let Some(&ty) = tys.next() {
425 p!(write(", "), print(ty));
434 ('tcx) ty::TypeAndMut<'tcx>, (self, cx) {
437 write("{}", if self.mutbl == hir::MutMutable { "mut " } else { "" }),
444 ('tcx) ty::ExistentialTraitRef<'tcx>, (self, cx) {
446 let dummy_self = cx.tcx.mk_infer(ty::FreshTy(0));
448 let trait_ref = *ty::Binder::bind(*self)
449 .with_self_ty(cx.tcx, dummy_self)
451 p!(print_display(trait_ref))
454 p!(print_display(self))
460 ('tcx) ty::adjustment::Adjustment<'tcx>, (self, cx) {
462 p!(write("{:?} -> ", self.kind), print(self.target))
467 impl fmt::Debug for ty::BoundRegion {
468 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
470 ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
471 ty::BrFresh(n) => write!(f, "BrFresh({:?})", n),
472 ty::BrNamed(did, name) => {
473 write!(f, "BrNamed({:?}:{:?}, {})",
474 did.krate, did.index, name)
476 ty::BrEnv => write!(f, "BrEnv"),
482 () ty::RegionKind, (self, cx) {
484 return cx.print_region(self);
488 ty::ReEarlyBound(ref data) => {
489 p!(write("ReEarlyBound({}, {})",
494 ty::ReClosureBound(ref vid) => {
495 p!(write("ReClosureBound({:?})", vid))
498 ty::ReLateBound(binder_id, ref bound_region) => {
499 p!(write("ReLateBound({:?}, {:?})", binder_id, bound_region))
502 ty::ReFree(ref fr) => p!(print_debug(fr)),
505 p!(write("ReScope({:?})", id))
508 ty::ReStatic => p!(write("ReStatic")),
510 ty::ReVar(ref vid) => {
511 p!(write("{:?}", vid));
514 ty::RePlaceholder(placeholder) => {
515 p!(write("RePlaceholder({:?})", placeholder))
518 ty::ReEmpty => p!(write("ReEmpty")),
520 ty::ReErased => p!(write("ReErased"))
527 () ty::FreeRegion, (self, cx) {
529 p!(write("ReFree({:?}, {:?})", self.scope, self.bound_region))
535 () ty::Variance, (self, cx) {
537 cx.printer.write_str(match *self {
538 ty::Covariant => "+",
539 ty::Contravariant => "-",
540 ty::Invariant => "o",
541 ty::Bivariant => "*",
548 ('tcx) ty::FnSig<'tcx>, (self, cx) {
550 if self.unsafety == hir::Unsafety::Unsafe {
551 p!(write("unsafe "));
554 if self.abi != Abi::Rust {
555 p!(write("extern {} ", self.abi));
559 nest!(|cx| cx.fn_sig(self.inputs(), self.c_variadic, self.output()));
562 p!(write("({:?}; c_variadic: {})->{:?}",
563 self.inputs(), self.c_variadic, self.output()))
568 impl fmt::Debug for ty::TyVid {
569 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
570 write!(f, "_#{}t", self.index)
574 impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
575 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
576 write!(f, "_#{}f", self.index)
580 impl fmt::Debug for ty::IntVid {
581 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
582 write!(f, "_#{}i", self.index)
586 impl fmt::Debug for ty::FloatVid {
587 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
588 write!(f, "_#{}f", self.index)
592 impl fmt::Debug for ty::RegionVid {
593 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
594 write!(f, "'_#{}r", self.index())
599 () ty::InferTy, (self, cx) {
601 if cx.config.is_verbose {
602 return self.print_debug(cx);
605 ty::TyVar(_) => p!(write("_")),
606 ty::IntVar(_) => p!(write("{}", "{integer}")),
607 ty::FloatVar(_) => p!(write("{}", "{float}")),
608 ty::FreshTy(v) => p!(write("FreshTy({})", v)),
609 ty::FreshIntTy(v) => p!(write("FreshIntTy({})", v)),
610 ty::FreshFloatTy(v) => p!(write("FreshFloatTy({})", v))
615 ty::TyVar(ref v) => p!(write("{:?}", v)),
616 ty::IntVar(ref v) => p!(write("{:?}", v)),
617 ty::FloatVar(ref v) => p!(write("{:?}", v)),
618 ty::FreshTy(v) => p!(write("FreshTy({:?})", v)),
619 ty::FreshIntTy(v) => p!(write("FreshIntTy({:?})", v)),
620 ty::FreshFloatTy(v) => p!(write("FreshFloatTy({:?})", v))
626 impl fmt::Debug for ty::IntVarValue {
627 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
629 ty::IntType(ref v) => v.fmt(f),
630 ty::UintType(ref v) => v.fmt(f),
635 impl fmt::Debug for ty::FloatVarValue {
636 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
641 // The generic impl doesn't work yet because projections are not
642 // normalized under HRTB.
643 /*impl<T> fmt::Display for ty::Binder<T>
644 where T: fmt::Display + for<'a> ty::Lift<'a>,
645 for<'a> <T as ty::Lift<'a>>::Lifted: fmt::Display + TypeFoldable<'a>
647 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
648 PrintCx::with_tls_tcx(|cx| cx.in_binder(cx.tcx.lift(self)
649 .expect("could not lift for printing")))
653 define_print_multi! {
655 ('tcx) ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
656 ('tcx) ty::Binder<ty::TraitRef<'tcx>>,
657 ('tcx) ty::Binder<ty::FnSig<'tcx>>,
658 ('tcx) ty::Binder<ty::TraitPredicate<'tcx>>,
659 ('tcx) ty::Binder<ty::SubtypePredicate<'tcx>>,
660 ('tcx) ty::Binder<ty::ProjectionPredicate<'tcx>>,
661 ('tcx) ty::Binder<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>,
662 ('tcx) ty::Binder<ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>>
666 nest!(|cx| cx.in_binder(self))
672 ('tcx) ty::TraitRef<'tcx>, (self, cx) {
674 nest!(|cx| cx.print_def_path(
682 nest!(|cx| cx.path_qualified(self.self_ty(), Some(*self), Namespace::TypeNS));
687 // FIXME(eddyb) move this to `ty::print`.
688 impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
689 pub fn pretty_print_type(
692 ) -> Result<P::Type, P::Error> {
693 define_scoped_cx!(self);
696 ty::Bool => p!(write("bool")),
697 ty::Char => p!(write("char")),
698 ty::Int(t) => p!(write("{}", t.ty_to_string())),
699 ty::Uint(t) => p!(write("{}", t.ty_to_string())),
700 ty::Float(t) => p!(write("{}", t.ty_to_string())),
701 ty::RawPtr(ref tm) => {
702 p!(write("*{} ", match tm.mutbl {
703 hir::MutMutable => "mut",
704 hir::MutImmutable => "const",
708 ty::Ref(r, ty, mutbl) => {
710 if self.print_region_outputs_anything(r) {
711 p!(print_display(r), write(" "));
713 p!(print(ty::TypeAndMut { ty, mutbl }))
715 ty::Never => p!(write("!")),
716 ty::Tuple(ref tys) => {
718 let mut tys = tys.iter();
719 if let Some(&ty) = tys.next() {
720 p!(print(ty), write(","));
721 if let Some(&ty) = tys.next() {
722 p!(write(" "), print(ty));
724 p!(write(", "), print(ty));
730 ty::FnDef(def_id, substs) => {
731 let sig = self.tcx.fn_sig(def_id).subst(self.tcx, substs);
732 p!(print(sig), write(" {{"));
733 nest!(|cx| cx.print_def_path(
741 ty::FnPtr(ref bare_fn) => {
744 ty::Infer(infer_ty) => p!(write("{}", infer_ty)),
745 ty::Error => p!(write("[type error]")),
746 ty::Param(ref param_ty) => p!(write("{}", param_ty)),
747 ty::Bound(debruijn, bound_ty) => {
748 match bound_ty.kind {
749 ty::BoundTyKind::Anon => {
750 if debruijn == ty::INNERMOST {
751 p!(write("^{}", bound_ty.var.index()))
753 p!(write("^{}_{}", debruijn.index(), bound_ty.var.index()))
757 ty::BoundTyKind::Param(p) => p!(write("{}", p)),
760 ty::Adt(def, substs) => {
761 nest!(|cx| cx.print_def_path(
768 ty::Dynamic(data, r) => {
769 let print_r = self.print_region_outputs_anything(r);
773 p!(write("dyn "), print(data));
775 p!(write(" + "), print_display(r), write(")"));
778 ty::Foreign(def_id) => {
779 nest!(|cx| cx.print_def_path(
786 ty::Projection(ref data) => p!(print(data)),
787 ty::UnnormalizedProjection(ref data) => {
788 p!(write("Unnormalized("), print(data), write(")"))
790 ty::Placeholder(placeholder) => {
791 p!(write("Placeholder({:?})", placeholder))
793 ty::Opaque(def_id, substs) => {
794 if self.config.is_verbose {
795 p!(write("Opaque({:?}, {:?})", def_id, substs));
796 return Ok(self.printer);
799 let def_key = self.tcx.def_key(def_id);
800 if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
801 p!(write("{}", name));
802 let mut substs = substs.iter();
803 // FIXME(eddyb) print this with `print_def_path`.
804 if let Some(first) = substs.next() {
806 p!(print_display(first));
807 for subst in substs {
808 p!(write(", "), print_display(subst));
812 return Ok(self.printer);
814 // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
815 // by looking up the projections associated with the def_id.
816 let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, substs);
818 let mut first = true;
819 let mut is_sized = false;
821 for predicate in bounds.predicates {
822 if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
823 // Don't print +Sized, but rather +?Sized if absent.
824 if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
830 write("{}", if first { " " } else { "+" }),
836 p!(write("{}?Sized", if first { " " } else { "+" }));
841 ty::Str => p!(write("str")),
842 ty::Generator(did, substs, movability) => {
843 let upvar_tys = substs.upvar_tys(did, self.tcx);
844 let witness = substs.witness(did, self.tcx);
845 if movability == hir::GeneratorMovability::Movable {
846 p!(write("[generator"));
848 p!(write("[static generator"));
851 // FIXME(eddyb) should use `def_span`.
852 if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) {
853 p!(write("@{:?}", self.tcx.hir().span_by_hir_id(hir_id)));
855 for (freevar, upvar_ty) in self.tcx.freevars(did)
857 .map_or(&[][..], |fv| &fv[..])
864 self.tcx.hir().name(freevar.var_id())),
869 // cross-crate closure types should only be
870 // visible in codegen bug reports, I imagine.
871 p!(write("@{:?}", did));
873 for (index, upvar_ty) in upvar_tys.enumerate() {
875 write("{}{}:", sep, index),
881 p!(write(" "), print(witness), write("]"))
883 ty::GeneratorWitness(types) => {
884 nest!(|cx| cx.in_binder(&types))
886 ty::Closure(did, substs) => {
887 let upvar_tys = substs.upvar_tys(did, self.tcx);
888 p!(write("[closure"));
890 // FIXME(eddyb) should use `def_span`.
891 if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) {
892 if self.tcx.sess.opts.debugging_opts.span_free_formats {
893 p!(write("@{:?}", hir_id));
895 p!(write("@{:?}", self.tcx.hir().span_by_hir_id(hir_id)));
898 for (freevar, upvar_ty) in self.tcx.freevars(did)
900 .map_or(&[][..], |fv| &fv[..])
907 self.tcx.hir().name(freevar.var_id())),
912 // cross-crate closure types should only be
913 // visible in codegen bug reports, I imagine.
914 p!(write("@{:?}", did));
916 for (index, upvar_ty) in upvar_tys.enumerate() {
918 write("{}{}:", sep, index),
924 if self.config.is_verbose {
926 " closure_kind_ty={:?} closure_sig_ty={:?}",
927 substs.closure_kind_ty(did, self.tcx),
928 substs.closure_sig_ty(did, self.tcx)
934 ty::Array(ty, sz) => {
935 p!(write("["), print(ty), write("; "));
937 ty::LazyConst::Unevaluated(_def_id, _substs) => {
940 ty::LazyConst::Evaluated(c) => {
942 ConstValue::Infer(..) => p!(write("_")),
943 ConstValue::Param(ParamConst { name, .. }) =>
944 p!(write("{}", name)),
945 _ => p!(write("{}", c.unwrap_usize(self.tcx))),
952 p!(write("["), print(ty), write("]"))
961 ('tcx) Ty<'tcx>, (self, cx) {
963 return cx.print_type(self);
966 p!(print_display(self))
972 ('tcx) ConstValue<'tcx>, (self, cx) {
975 ConstValue::Infer(..) => p!(write("_")),
976 ConstValue::Param(ParamConst { name, .. }) => p!(write("{}", name)),
977 _ => p!(write("{:?}", self)),
984 ('tcx) ty::Const<'tcx>, (self, cx) {
986 p!(write("{} : {}", self.val, self.ty))
992 ('tcx) ty::LazyConst<'tcx>, (self, cx) {
995 // FIXME(const_generics) this should print at least the type.
996 ty::LazyConst::Unevaluated(..) => p!(write("_ : _")),
997 ty::LazyConst::Evaluated(c) => p!(write("{}", c)),
1004 () ty::ParamTy, (self, cx) {
1006 p!(write("{}", self.name))
1009 p!(write("{}/#{}", self.name, self.idx))
1015 () ty::ParamConst, (self, cx) {
1017 p!(write("{}", self.name))
1020 p!(write("{}/#{}", self.name, self.index))
1025 // Similar problem to `Binder<T>`, can't define a generic impl.
1026 define_print_multi! {
1028 ('tcx) ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>,
1029 ('tcx) ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>
1033 p!(print(self.0), write(" : "), print(self.1))
1039 ('tcx) ty::SubtypePredicate<'tcx>, (self, cx) {
1041 p!(print(self.a), write(" <: "), print(self.b))
1047 ('tcx) ty::TraitPredicate<'tcx>, (self, cx) {
1049 p!(write("TraitPredicate({:?})",
1053 p!(print(self.trait_ref.self_ty()), write(": "), print(self.trait_ref))
1059 ('tcx) ty::ProjectionPredicate<'tcx>, (self, cx) {
1062 write("ProjectionPredicate("),
1063 print(self.projection_ty),
1069 p!(print(self.projection_ty), write(" == "), print(self.ty))
1075 ('tcx) ty::ProjectionTy<'tcx>, (self, cx) {
1077 nest!(|cx| cx.print_def_path(
1088 () ty::ClosureKind, (self, cx) {
1091 ty::ClosureKind::Fn => p!(write("Fn")),
1092 ty::ClosureKind::FnMut => p!(write("FnMut")),
1093 ty::ClosureKind::FnOnce => p!(write("FnOnce")),
1100 ('tcx) ty::Predicate<'tcx>, (self, cx) {
1103 ty::Predicate::Trait(ref data) => p!(print(data)),
1104 ty::Predicate::Subtype(ref predicate) => p!(print(predicate)),
1105 ty::Predicate::RegionOutlives(ref predicate) => p!(print(predicate)),
1106 ty::Predicate::TypeOutlives(ref predicate) => p!(print(predicate)),
1107 ty::Predicate::Projection(ref predicate) => p!(print(predicate)),
1108 ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")),
1109 ty::Predicate::ObjectSafe(trait_def_id) => {
1110 p!(write("the trait `"));
1111 nest!(|cx| cx.print_def_path(
1117 p!(write("` is object-safe"))
1119 ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
1120 p!(write("the closure `"));
1121 nest!(|cx| cx.print_def_path(
1127 p!(write("` implements the trait `{}`", kind))
1129 ty::Predicate::ConstEvaluatable(def_id, substs) => {
1130 p!(write("the constant `"));
1131 nest!(|cx| cx.print_def_path(
1137 p!(write("` can be evaluated"))
1143 ty::Predicate::Trait(ref a) => p!(print(a)),
1144 ty::Predicate::Subtype(ref pair) => p!(print(pair)),
1145 ty::Predicate::RegionOutlives(ref pair) => p!(print(pair)),
1146 ty::Predicate::TypeOutlives(ref pair) => p!(print(pair)),
1147 ty::Predicate::Projection(ref pair) => p!(print(pair)),
1148 ty::Predicate::WellFormed(ty) => p!(print(ty)),
1149 ty::Predicate::ObjectSafe(trait_def_id) => {
1150 p!(write("ObjectSafe({:?})", trait_def_id))
1152 ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
1153 p!(write("ClosureKind({:?}, {:?}, {:?})",
1154 closure_def_id, closure_substs, kind))
1156 ty::Predicate::ConstEvaluatable(def_id, substs) => {
1157 p!(write("ConstEvaluatable({:?}, {:?})", def_id, substs))
1165 ('tcx) Kind<'tcx>, (self, cx) {
1167 match self.unpack() {
1168 UnpackedKind::Lifetime(lt) => p!(print(lt)),
1169 UnpackedKind::Type(ty) => p!(print(ty)),
1170 UnpackedKind::Const(ct) => p!(print(ct)),
1174 match self.unpack() {
1175 UnpackedKind::Lifetime(lt) => p!(print(lt)),
1176 UnpackedKind::Type(ty) => p!(print(ty)),
1177 UnpackedKind::Const(ct) => p!(print(ct)),