@@ -40,6 +40,44 @@ pub struct TraitRef<I: Interner> {
40
40
_use_trait_ref_new_instead : ( ) ,
41
41
}
42
42
43
+ impl < I : Interner > fmt:: Debug for TraitRef < I > {
44
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
45
+ WithInfcx :: with_no_infcx ( self ) . fmt ( f)
46
+ }
47
+ }
48
+ impl < I : Interner > DebugWithInfcx < I > for TraitRef < I > {
49
+ fn fmt < Infcx : InferCtxtLike < Interner = I > > (
50
+ this : WithInfcx < ' _ , Infcx , & Self > ,
51
+ f : & mut fmt:: Formatter < ' _ > ,
52
+ ) -> fmt:: Result {
53
+ // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?)
54
+ if this. data . args . len ( ) == 0 {
55
+ return f
56
+ . debug_tuple ( "TraitRef" )
57
+ . field ( & this. data . def_id )
58
+ . field ( & this. data . args )
59
+ . finish ( ) ;
60
+ }
61
+
62
+ write ! ( f, "({:?} as " , this. map( |trait_ref| trait_ref. args[ 0 ] ) ) ?;
63
+ I :: print_def_path ( this. data . def_id , f) ?;
64
+
65
+ match this. data . args . len ( ) {
66
+ 0 => unreachable ! ( ) ,
67
+ 1 => write ! ( f, ")" ) , // the first arg is the self type
68
+ 2 => write ! ( f, "<{:?}>)" , this. map( |trait_ref| trait_ref. args[ 1 ] ) ) ,
69
+ 3 .. => {
70
+ write ! ( f, "<{:?}" , this. map( |trait_ref| trait_ref. args[ 1 ] ) ) ?;
71
+ for arg in & this. data . args [ 2 ..] {
72
+ let arg = this. wrap ( arg) ;
73
+ write ! ( f, ", {:?}" , arg) ?;
74
+ }
75
+ write ! ( f, ">)" )
76
+ }
77
+ }
78
+ }
79
+ }
80
+
43
81
impl < I : Interner > TraitRef < I > {
44
82
pub fn new (
45
83
interner : I ,
@@ -114,8 +152,46 @@ impl<I: Interner> TraitPredicate<I> {
114
152
115
153
impl < I : Interner > fmt:: Debug for TraitPredicate < I > {
116
154
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
155
+ WithInfcx :: with_no_infcx ( self ) . fmt ( f)
156
+ }
157
+ }
158
+ impl < I : Interner > DebugWithInfcx < I > for TraitPredicate < I > {
159
+ fn fmt < Infcx : InferCtxtLike < Interner = I > > (
160
+ this : WithInfcx < ' _ , Infcx , & Self > ,
161
+ f : & mut fmt:: Formatter < ' _ > ,
162
+ ) -> fmt:: Result {
117
163
// FIXME(effects) printing?
118
- write ! ( f, "TraitPredicate({:?}, polarity:{:?})" , self . trait_ref, self . polarity)
164
+
165
+ // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?)
166
+ if this. data . trait_ref . args . len ( ) == 0 {
167
+ return f
168
+ . debug_tuple ( "TraitPredicate" )
169
+ . field ( & this. data . trait_ref . def_id )
170
+ . field ( & this. data . trait_ref . args )
171
+ . field ( & this. data . polarity )
172
+ . finish ( ) ;
173
+ }
174
+
175
+ write ! ( f, "({:?}: " , this. map( |pred| pred. trait_ref. args[ 0 ] ) ) ?;
176
+ match this. data . polarity {
177
+ PredicatePolarity :: Positive => ( ) ,
178
+ PredicatePolarity :: Negative => write ! ( f, "!" ) ?,
179
+ } ;
180
+ I :: print_def_path ( this. data . trait_ref . def_id , f) ?;
181
+
182
+ match this. data . trait_ref . args . len ( ) {
183
+ 0 => unreachable ! ( ) ,
184
+ 1 => write ! ( f, ")" ) , // the first arg is the self type
185
+ 2 => write ! ( f, "<{:?}>)" , this. map( |trait_ref| trait_ref. trait_ref. args[ 1 ] ) ) ,
186
+ 3 .. => {
187
+ write ! ( f, "<{:?}" , this. map( |trait_ref| trait_ref. trait_ref. args[ 1 ] ) ) ?;
188
+ for arg in & this. data . trait_ref . args [ 2 ..] {
189
+ let arg = this. wrap ( arg) ;
190
+ write ! ( f, ", {:?}" , arg) ?;
191
+ }
192
+ write ! ( f, ">)" )
193
+ }
194
+ }
119
195
}
120
196
}
121
197
0 commit comments