]> git.lizzy.rs Git - rust.git/blob - src/librustc/util/ppaux.rs
Remove unnecessary stat64 pointer casts
[rust.git] / src / librustc / util / ppaux.rs
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.
4 //
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.
10
11 use hir::def_id::DefId;
12 use hir::map::definitions::DefPathData;
13 use middle::const_val::ConstVal;
14 use middle::region::{self, BlockRemainder};
15 use ty::subst::{self, Subst};
16 use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
17 use ty::{TyBool, TyChar, TyAdt};
18 use ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyFnDef, TyFnPtr};
19 use ty::{TyParam, TyRawPtr, TyRef, TyNever, TyTuple};
20 use ty::{TyClosure, TyGenerator, TyGeneratorWitness, TyForeign, TyProjection, TyAnon};
21 use ty::{TyDynamic, TyInt, TyUint, TyInfer};
22 use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
23 use util::nodemap::FxHashSet;
24
25 use std::cell::Cell;
26 use std::fmt;
27 use std::usize;
28
29 use rustc_data_structures::indexed_vec::Idx;
30 use rustc_target::spec::abi::Abi;
31 use syntax::ast::CRATE_NODE_ID;
32 use syntax::symbol::{Symbol, InternedString};
33 use hir;
34
35 macro_rules! gen_display_debug_body {
36     ( $with:path ) => {
37         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38             let mut cx = PrintContext::new();
39             $with(self, f, &mut cx)
40         }
41     };
42 }
43 macro_rules! gen_display_debug {
44     ( ($($x:tt)+) $target:ty, display yes ) => {
45         impl<$($x)+> fmt::Display for $target {
46             gen_display_debug_body! { Print::print_display }
47         }
48     };
49     ( () $target:ty, display yes ) => {
50         impl fmt::Display for $target {
51             gen_display_debug_body! { Print::print_display }
52         }
53     };
54     ( ($($x:tt)+) $target:ty, debug yes ) => {
55         impl<$($x)+> fmt::Debug for $target {
56             gen_display_debug_body! { Print::print_debug }
57         }
58     };
59     ( () $target:ty, debug yes ) => {
60         impl fmt::Debug for $target {
61             gen_display_debug_body! { Print::print_debug }
62         }
63     };
64     ( $generic:tt $target:ty, $t:ident no ) => {};
65 }
66 macro_rules! gen_print_impl {
67     ( ($($x:tt)+) $target:ty, ($self:ident, $f:ident, $cx:ident) $disp:block $dbg:block ) => {
68         impl<$($x)+> Print for $target {
69             fn print<F: fmt::Write>(&$self, $f: &mut F, $cx: &mut PrintContext) -> fmt::Result {
70                 if $cx.is_debug $dbg
71                 else $disp
72             }
73         }
74     };
75     ( () $target:ty, ($self:ident, $f:ident, $cx:ident) $disp:block $dbg:block ) => {
76         impl Print for $target {
77             fn print<F: fmt::Write>(&$self, $f: &mut F, $cx: &mut PrintContext) -> fmt::Result {
78                 if $cx.is_debug $dbg
79                 else $disp
80             }
81         }
82     };
83     ( $generic:tt $target:ty,
84       $vars:tt $gendisp:ident $disp:block $gendbg:ident $dbg:block ) => {
85         gen_print_impl! { $generic $target, $vars $disp $dbg }
86         gen_display_debug! { $generic $target, display $gendisp }
87         gen_display_debug! { $generic $target, debug $gendbg }
88     }
89 }
90 macro_rules! define_print {
91     ( $generic:tt $target:ty,
92       $vars:tt { display $disp:block debug $dbg:block } ) => {
93         gen_print_impl! { $generic $target, $vars yes $disp yes $dbg }
94     };
95     ( $generic:tt $target:ty,
96       $vars:tt { debug $dbg:block display $disp:block } ) => {
97         gen_print_impl! { $generic $target, $vars yes $disp yes $dbg }
98     };
99     ( $generic:tt $target:ty,
100       $vars:tt { debug $dbg:block } ) => {
101         gen_print_impl! { $generic $target, $vars no {
102             bug!(concat!("display not implemented for ", stringify!($target)));
103         } yes $dbg }
104     };
105     ( $generic:tt $target:ty,
106       ($self:ident, $f:ident, $cx:ident) { display $disp:block } ) => {
107         gen_print_impl! { $generic $target, ($self, $f, $cx) yes $disp no {
108             write!($f, "{:?}", $self)
109         } }
110     };
111 }
112 macro_rules! define_print_multi {
113     ( [ $($generic:tt $target:ty),* ] $vars:tt $def:tt ) => {
114         $(define_print! { $generic $target, $vars $def })*
115     };
116 }
117 macro_rules! print_inner {
118     ( $f:expr, $cx:expr, write ($($data:expr),+) ) => {
119         write!($f, $($data),+)
120     };
121     ( $f:expr, $cx:expr, $kind:ident ($data:expr) ) => {
122         $data.$kind($f, $cx)
123     };
124 }
125 macro_rules! print {
126     ( $f:expr, $cx:expr $(, $kind:ident $data:tt)+ ) => {
127         Ok(())$(.and_then(|_| print_inner!($f, $cx, $kind $data)))+
128     };
129 }
130
131
132 struct LateBoundRegionNameCollector(FxHashSet<InternedString>);
133 impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
134     fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
135         match *r {
136             ty::ReLateBound(_, ty::BrNamed(_, name)) => {
137                 self.0.insert(name);
138             },
139             _ => {},
140         }
141         r.super_visit_with(self)
142     }
143 }
144
145 #[derive(Debug)]
146 pub struct PrintContext {
147     is_debug: bool,
148     is_verbose: bool,
149     identify_regions: bool,
150     used_region_names: Option<FxHashSet<InternedString>>,
151     region_index: usize,
152     binder_depth: usize,
153 }
154 impl PrintContext {
155     fn new() -> Self {
156         ty::tls::with_opt(|tcx| {
157             let (is_verbose, identify_regions) = tcx.map(
158                 |tcx| (tcx.sess.verbose(), tcx.sess.opts.debugging_opts.identify_regions)
159             ).unwrap_or((false, false));
160             PrintContext {
161                 is_debug: false,
162                 is_verbose: is_verbose,
163                 identify_regions: identify_regions,
164                 used_region_names: None,
165                 region_index: 0,
166                 binder_depth: 0,
167             }
168         })
169     }
170     fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
171     where T: TypeFoldable<'tcx>
172     {
173         let mut collector = LateBoundRegionNameCollector(FxHashSet());
174         value.visit_with(&mut collector);
175         self.used_region_names = Some(collector.0);
176         self.region_index = 0;
177     }
178 }
179
180 pub trait Print {
181     fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result;
182     fn print_to_string(&self, cx: &mut PrintContext) -> String {
183         let mut result = String::new();
184         let _ = self.print(&mut result, cx);
185         result
186     }
187     fn print_display<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
188         let old_debug = cx.is_debug;
189         cx.is_debug = false;
190         let result = self.print(f, cx);
191         cx.is_debug = old_debug;
192         result
193     }
194     fn print_display_to_string(&self, cx: &mut PrintContext) -> String {
195         let mut result = String::new();
196         let _ = self.print_display(&mut result, cx);
197         result
198     }
199     fn print_debug<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
200         let old_debug = cx.is_debug;
201         cx.is_debug = true;
202         let result = self.print(f, cx);
203         cx.is_debug = old_debug;
204         result
205     }
206     fn print_debug_to_string(&self, cx: &mut PrintContext) -> String {
207         let mut result = String::new();
208         let _ = self.print_debug(&mut result, cx);
209         result
210     }
211 }
212
213 impl PrintContext {
214     fn fn_sig<F: fmt::Write>(&mut self,
215                              f: &mut F,
216                              inputs: &[Ty],
217                              variadic: bool,
218                              output: Ty)
219                              -> fmt::Result {
220         write!(f, "(")?;
221         let mut inputs = inputs.iter();
222         if let Some(&ty) = inputs.next() {
223             print!(f, self, print_display(ty))?;
224             for &ty in inputs {
225                 print!(f, self, write(", "), print_display(ty))?;
226             }
227             if variadic {
228                 write!(f, ", ...")?;
229             }
230         }
231         write!(f, ")")?;
232         if !output.is_nil() {
233             print!(f, self, write(" -> "), print_display(output))?;
234         }
235
236         Ok(())
237     }
238
239     fn parameterized<F: fmt::Write>(&mut self,
240                                     f: &mut F,
241                                     substs: &subst::Substs,
242                                     mut did: DefId,
243                                     projections: &[ty::ProjectionPredicate])
244                                     -> fmt::Result {
245         let key = ty::tls::with(|tcx| tcx.def_key(did));
246         let mut item_name = if let Some(name) = key.disambiguated_data.data.get_opt_name() {
247             Some(name)
248         } else {
249             did.index = key.parent.unwrap_or_else(
250                 || bug!("finding type for {:?}, encountered def-id {:?} with no parent",
251                         did, did));
252             self.parameterized(f, substs, did, projections)?;
253             return write!(f, "::{}", key.disambiguated_data.data.as_interned_str());
254         };
255
256         let verbose = self.is_verbose;
257         let mut num_supplied_defaults = 0;
258         let mut has_self = false;
259         let mut own_counts = GenericParamCount {
260             lifetimes: 0,
261             types: 0,
262         };
263         let mut is_value_path = false;
264         let fn_trait_kind = ty::tls::with(|tcx| {
265             // Unfortunately, some kinds of items (e.g., closures) don't have
266             // generics. So walk back up the find the closest parent that DOES
267             // have them.
268             let mut item_def_id = did;
269             loop {
270                 let key = tcx.def_key(item_def_id);
271                 match key.disambiguated_data.data {
272                     DefPathData::AssocTypeInTrait(_) |
273                     DefPathData::AssocTypeInImpl(_) |
274                     DefPathData::Trait(_) |
275                     DefPathData::TypeNs(_) => {
276                         break;
277                     }
278                     DefPathData::ValueNs(_) |
279                     DefPathData::EnumVariant(_) => {
280                         is_value_path = true;
281                         break;
282                     }
283                     DefPathData::CrateRoot |
284                     DefPathData::Misc |
285                     DefPathData::Impl |
286                     DefPathData::Module(_) |
287                     DefPathData::MacroDef(_) |
288                     DefPathData::ClosureExpr |
289                     DefPathData::TypeParam(_) |
290                     DefPathData::LifetimeParam(_) |
291                     DefPathData::Field(_) |
292                     DefPathData::StructCtor |
293                     DefPathData::AnonConst |
294                     DefPathData::ExistentialImplTrait |
295                     DefPathData::UniversalImplTrait |
296                     DefPathData::GlobalMetaData(_) => {
297                         // if we're making a symbol for something, there ought
298                         // to be a value or type-def or something in there
299                         // *somewhere*
300                         item_def_id.index = key.parent.unwrap_or_else(|| {
301                             bug!("finding type for {:?}, encountered def-id {:?} with no \
302                                  parent", did, item_def_id);
303                         });
304                     }
305                 }
306             }
307             let mut generics = tcx.generics_of(item_def_id);
308             let child_own_counts = generics.own_counts();
309             let mut path_def_id = did;
310             has_self = generics.has_self;
311
312             let mut child_types = 0;
313             if let Some(def_id) = generics.parent {
314                 // Methods.
315                 assert!(is_value_path);
316                 child_types = child_own_counts.types;
317                 generics = tcx.generics_of(def_id);
318                 own_counts = generics.own_counts();
319
320                 if has_self {
321                     print!(f, self, write("<"), print_display(substs.type_at(0)), write(" as "))?;
322                 }
323
324                 path_def_id = def_id;
325             } else {
326                 item_name = None;
327
328                 if is_value_path {
329                     // Functions.
330                     assert_eq!(has_self, false);
331                 } else {
332                     // Types and traits.
333                     own_counts = child_own_counts;
334                 }
335             }
336
337             if !verbose {
338                 let mut type_params =
339                     generics.params.iter().rev().filter_map(|param| match param.kind {
340                         GenericParamDefKind::Lifetime => None,
341                         GenericParamDefKind::Type { has_default, .. } => {
342                             Some((param.def_id, has_default))
343                         }
344                     }).peekable();
345                 let has_default = {
346                     let has_default = type_params.peek().map(|(_, has_default)| has_default);
347                     *has_default.unwrap_or(&false)
348                 };
349                 if has_default {
350                     if let Some(substs) = tcx.lift(&substs) {
351                         let mut types = substs.types().rev().skip(child_types);
352                         for ((def_id, has_default), actual) in type_params.zip(types) {
353                             if !has_default {
354                                 break;
355                             }
356                             if tcx.type_of(def_id).subst(tcx, substs) != actual {
357                                 break;
358                             }
359                             num_supplied_defaults += 1;
360                         }
361                     }
362                 }
363             }
364
365             print!(f, self, write("{}", tcx.item_path_str(path_def_id)))?;
366             Ok(tcx.lang_items().fn_trait_kind(path_def_id))
367         })?;
368
369         if !verbose && fn_trait_kind.is_some() && projections.len() == 1 {
370             let projection_ty = projections[0].ty;
371             if let TyTuple(ref args) = substs.type_at(1).sty {
372                 return self.fn_sig(f, args, false, projection_ty);
373             }
374         }
375
376         let empty = Cell::new(true);
377         let start_or_continue = |f: &mut F, start: &str, cont: &str| {
378             if empty.get() {
379                 empty.set(false);
380                 write!(f, "{}", start)
381             } else {
382                 write!(f, "{}", cont)
383             }
384         };
385
386         let print_regions = |f: &mut F, start: &str, skip, count| {
387             // Don't print any regions if they're all erased.
388             let regions = || substs.regions().skip(skip).take(count);
389             if regions().all(|r: ty::Region| *r == ty::ReErased) {
390                 return Ok(());
391             }
392
393             for region in regions() {
394                 let region: ty::Region = region;
395                 start_or_continue(f, start, ", ")?;
396                 if verbose {
397                     write!(f, "{:?}", region)?;
398                 } else {
399                     let s = region.to_string();
400                     if s.is_empty() {
401                         // This happens when the value of the region
402                         // parameter is not easily serialized. This may be
403                         // because the user omitted it in the first place,
404                         // or because it refers to some block in the code,
405                         // etc. I'm not sure how best to serialize this.
406                         write!(f, "'_")?;
407                     } else {
408                         write!(f, "{}", s)?;
409                     }
410                 }
411             }
412
413             Ok(())
414         };
415
416         print_regions(f, "<", 0, own_counts.lifetimes)?;
417
418         let tps = substs.types()
419                         .take(own_counts.types - num_supplied_defaults)
420                         .skip(has_self as usize);
421
422         for ty in tps {
423             start_or_continue(f, "<", ", ")?;
424             ty.print_display(f, self)?;
425         }
426
427         for projection in projections {
428             start_or_continue(f, "<", ", ")?;
429             ty::tls::with(|tcx|
430                 print!(f, self,
431                        write("{}=",
432                              tcx.associated_item(projection.projection_ty.item_def_id).name),
433                        print_display(projection.ty))
434             )?;
435         }
436
437         start_or_continue(f, "", ">")?;
438
439         // For values, also print their name and type parameters.
440         if is_value_path {
441             empty.set(true);
442
443             if has_self {
444                 write!(f, ">")?;
445             }
446
447             if let Some(item_name) = item_name {
448                 write!(f, "::{}", item_name)?;
449             }
450
451             print_regions(f, "::<", own_counts.lifetimes, usize::MAX)?;
452
453             // FIXME: consider being smart with defaults here too
454             for ty in substs.types().skip(own_counts.types) {
455                 start_or_continue(f, "::<", ", ")?;
456                 ty.print_display(f, self)?;
457             }
458
459             start_or_continue(f, "", ">")?;
460         }
461
462         Ok(())
463     }
464
465     fn in_binder<'a, 'gcx, 'tcx, T, U, F>(&mut self,
466                                           f: &mut F,
467                                           tcx: TyCtxt<'a, 'gcx, 'tcx>,
468                                           original: &ty::Binder<T>,
469                                           lifted: Option<ty::Binder<U>>) -> fmt::Result
470         where T: Print, U: Print + TypeFoldable<'tcx>, F: fmt::Write
471     {
472         fn name_by_region_index(index: usize) -> InternedString {
473             match index {
474                 0 => Symbol::intern("'r"),
475                 1 => Symbol::intern("'s"),
476                 i => Symbol::intern(&format!("'t{}", i-2)),
477             }.as_interned_str()
478         }
479
480         // Replace any anonymous late-bound regions with named
481         // variants, using gensym'd identifiers, so that we can
482         // clearly differentiate between named and unnamed regions in
483         // the output. We'll probably want to tweak this over time to
484         // decide just how much information to give.
485         let value = if let Some(v) = lifted {
486             v
487         } else {
488             return original.skip_binder().print_display(f, self);
489         };
490
491         if self.binder_depth == 0 {
492             self.prepare_late_bound_region_info(&value);
493         }
494
495         let mut empty = true;
496         let mut start_or_continue = |f: &mut F, start: &str, cont: &str| {
497             if empty {
498                 empty = false;
499                 write!(f, "{}", start)
500             } else {
501                 write!(f, "{}", cont)
502             }
503         };
504
505         let old_region_index = self.region_index;
506         let mut region_index = old_region_index;
507         let new_value = tcx.replace_late_bound_regions(&value, |br| {
508             let _ = start_or_continue(f, "for<", ", ");
509             let br = match br {
510                 ty::BrNamed(_, name) => {
511                     let _ = write!(f, "{}", name);
512                     br
513                 }
514                 ty::BrAnon(_) |
515                 ty::BrFresh(_) |
516                 ty::BrEnv => {
517                     let name = loop {
518                         let name = name_by_region_index(region_index);
519                         region_index += 1;
520                         if !self.is_name_used(&name) {
521                             break name;
522                         }
523                     };
524                     let _ = write!(f, "{}", name);
525                     ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name)
526                 }
527             };
528             tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br))
529         }).0;
530         start_or_continue(f, "", "> ")?;
531
532         // Push current state to gcx, and restore after writing new_value.
533         self.binder_depth += 1;
534         self.region_index = region_index;
535         let result = new_value.print_display(f, self);
536         self.region_index = old_region_index;
537         self.binder_depth -= 1;
538         result
539     }
540
541     fn is_name_used(&self, name: &InternedString) -> bool {
542         match self.used_region_names {
543             Some(ref names) => names.contains(name),
544             None => false,
545         }
546     }
547 }
548
549 pub fn verbose() -> bool {
550     ty::tls::with(|tcx| tcx.sess.verbose())
551 }
552
553 pub fn identify_regions() -> bool {
554     ty::tls::with(|tcx| tcx.sess.opts.debugging_opts.identify_regions)
555 }
556
557 pub fn parameterized<F: fmt::Write>(f: &mut F,
558                                     substs: &subst::Substs,
559                                     did: DefId,
560                                     projections: &[ty::ProjectionPredicate])
561                                     -> fmt::Result {
562     PrintContext::new().parameterized(f, substs, did, projections)
563 }
564
565
566 impl<'a, T: Print> Print for &'a T {
567     fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
568         (*self).print(f, cx)
569     }
570 }
571
572 define_print! {
573     ('tcx) &'tcx ty::Slice<ty::ExistentialPredicate<'tcx>>, (self, f, cx) {
574         display {
575             // Generate the main trait ref, including associated types.
576             ty::tls::with(|tcx| {
577                 // Use a type that can't appear in defaults of type parameters.
578                 let dummy_self = tcx.mk_infer(ty::FreshTy(0));
579
580                 if let Some(p) = self.principal() {
581                     let principal = tcx.lift(&p).expect("could not lift TraitRef for printing")
582                         .with_self_ty(tcx, dummy_self);
583                     let projections = self.projection_bounds().map(|p| {
584                         tcx.lift(&p)
585                             .expect("could not lift projection for printing")
586                             .with_self_ty(tcx, dummy_self)
587                     }).collect::<Vec<_>>();
588                     cx.parameterized(f, principal.substs, principal.def_id, &projections)?;
589                 }
590
591                 // Builtin bounds.
592                 for did in self.auto_traits() {
593                     write!(f, " + {}", tcx.item_path_str(did))?;
594                 }
595
596                 Ok(())
597             })?;
598
599             Ok(())
600         }
601     }
602 }
603
604 impl fmt::Debug for ty::GenericParamDef {
605     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
606         let type_name = match self.kind {
607             ty::GenericParamDefKind::Lifetime => "Lifetime",
608             ty::GenericParamDefKind::Type {..} => "Type",
609         };
610         write!(f, "{}({}, {:?}, {})",
611                type_name,
612                self.name,
613                self.def_id,
614                self.index)
615     }
616 }
617
618 impl fmt::Debug for ty::TraitDef {
619     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
620         ty::tls::with(|tcx| {
621             write!(f, "{}", tcx.item_path_str(self.def_id))
622         })
623     }
624 }
625
626 impl fmt::Debug for ty::AdtDef {
627     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
628         ty::tls::with(|tcx| {
629             write!(f, "{}", tcx.item_path_str(self.did))
630         })
631     }
632 }
633
634 impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
635     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
636         write!(f, "ClosureUpvar({:?},{:?})",
637                self.def,
638                self.ty)
639     }
640 }
641
642 impl fmt::Debug for ty::UpvarId {
643     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
644         write!(f, "UpvarId({:?};`{}`;{:?})",
645                self.var_id,
646                ty::tls::with(|tcx| tcx.hir.name(tcx.hir.hir_to_node_id(self.var_id))),
647                self.closure_expr_id)
648     }
649 }
650
651 impl<'tcx> fmt::Debug for ty::UpvarBorrow<'tcx> {
652     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
653         write!(f, "UpvarBorrow({:?}, {:?})",
654                self.kind, self.region)
655     }
656 }
657
658 define_print! {
659     ('tcx) &'tcx ty::Slice<Ty<'tcx>>, (self, f, cx) {
660         display {
661             write!(f, "{{")?;
662             let mut tys = self.iter();
663             if let Some(&ty) = tys.next() {
664                 print!(f, cx, print(ty))?;
665                 for &ty in tys {
666                     print!(f, cx, write(", "), print(ty))?;
667                 }
668             }
669             write!(f, "}}")
670         }
671     }
672 }
673
674 define_print! {
675     ('tcx) ty::TypeAndMut<'tcx>, (self, f, cx) {
676         display {
677             print!(f, cx,
678                    write("{}", if self.mutbl == hir::MutMutable { "mut " } else { "" }),
679                    print(self.ty))
680         }
681     }
682 }
683
684 define_print! {
685     ('tcx) ty::ExistentialTraitRef<'tcx>, (self, f, cx) {
686         debug {
687             ty::tls::with(|tcx| {
688                 let dummy_self = tcx.mk_infer(ty::FreshTy(0));
689
690                 let trait_ref = *tcx.lift(&ty::Binder::bind(*self))
691                                    .expect("could not lift TraitRef for printing")
692                                    .with_self_ty(tcx, dummy_self).skip_binder();
693                 cx.parameterized(f, trait_ref.substs, trait_ref.def_id, &[])
694             })
695         }
696     }
697 }
698
699 define_print! {
700     ('tcx) ty::adjustment::Adjustment<'tcx>, (self, f, cx) {
701         debug {
702             print!(f, cx, write("{:?} -> ", self.kind), print(self.target))
703         }
704     }
705 }
706
707 define_print! {
708     () ty::BoundRegion, (self, f, cx) {
709         display {
710             if cx.is_verbose {
711                 return self.print_debug(f, cx);
712             }
713
714             match *self {
715                 BrNamed(_, name) => write!(f, "{}", name),
716                 BrAnon(_) | BrFresh(_) | BrEnv => Ok(())
717             }
718         }
719         debug {
720             return match *self {
721                 BrAnon(n) => write!(f, "BrAnon({:?})", n),
722                 BrFresh(n) => write!(f, "BrFresh({:?})", n),
723                 BrNamed(did, name) => {
724                     write!(f, "BrNamed({:?}:{:?}, {})",
725                            did.krate, did.index, name)
726                 }
727                 BrEnv => write!(f, "BrEnv"),
728             };
729         }
730     }
731 }
732
733 define_print! {
734     () ty::RegionKind, (self, f, cx) {
735         display {
736             if cx.is_verbose {
737                 return self.print_debug(f, cx);
738             }
739
740             // These printouts are concise.  They do not contain all the information
741             // the user might want to diagnose an error, but there is basically no way
742             // to fit that into a short string.  Hence the recommendation to use
743             // `explain_region()` or `note_and_explain_region()`.
744             match *self {
745                 ty::ReEarlyBound(ref data) => {
746                     write!(f, "{}", data.name)
747                 }
748                 ty::ReCanonical(_) => {
749                     write!(f, "'_")
750                 }
751                 ty::ReLateBound(_, br) |
752                 ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
753                 ty::ReSkolemized(_, br) => {
754                     write!(f, "{}", br)
755                 }
756                 ty::ReScope(scope) if cx.identify_regions => {
757                     match scope.data() {
758                         region::ScopeData::Node(id) =>
759                             write!(f, "'{}s", id.as_usize()),
760                         region::ScopeData::CallSite(id) =>
761                             write!(f, "'{}cs", id.as_usize()),
762                         region::ScopeData::Arguments(id) =>
763                             write!(f, "'{}as", id.as_usize()),
764                         region::ScopeData::Destruction(id) =>
765                             write!(f, "'{}ds", id.as_usize()),
766                         region::ScopeData::Remainder(BlockRemainder
767                                                      { block, first_statement_index }) =>
768                             write!(f, "'{}_{}rs", block.as_usize(), first_statement_index.index()),
769                     }
770                 }
771                 ty::ReVar(region_vid) if cx.identify_regions => {
772                     write!(f, "'{}rv", region_vid.index())
773                 }
774                 ty::ReScope(_) |
775                 ty::ReVar(_) |
776                 ty::ReErased => Ok(()),
777                 ty::ReStatic => write!(f, "'static"),
778                 ty::ReEmpty => write!(f, "'<empty>"),
779
780                 // The user should never encounter these in unsubstituted form.
781                 ty::ReClosureBound(vid) => write!(f, "{:?}", vid),
782             }
783         }
784         debug {
785             match *self {
786                 ty::ReEarlyBound(ref data) => {
787                     write!(f, "ReEarlyBound({}, {})",
788                            data.index,
789                            data.name)
790                 }
791
792                 ty::ReClosureBound(ref vid) => {
793                     write!(f, "ReClosureBound({:?})",
794                            vid)
795                 }
796
797                 ty::ReLateBound(binder_id, ref bound_region) => {
798                     write!(f, "ReLateBound({:?}, {:?})",
799                            binder_id,
800                            bound_region)
801                 }
802
803                 ty::ReFree(ref fr) => write!(f, "{:?}", fr),
804
805                 ty::ReScope(id) => {
806                     write!(f, "ReScope({:?})", id)
807                 }
808
809                 ty::ReStatic => write!(f, "ReStatic"),
810
811                 ty::ReVar(ref vid) => {
812                     write!(f, "{:?}", vid)
813                 }
814
815                 ty::ReCanonical(c) => {
816                     write!(f, "'?{}", c.index())
817                 }
818
819                 ty::ReSkolemized(universe, ref bound_region) => {
820                     write!(f, "ReSkolemized({:?}, {:?})", universe, bound_region)
821                 }
822
823                 ty::ReEmpty => write!(f, "ReEmpty"),
824
825                 ty::ReErased => write!(f, "ReErased")
826             }
827         }
828     }
829 }
830
831 define_print! {
832     () ty::FreeRegion, (self, f, cx) {
833         debug {
834             write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
835         }
836     }
837 }
838
839 define_print! {
840     () ty::Variance, (self, f, cx) {
841         debug {
842             f.write_str(match *self {
843                 ty::Covariant => "+",
844                 ty::Contravariant => "-",
845                 ty::Invariant => "o",
846                 ty::Bivariant => "*",
847             })
848         }
849     }
850 }
851
852 define_print! {
853     ('tcx) ty::GenericPredicates<'tcx>, (self, f, cx) {
854         debug {
855             write!(f, "GenericPredicates({:?})", self.predicates)
856         }
857     }
858 }
859
860 define_print! {
861     ('tcx) ty::InstantiatedPredicates<'tcx>, (self, f, cx) {
862         debug {
863             write!(f, "InstantiatedPredicates({:?})", self.predicates)
864         }
865     }
866 }
867
868 define_print! {
869     ('tcx) ty::FnSig<'tcx>, (self, f, cx) {
870         display {
871             if self.unsafety == hir::Unsafety::Unsafe {
872                 write!(f, "unsafe ")?;
873             }
874
875             if self.abi != Abi::Rust {
876                 write!(f, "extern {} ", self.abi)?;
877             }
878
879             write!(f, "fn")?;
880             cx.fn_sig(f, self.inputs(), self.variadic, self.output())
881         }
882         debug {
883             write!(f, "({:?}; variadic: {})->{:?}", self.inputs(), self.variadic, self.output())
884         }
885     }
886 }
887
888 impl fmt::Debug for ty::TyVid {
889     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
890         write!(f, "_#{}t", self.index)
891     }
892 }
893
894 impl fmt::Debug for ty::IntVid {
895     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
896         write!(f, "_#{}i", self.index)
897     }
898 }
899
900 impl fmt::Debug for ty::FloatVid {
901     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
902         write!(f, "_#{}f", self.index)
903     }
904 }
905
906 impl fmt::Debug for ty::RegionVid {
907     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
908         write!(f, "'_#{}r", self.index())
909     }
910 }
911
912 define_print! {
913     () ty::InferTy, (self, f, cx) {
914         display {
915             if cx.is_verbose {
916                 print!(f, cx, print_debug(self))
917             } else {
918                 match *self {
919                     ty::TyVar(_) => write!(f, "_"),
920                     ty::IntVar(_) => write!(f, "{}", "{integer}"),
921                     ty::FloatVar(_) => write!(f, "{}", "{float}"),
922                     ty::CanonicalTy(_) => write!(f, "_"),
923                     ty::FreshTy(v) => write!(f, "FreshTy({})", v),
924                     ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
925                     ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)
926                 }
927             }
928         }
929         debug {
930             match *self {
931                 ty::TyVar(ref v) => write!(f, "{:?}", v),
932                 ty::IntVar(ref v) => write!(f, "{:?}", v),
933                 ty::FloatVar(ref v) => write!(f, "{:?}", v),
934                 ty::CanonicalTy(v) => write!(f, "?{:?}", v.index()),
935                 ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
936                 ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
937                 ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
938             }
939         }
940     }
941 }
942
943 impl fmt::Debug for ty::IntVarValue {
944     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
945         match *self {
946             ty::IntType(ref v) => v.fmt(f),
947             ty::UintType(ref v) => v.fmt(f),
948         }
949     }
950 }
951
952 impl fmt::Debug for ty::FloatVarValue {
953     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
954         self.0.fmt(f)
955     }
956 }
957
958 // The generic impl doesn't work yet because projections are not
959 // normalized under HRTB.
960 /*impl<T> fmt::Display for ty::Binder<T>
961     where T: fmt::Display + for<'a> ty::Lift<'a>,
962           for<'a> <T as ty::Lift<'a>>::Lifted: fmt::Display + TypeFoldable<'a>
963 {
964     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
965         ty::tls::with(|tcx| in_binder(f, tcx, self, tcx.lift(self)))
966     }
967 }*/
968
969 define_print_multi! {
970     [
971     ('tcx) ty::Binder<&'tcx ty::Slice<ty::ExistentialPredicate<'tcx>>>,
972     ('tcx) ty::Binder<ty::TraitRef<'tcx>>,
973     ('tcx) ty::Binder<ty::FnSig<'tcx>>,
974     ('tcx) ty::Binder<ty::TraitPredicate<'tcx>>,
975     ('tcx) ty::Binder<ty::SubtypePredicate<'tcx>>,
976     ('tcx) ty::Binder<ty::ProjectionPredicate<'tcx>>,
977     ('tcx) ty::Binder<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>,
978     ('tcx) ty::Binder<ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>>
979     ]
980     (self, f, cx) {
981         display {
982             ty::tls::with(|tcx| cx.in_binder(f, tcx, self, tcx.lift(self)))
983         }
984     }
985 }
986
987 define_print! {
988     ('tcx) ty::TraitRef<'tcx>, (self, f, cx) {
989         display {
990             cx.parameterized(f, self.substs, self.def_id, &[])
991         }
992         debug {
993             // when printing out the debug representation, we don't need
994             // to enumerate the `for<...>` etc because the debruijn index
995             // tells you everything you need to know.
996             print!(f, cx,
997                    write("<"),
998                    print(self.self_ty()),
999                    write(" as "))?;
1000             cx.parameterized(f, self.substs, self.def_id, &[])?;
1001             write!(f, ">")
1002         }
1003     }
1004 }
1005
1006 define_print! {
1007     ('tcx) ty::TypeVariants<'tcx>, (self, f, cx) {
1008         display {
1009             match *self {
1010                 TyBool => write!(f, "bool"),
1011                 TyChar => write!(f, "char"),
1012                 TyInt(t) => write!(f, "{}", t.ty_to_string()),
1013                 TyUint(t) => write!(f, "{}", t.ty_to_string()),
1014                 TyFloat(t) => write!(f, "{}", t.ty_to_string()),
1015                 TyRawPtr(ref tm) => {
1016                     write!(f, "*{} ", match tm.mutbl {
1017                         hir::MutMutable => "mut",
1018                         hir::MutImmutable => "const",
1019                     })?;
1020                     tm.ty.print(f, cx)
1021                 }
1022                 TyRef(r, ty, mutbl) => {
1023                     write!(f, "&")?;
1024                     let s = r.print_to_string(cx);
1025                     write!(f, "{}", s)?;
1026                     if !s.is_empty() {
1027                         write!(f, " ")?;
1028                     }
1029                     ty::TypeAndMut { ty, mutbl }.print(f, cx)
1030                 }
1031                 TyNever => write!(f, "!"),
1032                 TyTuple(ref tys) => {
1033                     write!(f, "(")?;
1034                     let mut tys = tys.iter();
1035                     if let Some(&ty) = tys.next() {
1036                         print!(f, cx, print(ty), write(","))?;
1037                         if let Some(&ty) = tys.next() {
1038                             print!(f, cx, write(" "), print(ty))?;
1039                             for &ty in tys {
1040                                 print!(f, cx, write(", "), print(ty))?;
1041                             }
1042                         }
1043                     }
1044                     write!(f, ")")
1045                 }
1046                 TyFnDef(def_id, substs) => {
1047                     ty::tls::with(|tcx| {
1048                         let mut sig = tcx.fn_sig(def_id);
1049                         if let Some(substs) = tcx.lift(&substs) {
1050                             sig = sig.subst(tcx, substs);
1051                         }
1052                         print!(f, cx, print(sig), write(" {{"))
1053                     })?;
1054                     cx.parameterized(f, substs, def_id, &[])?;
1055                     write!(f, "}}")
1056                 }
1057                 TyFnPtr(ref bare_fn) => {
1058                     bare_fn.print(f, cx)
1059                 }
1060                 TyInfer(infer_ty) => write!(f, "{}", infer_ty),
1061                 TyError => write!(f, "[type error]"),
1062                 TyParam(ref param_ty) => write!(f, "{}", param_ty),
1063                 TyAdt(def, substs) => cx.parameterized(f, substs, def.did, &[]),
1064                 TyDynamic(data, r) => {
1065                     data.print(f, cx)?;
1066                     let r = r.print_to_string(cx);
1067                     if !r.is_empty() {
1068                         write!(f, " + {}", r)
1069                     } else {
1070                         Ok(())
1071                     }
1072                 }
1073                 TyForeign(def_id) => parameterized(f, subst::Substs::empty(), def_id, &[]),
1074                 TyProjection(ref data) => data.print(f, cx),
1075                 TyAnon(def_id, substs) => {
1076                     if cx.is_verbose {
1077                         return write!(f, "TyAnon({:?}, {:?})", def_id, substs);
1078                     }
1079
1080                     ty::tls::with(|tcx| {
1081                         // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
1082                         // by looking up the projections associated with the def_id.
1083                         let predicates_of = tcx.predicates_of(def_id);
1084                         let substs = tcx.lift(&substs).unwrap_or_else(|| {
1085                             tcx.intern_substs(&[])
1086                         });
1087                         let bounds = predicates_of.instantiate(tcx, substs);
1088
1089                         let mut first = true;
1090                         let mut is_sized = false;
1091                         write!(f, "impl")?;
1092                         for predicate in bounds.predicates {
1093                             if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
1094                                 // Don't print +Sized, but rather +?Sized if absent.
1095                                 if Some(trait_ref.def_id()) == tcx.lang_items().sized_trait() {
1096                                     is_sized = true;
1097                                     continue;
1098                                 }
1099
1100                                 print!(f, cx,
1101                                        write("{}", if first { " " } else { "+" }),
1102                                        print(trait_ref))?;
1103                                 first = false;
1104                             }
1105                         }
1106                         if !is_sized {
1107                             write!(f, "{}?Sized", if first { " " } else { "+" })?;
1108                         }
1109                         Ok(())
1110                     })
1111                 }
1112                 TyStr => write!(f, "str"),
1113                 TyGenerator(did, substs, movability) => ty::tls::with(|tcx| {
1114                     let upvar_tys = substs.upvar_tys(did, tcx);
1115                     let witness = substs.witness(did, tcx);
1116                     if movability == hir::GeneratorMovability::Movable {
1117                         write!(f, "[generator")?;
1118                     } else {
1119                         write!(f, "[static generator")?;
1120                     }
1121
1122                     if let Some(node_id) = tcx.hir.as_local_node_id(did) {
1123                         write!(f, "@{:?}", tcx.hir.span(node_id))?;
1124                         let mut sep = " ";
1125                         tcx.with_freevars(node_id, |freevars| {
1126                             for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {
1127                                 print!(f, cx,
1128                                        write("{}{}:",
1129                                              sep,
1130                                              tcx.hir.name(freevar.var_id())),
1131                                        print(upvar_ty))?;
1132                                 sep = ", ";
1133                             }
1134                             Ok(())
1135                         })?
1136                     } else {
1137                         // cross-crate closure types should only be
1138                         // visible in codegen bug reports, I imagine.
1139                         write!(f, "@{:?}", did)?;
1140                         let mut sep = " ";
1141                         for (index, upvar_ty) in upvar_tys.enumerate() {
1142                             print!(f, cx,
1143                                    write("{}{}:", sep, index),
1144                                    print(upvar_ty))?;
1145                             sep = ", ";
1146                         }
1147                     }
1148
1149                     print!(f, cx, write(" "), print(witness), write("]"))
1150                 }),
1151                 TyGeneratorWitness(types) => {
1152                     ty::tls::with(|tcx| cx.in_binder(f, tcx, &types, tcx.lift(&types)))
1153                 }
1154                 TyClosure(did, substs) => ty::tls::with(|tcx| {
1155                     let upvar_tys = substs.upvar_tys(did, tcx);
1156                     write!(f, "[closure")?;
1157
1158                     if let Some(node_id) = tcx.hir.as_local_node_id(did) {
1159                         if tcx.sess.opts.debugging_opts.span_free_formats {
1160                             write!(f, "@{:?}", node_id)?;
1161                         } else {
1162                             write!(f, "@{:?}", tcx.hir.span(node_id))?;
1163                         }
1164                         let mut sep = " ";
1165                         tcx.with_freevars(node_id, |freevars| {
1166                             for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {
1167                                 print!(f, cx,
1168                                        write("{}{}:",
1169                                              sep,
1170                                              tcx.hir.name(freevar.var_id())),
1171                                        print(upvar_ty))?;
1172                                 sep = ", ";
1173                             }
1174                             Ok(())
1175                         })?
1176                     } else {
1177                         // cross-crate closure types should only be
1178                         // visible in codegen bug reports, I imagine.
1179                         write!(f, "@{:?}", did)?;
1180                         let mut sep = " ";
1181                         for (index, upvar_ty) in upvar_tys.enumerate() {
1182                             print!(f, cx,
1183                                    write("{}{}:", sep, index),
1184                                    print(upvar_ty))?;
1185                             sep = ", ";
1186                         }
1187                     }
1188
1189                     write!(f, "]")
1190                 }),
1191                 TyArray(ty, sz) => {
1192                     print!(f, cx, write("["), print(ty), write("; "))?;
1193                     match sz.val {
1194                         ConstVal::Value(..) => ty::tls::with(|tcx| {
1195                             write!(f, "{}", sz.unwrap_usize(tcx))
1196                         })?,
1197                         ConstVal::Unevaluated(_def_id, _substs) => {
1198                             write!(f, "_")?;
1199                         }
1200                     }
1201                     write!(f, "]")
1202                 }
1203                 TySlice(ty) => {
1204                     print!(f, cx, write("["), print(ty), write("]"))
1205                 }
1206             }
1207         }
1208     }
1209 }
1210
1211 define_print! {
1212     ('tcx) ty::TyS<'tcx>, (self, f, cx) {
1213         display {
1214             self.sty.print(f, cx)
1215         }
1216         debug {
1217             self.sty.print_display(f, cx)
1218         }
1219     }
1220 }
1221
1222 define_print! {
1223     () ty::ParamTy, (self, f, cx) {
1224         display {
1225             write!(f, "{}", self.name)
1226         }
1227         debug {
1228             write!(f, "{}/#{}", self.name, self.idx)
1229         }
1230     }
1231 }
1232
1233 define_print! {
1234     ('tcx, T: Print + fmt::Debug, U: Print + fmt::Debug) ty::OutlivesPredicate<T, U>,
1235     (self, f, cx) {
1236         display {
1237             print!(f, cx, print(self.0), write(" : "), print(self.1))
1238         }
1239     }
1240 }
1241
1242 define_print! {
1243     ('tcx) ty::SubtypePredicate<'tcx>, (self, f, cx) {
1244         display {
1245             print!(f, cx, print(self.a), write(" <: "), print(self.b))
1246         }
1247     }
1248 }
1249
1250 define_print! {
1251     ('tcx) ty::TraitPredicate<'tcx>, (self, f, cx) {
1252         debug {
1253             write!(f, "TraitPredicate({:?})",
1254                    self.trait_ref)
1255         }
1256         display {
1257             print!(f, cx, print(self.trait_ref.self_ty()), write(": "), print(self.trait_ref))
1258         }
1259     }
1260 }
1261
1262 define_print! {
1263     ('tcx) ty::ProjectionPredicate<'tcx>, (self, f, cx) {
1264         debug {
1265             print!(f, cx,
1266                    write("ProjectionPredicate("),
1267                    print(self.projection_ty),
1268                    write(", "),
1269                    print(self.ty),
1270                    write(")"))
1271         }
1272         display {
1273             print!(f, cx, print(self.projection_ty), write(" == "), print(self.ty))
1274         }
1275     }
1276 }
1277
1278 define_print! {
1279     ('tcx) ty::ProjectionTy<'tcx>, (self, f, cx) {
1280         display {
1281             // FIXME(tschottdorf): use something like
1282             //   parameterized(f, self.substs, self.item_def_id, &[])
1283             // (which currently ICEs).
1284             let (trait_ref, item_name) = ty::tls::with(|tcx|
1285                 (self.trait_ref(tcx), tcx.associated_item(self.item_def_id).name)
1286             );
1287             print!(f, cx, print_debug(trait_ref), write("::{}", item_name))
1288         }
1289     }
1290 }
1291
1292 define_print! {
1293     () ty::ClosureKind, (self, f, cx) {
1294         display {
1295             match *self {
1296                 ty::ClosureKind::Fn => write!(f, "Fn"),
1297                 ty::ClosureKind::FnMut => write!(f, "FnMut"),
1298                 ty::ClosureKind::FnOnce => write!(f, "FnOnce"),
1299             }
1300         }
1301     }
1302 }
1303
1304 define_print! {
1305     ('tcx) ty::Predicate<'tcx>, (self, f, cx) {
1306         display {
1307             match *self {
1308                 ty::Predicate::Trait(ref data) => data.print(f, cx),
1309                 ty::Predicate::Subtype(ref predicate) => predicate.print(f, cx),
1310                 ty::Predicate::RegionOutlives(ref predicate) => predicate.print(f, cx),
1311                 ty::Predicate::TypeOutlives(ref predicate) => predicate.print(f, cx),
1312                 ty::Predicate::Projection(ref predicate) => predicate.print(f, cx),
1313                 ty::Predicate::WellFormed(ty) => print!(f, cx, print(ty), write(" well-formed")),
1314                 ty::Predicate::ObjectSafe(trait_def_id) =>
1315                     ty::tls::with(|tcx| {
1316                         write!(f, "the trait `{}` is object-safe", tcx.item_path_str(trait_def_id))
1317                     }),
1318                 ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) =>
1319                     ty::tls::with(|tcx| {
1320                         write!(f, "the closure `{}` implements the trait `{}`",
1321                                tcx.item_path_str(closure_def_id), kind)
1322                     }),
1323                 ty::Predicate::ConstEvaluatable(def_id, substs) => {
1324                     write!(f, "the constant `")?;
1325                     cx.parameterized(f, substs, def_id, &[])?;
1326                     write!(f, "` can be evaluated")
1327                 }
1328             }
1329         }
1330         debug {
1331             match *self {
1332                 ty::Predicate::Trait(ref a) => a.print(f, cx),
1333                 ty::Predicate::Subtype(ref pair) => pair.print(f, cx),
1334                 ty::Predicate::RegionOutlives(ref pair) => pair.print(f, cx),
1335                 ty::Predicate::TypeOutlives(ref pair) => pair.print(f, cx),
1336                 ty::Predicate::Projection(ref pair) => pair.print(f, cx),
1337                 ty::Predicate::WellFormed(ty) => ty.print(f, cx),
1338                 ty::Predicate::ObjectSafe(trait_def_id) => {
1339                     write!(f, "ObjectSafe({:?})", trait_def_id)
1340                 }
1341                 ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
1342                     write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
1343                 }
1344                 ty::Predicate::ConstEvaluatable(def_id, substs) => {
1345                     write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
1346                 }
1347             }
1348         }
1349     }
1350 }