rustc_type_ir/
ir_print.rs1use std::fmt;
2
3use crate::{
4 AliasTerm, AliasTy, Binder, CoercePredicate, ExistentialProjection, ExistentialTraitRef, FnSig,
5 HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate, PatternKind,
6 ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef,
7};
8
9pub trait IrPrint<T> {
10 fn print(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
11 fn print_debug(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
12}
13
14macro_rules! define_display_via_print {
15 ($($ty:ident),+ $(,)?) => {
16 $(
17 impl<I: Interner> fmt::Display for $ty<I> {
18 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
19 <I as IrPrint<$ty<I>>>::print(self, fmt)
20 }
21 }
22 )*
23 }
24}
25
26impl<I: Interner, T> fmt::Display for Binder<I, T>
27where
28 I: IrPrint<Binder<I, T>>,
29{
30 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
31 <I as IrPrint<Binder<I, T>>>::print(self, fmt)
32 }
33}
34
35macro_rules! define_debug_via_print {
36 ($($ty:ident),+ $(,)?) => {
37 $(
38 impl<I: Interner> fmt::Debug for $ty<I> {
39 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
40 <I as IrPrint<$ty<I>>>::print_debug(self, fmt)
41 }
42 }
43 )*
44 }
45}
46
47define_display_via_print!(
48 TraitRef,
49 TraitPredicate,
50 ExistentialTraitRef,
51 ExistentialProjection,
52 ProjectionPredicate,
53 NormalizesTo,
54 SubtypePredicate,
55 CoercePredicate,
56 HostEffectPredicate,
57 AliasTy,
58 AliasTerm,
59 FnSig,
60 PatternKind,
61);
62
63define_debug_via_print!(TraitRef, ExistentialTraitRef, PatternKind);
64
65impl<I: Interner, T> fmt::Display for OutlivesPredicate<I, T>
66where
67 I: IrPrint<OutlivesPredicate<I, T>>,
68{
69 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
70 <I as IrPrint<OutlivesPredicate<I, T>>>::print(self, fmt)
71 }
72}