@@ -73,6 +73,44 @@ pub struct TraitRef<I: Interner> {
73
73
_use_trait_ref_new_instead : ( ) ,
74
74
}
75
75
76
+ impl < I : Interner > fmt:: Debug for TraitRef < I > {
77
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
78
+ WithInfcx :: with_no_infcx ( self ) . fmt ( f)
79
+ }
80
+ }
81
+ impl < I : Interner > DebugWithInfcx < I > for TraitRef < I > {
82
+ fn fmt < Infcx : InferCtxtLike < Interner = I > > (
83
+ this : WithInfcx < ' _ , Infcx , & Self > ,
84
+ f : & mut fmt:: Formatter < ' _ > ,
85
+ ) -> fmt:: Result {
86
+ // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?)
87
+ if this. data . args . len ( ) == 0 {
88
+ return f
89
+ . debug_tuple ( "TraitRef" )
90
+ . field ( & this. data . def_id )
91
+ . field ( & this. data . args )
92
+ . finish ( ) ;
93
+ }
94
+
95
+ write ! ( f, "({:?} as " , this. map( |trait_ref| trait_ref. args[ 0 ] ) ) ?;
96
+ I :: print_def_path ( this. data . def_id , f) ?;
97
+
98
+ match this. data . args . len ( ) {
99
+ 0 => unreachable ! ( ) ,
100
+ 1 => write ! ( f, ")" ) , // the first arg is the self type
101
+ 2 => write ! ( f, "<{:?}>)" , this. map( |trait_ref| trait_ref. args[ 1 ] ) ) ,
102
+ 3 .. => {
103
+ write ! ( f, "<{:?}" , this. map( |trait_ref| trait_ref. args[ 1 ] ) ) ?;
104
+ for arg in & this. data . args [ 2 ..] {
105
+ let arg = this. wrap ( arg) ;
106
+ write ! ( f, ", {:?}" , arg) ?;
107
+ }
108
+ write ! ( f, ">)" )
109
+ }
110
+ }
111
+ }
112
+ }
113
+
76
114
impl < I : Interner > TraitRef < I > {
77
115
pub fn new (
78
116
interner : I ,
@@ -147,8 +185,46 @@ impl<I: Interner> TraitPredicate<I> {
147
185
148
186
impl < I : Interner > fmt:: Debug for TraitPredicate < I > {
149
187
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
188
+ WithInfcx :: with_no_infcx ( self ) . fmt ( f)
189
+ }
190
+ }
191
+ impl < I : Interner > DebugWithInfcx < I > for TraitPredicate < I > {
192
+ fn fmt < Infcx : InferCtxtLike < Interner = I > > (
193
+ this : WithInfcx < ' _ , Infcx , & Self > ,
194
+ f : & mut fmt:: Formatter < ' _ > ,
195
+ ) -> fmt:: Result {
150
196
// FIXME(effects) printing?
151
- write ! ( f, "TraitPredicate({:?}, polarity:{:?})" , self . trait_ref, self . polarity)
197
+
198
+ // If we ever wind up with a malformed `TraitRef` it might be good to not ICE in its Debug impl(?)
199
+ if this. data . trait_ref . args . len ( ) == 0 {
200
+ return f
201
+ . debug_tuple ( "TraitPredicate" )
202
+ . field ( & this. data . trait_ref . def_id )
203
+ . field ( & this. data . trait_ref . args )
204
+ . field ( & this. data . polarity )
205
+ . finish ( ) ;
206
+ }
207
+
208
+ write ! ( f, "({:?}: " , this. map( |pred| pred. trait_ref. args[ 0 ] ) ) ?;
209
+ match this. data . polarity {
210
+ PredicatePolarity :: Positive => ( ) ,
211
+ PredicatePolarity :: Negative => write ! ( f, "!" ) ?,
212
+ } ;
213
+ I :: print_def_path ( this. data . trait_ref . def_id , f) ?;
214
+
215
+ match this. data . trait_ref . args . len ( ) {
216
+ 0 => unreachable ! ( ) ,
217
+ 1 => write ! ( f, ")" ) , // the first arg is the self type
218
+ 2 => write ! ( f, "<{:?}>)" , this. map( |trait_ref| trait_ref. trait_ref. args[ 1 ] ) ) ,
219
+ 3 .. => {
220
+ write ! ( f, "<{:?}" , this. map( |trait_ref| trait_ref. trait_ref. args[ 1 ] ) ) ?;
221
+ for arg in & this. data . trait_ref . args [ 2 ..] {
222
+ let arg = this. wrap ( arg) ;
223
+ write ! ( f, ", {:?}" , arg) ?;
224
+ }
225
+ write ! ( f, ">)" )
226
+ }
227
+ }
152
228
}
153
229
}
154
230
0 commit comments