55
55
}
56
56
}
57
57
}
58
+
58
59
fn call_with_pp_support_hir < A , F > ( ppmode : & PpHirMode , tcx : TyCtxt < ' _ > , f : F ) -> A
59
60
where
60
- F : FnOnce ( & dyn HirPrinterSupport < ' _ > , hir_map:: Map < ' _ > ) -> A ,
61
+ F : FnOnce ( & dyn HirPrinterSupport , hir_map:: Map < ' _ > ) -> A ,
61
62
{
62
63
match * ppmode {
63
64
PpHirMode :: Normal => {
@@ -77,54 +78,28 @@ where
77
78
}
78
79
}
79
80
80
- trait AstPrinterSupport : pprust_ast :: PpAnn {
81
+ trait Sess {
81
82
/// Provides a uniform interface for re-extracting a reference to a
82
- /// `Session` from a value that now owns it .
83
+ /// `Session`.
83
84
fn sess ( & self ) -> & Session ;
84
-
85
- /// Produces the pretty-print annotation object.
86
- ///
87
- /// (Rust does not yet support upcasting from a trait object to
88
- /// an object for one of its supertraits.)
89
- fn pp_ann ( & self ) -> & dyn pprust_ast:: PpAnn ;
90
85
}
91
86
92
- trait HirPrinterSupport < ' hir > : pprust_hir:: PpAnn {
93
- /// Provides a uniform interface for re-extracting a reference to a
94
- /// `Session` from a value that now owns it.
95
- fn sess ( & self ) -> & Session ;
96
-
97
- /// Produces the pretty-print annotation object.
98
- ///
99
- /// (Rust does not yet support upcasting from a trait object to
100
- /// an object for one of its supertraits.)
101
- fn pp_ann ( & self ) -> & dyn pprust_hir:: PpAnn ;
102
- }
87
+ trait AstPrinterSupport : pprust_ast:: PpAnn + Sess { }
88
+ trait HirPrinterSupport : pprust_hir:: PpAnn + Sess { }
103
89
104
90
struct NoAnn < ' hir > {
105
91
sess : & ' hir Session ,
106
92
tcx : Option < TyCtxt < ' hir > > ,
107
93
}
108
94
109
- impl < ' hir > AstPrinterSupport for NoAnn < ' hir > {
95
+ impl < ' hir > Sess for NoAnn < ' hir > {
110
96
fn sess ( & self ) -> & Session {
111
97
self . sess
112
98
}
113
-
114
- fn pp_ann ( & self ) -> & dyn pprust_ast:: PpAnn {
115
- self
116
- }
117
99
}
118
100
119
- impl < ' hir > HirPrinterSupport < ' hir > for NoAnn < ' hir > {
120
- fn sess ( & self ) -> & Session {
121
- self . sess
122
- }
123
-
124
- fn pp_ann ( & self ) -> & dyn pprust_hir:: PpAnn {
125
- self
126
- }
127
- }
101
+ impl < ' tcx > AstPrinterSupport for NoAnn < ' tcx > { }
102
+ impl < ' hir > HirPrinterSupport for NoAnn < ' hir > { }
128
103
129
104
impl < ' hir > pprust_ast:: PpAnn for NoAnn < ' hir > { }
130
105
impl < ' hir > pprust_hir:: PpAnn for NoAnn < ' hir > {
@@ -140,22 +115,21 @@ struct IdentifiedAnnotation<'hir> {
140
115
tcx : Option < TyCtxt < ' hir > > ,
141
116
}
142
117
143
- impl < ' hir > AstPrinterSupport for IdentifiedAnnotation < ' hir > {
118
+ impl < ' hir > Sess for IdentifiedAnnotation < ' hir > {
144
119
fn sess ( & self ) -> & Session {
145
120
self . sess
146
121
}
147
-
148
- fn pp_ann ( & self ) -> & dyn pprust_ast:: PpAnn {
149
- self
150
- }
151
122
}
152
123
124
+ impl < ' hir > AstPrinterSupport for IdentifiedAnnotation < ' hir > { }
125
+
153
126
impl < ' hir > pprust_ast:: PpAnn for IdentifiedAnnotation < ' hir > {
154
127
fn pre ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
155
128
if let pprust_ast:: AnnNode :: Expr ( _) = node {
156
129
s. popen ( ) ;
157
130
}
158
131
}
132
+
159
133
fn post ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
160
134
match node {
161
135
pprust_ast:: AnnNode :: Crate ( _)
@@ -187,27 +161,21 @@ impl<'hir> pprust_ast::PpAnn for IdentifiedAnnotation<'hir> {
187
161
}
188
162
}
189
163
190
- impl < ' hir > HirPrinterSupport < ' hir > for IdentifiedAnnotation < ' hir > {
191
- fn sess ( & self ) -> & Session {
192
- self . sess
193
- }
194
-
195
- fn pp_ann ( & self ) -> & dyn pprust_hir:: PpAnn {
196
- self
197
- }
198
- }
164
+ impl < ' hir > HirPrinterSupport for IdentifiedAnnotation < ' hir > { }
199
165
200
166
impl < ' hir > pprust_hir:: PpAnn for IdentifiedAnnotation < ' hir > {
201
167
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
202
168
if let Some ( ref tcx) = self . tcx {
203
169
pprust_hir:: PpAnn :: nested ( & ( & tcx. hir ( ) as & dyn hir:: intravisit:: Map < ' _ > ) , state, nested)
204
170
}
205
171
}
172
+
206
173
fn pre ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
207
174
if let pprust_hir:: AnnNode :: Expr ( _) = node {
208
175
s. popen ( ) ;
209
176
}
210
177
}
178
+
211
179
fn post ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
212
180
match node {
213
181
pprust_hir:: AnnNode :: Name ( _) => { }
@@ -244,16 +212,14 @@ struct HygieneAnnotation<'a> {
244
212
sess : & ' a Session ,
245
213
}
246
214
247
- impl < ' a > AstPrinterSupport for HygieneAnnotation < ' a > {
215
+ impl < ' a > Sess for HygieneAnnotation < ' a > {
248
216
fn sess ( & self ) -> & Session {
249
217
self . sess
250
218
}
251
-
252
- fn pp_ann ( & self ) -> & dyn pprust_ast:: PpAnn {
253
- self
254
- }
255
219
}
256
220
221
+ impl < ' a > AstPrinterSupport for HygieneAnnotation < ' a > { }
222
+
257
223
impl < ' a > pprust_ast:: PpAnn for HygieneAnnotation < ' a > {
258
224
fn post ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
259
225
match node {
@@ -281,16 +247,14 @@ struct TypedAnnotation<'tcx> {
281
247
maybe_typeck_results : Cell < Option < & ' tcx ty:: TypeckResults < ' tcx > > > ,
282
248
}
283
249
284
- impl < ' tcx > HirPrinterSupport < ' tcx > for TypedAnnotation < ' tcx > {
250
+ impl < ' tcx > Sess for TypedAnnotation < ' tcx > {
285
251
fn sess ( & self ) -> & Session {
286
252
self . tcx . sess
287
253
}
288
-
289
- fn pp_ann ( & self ) -> & dyn pprust_hir:: PpAnn {
290
- self
291
- }
292
254
}
293
255
256
+ impl < ' tcx > HirPrinterSupport for TypedAnnotation < ' tcx > { }
257
+
294
258
impl < ' tcx > pprust_hir:: PpAnn for TypedAnnotation < ' tcx > {
295
259
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
296
260
let old_maybe_typeck_results = self . maybe_typeck_results . get ( ) ;
@@ -301,11 +265,13 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
301
265
pprust_hir:: PpAnn :: nested ( pp_ann, state, nested) ;
302
266
self . maybe_typeck_results . set ( old_maybe_typeck_results) ;
303
267
}
268
+
304
269
fn pre ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
305
270
if let pprust_hir:: AnnNode :: Expr ( _) = node {
306
271
s. popen ( ) ;
307
272
}
308
273
}
274
+
309
275
fn post ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
310
276
if let pprust_hir:: AnnNode :: Expr ( expr) = node {
311
277
let typeck_results = self . maybe_typeck_results . get ( ) . or_else ( || {
@@ -359,7 +325,7 @@ pub fn print_after_parsing(sess: &Session, krate: &ast::Crate, ppm: PpMode) {
359
325
krate,
360
326
src_name,
361
327
src,
362
- annotation. pp_ann ( ) ,
328
+ annotation,
363
329
false ,
364
330
parse. edition ,
365
331
& sess. parse_sess . attr_id_generator ,
@@ -396,7 +362,7 @@ pub fn print_after_hir_lowering<'tcx>(tcx: TyCtxt<'tcx>, ppm: PpMode) {
396
362
& tcx. resolver_for_lowering ( ( ) ) . borrow ( ) . 1 ,
397
363
src_name,
398
364
src,
399
- annotation. pp_ann ( ) ,
365
+ annotation,
400
366
true ,
401
367
parse. edition ,
402
368
& sess. parse_sess . attr_id_generator ,
@@ -414,14 +380,7 @@ pub fn print_after_hir_lowering<'tcx>(tcx: TyCtxt<'tcx>, ppm: PpMode) {
414
380
let sess = annotation. sess ( ) ;
415
381
let sm = sess. source_map ( ) ;
416
382
let attrs = |id| hir_map. attrs ( id) ;
417
- pprust_hir:: print_crate (
418
- sm,
419
- hir_map. root_module ( ) ,
420
- src_name,
421
- src,
422
- & attrs,
423
- annotation. pp_ann ( ) ,
424
- )
383
+ pprust_hir:: print_crate ( sm, hir_map. root_module ( ) , src_name, src, & attrs, annotation)
425
384
} ) ,
426
385
427
386
HirTree => {
0 commit comments