1
1
//! The various pretty-printing routines.
2
2
3
3
use rustc_ast as ast;
4
- use rustc_ast_pretty:: pprust;
4
+ use rustc_ast_pretty:: pprust as pprust_ast ;
5
5
use rustc_errors:: ErrorGuaranteed ;
6
6
use rustc_hir as hir;
7
7
use rustc_hir_pretty as pprust_hir;
@@ -26,26 +26,25 @@ use crate::abort_on_err;
26
26
// analysis results) on to the chosen pretty-printer, along with the
27
27
// `&PpAnn` object.
28
28
//
29
- // Note that since the `&PrinterSupport ` is freshly constructed on each
29
+ // Note that since the `&AstPrinterSupport ` is freshly constructed on each
30
30
// call, it would not make sense to try to attach the lifetime of `self`
31
31
// to the lifetime of the `&PrinterObject`.
32
32
33
- /// Constructs a `PrinterSupport ` object and passes it to `f`.
34
- fn call_with_pp_support < ' tcx , A , F > (
33
+ /// Constructs an `AstPrinterSupport ` object and passes it to `f`.
34
+ fn call_with_pp_support_ast < ' tcx , A , F > (
35
35
ppmode : & PpSourceMode ,
36
36
sess : & ' tcx Session ,
37
37
tcx : Option < TyCtxt < ' tcx > > ,
38
38
f : F ,
39
39
) -> A
40
40
where
41
- F : FnOnce ( & dyn PrinterSupport ) -> A ,
41
+ F : FnOnce ( & dyn AstPrinterSupport ) -> A ,
42
42
{
43
43
match * ppmode {
44
44
Normal | Expanded => {
45
45
let annotation = NoAnn { sess, tcx } ;
46
46
f ( & annotation)
47
47
}
48
-
49
48
Identified | ExpandedIdentified => {
50
49
let annotation = IdentifiedAnnotation { sess, tcx } ;
51
50
f ( & annotation)
65
64
let annotation = NoAnn { sess : tcx. sess , tcx : Some ( tcx) } ;
66
65
f ( & annotation, tcx. hir ( ) )
67
66
}
68
-
69
67
PpHirMode :: Identified => {
70
68
let annotation = IdentifiedAnnotation { sess : tcx. sess , tcx : Some ( tcx) } ;
71
69
f ( & annotation, tcx. hir ( ) )
79
77
}
80
78
}
81
79
82
- trait PrinterSupport : pprust :: PpAnn {
80
+ trait AstPrinterSupport : pprust_ast :: PpAnn {
83
81
/// Provides a uniform interface for re-extracting a reference to a
84
82
/// `Session` from a value that now owns it.
85
83
fn sess ( & self ) -> & Session ;
@@ -88,7 +86,7 @@ trait PrinterSupport: pprust::PpAnn {
88
86
///
89
87
/// (Rust does not yet support upcasting from a trait object to
90
88
/// an object for one of its supertraits.)
91
- fn pp_ann ( & self ) -> & dyn pprust :: PpAnn ;
89
+ fn pp_ann ( & self ) -> & dyn pprust_ast :: PpAnn ;
92
90
}
93
91
94
92
trait HirPrinterSupport < ' hir > : pprust_hir:: PpAnn {
@@ -112,12 +110,12 @@ struct NoAnn<'hir> {
112
110
tcx : Option < TyCtxt < ' hir > > ,
113
111
}
114
112
115
- impl < ' hir > PrinterSupport for NoAnn < ' hir > {
113
+ impl < ' hir > AstPrinterSupport for NoAnn < ' hir > {
116
114
fn sess ( & self ) -> & Session {
117
115
self . sess
118
116
}
119
117
120
- fn pp_ann ( & self ) -> & dyn pprust :: PpAnn {
118
+ fn pp_ann ( & self ) -> & dyn pprust_ast :: PpAnn {
121
119
self
122
120
}
123
121
}
@@ -136,7 +134,7 @@ impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> {
136
134
}
137
135
}
138
136
139
- impl < ' hir > pprust :: PpAnn for NoAnn < ' hir > { }
137
+ impl < ' hir > pprust_ast :: PpAnn for NoAnn < ' hir > { }
140
138
impl < ' hir > pprust_hir:: PpAnn for NoAnn < ' hir > {
141
139
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
142
140
if let Some ( tcx) = self . tcx {
@@ -150,44 +148,46 @@ struct IdentifiedAnnotation<'hir> {
150
148
tcx : Option < TyCtxt < ' hir > > ,
151
149
}
152
150
153
- impl < ' hir > PrinterSupport for IdentifiedAnnotation < ' hir > {
151
+ impl < ' hir > AstPrinterSupport for IdentifiedAnnotation < ' hir > {
154
152
fn sess ( & self ) -> & Session {
155
153
self . sess
156
154
}
157
155
158
- fn pp_ann ( & self ) -> & dyn pprust :: PpAnn {
156
+ fn pp_ann ( & self ) -> & dyn pprust_ast :: PpAnn {
159
157
self
160
158
}
161
159
}
162
160
163
- impl < ' hir > pprust :: PpAnn for IdentifiedAnnotation < ' hir > {
164
- fn pre ( & self , s : & mut pprust :: State < ' _ > , node : pprust :: AnnNode < ' _ > ) {
165
- if let pprust :: AnnNode :: Expr ( _) = node {
161
+ impl < ' hir > pprust_ast :: PpAnn for IdentifiedAnnotation < ' hir > {
162
+ fn pre ( & self , s : & mut pprust_ast :: State < ' _ > , node : pprust_ast :: AnnNode < ' _ > ) {
163
+ if let pprust_ast :: AnnNode :: Expr ( _) = node {
166
164
s. popen ( ) ;
167
165
}
168
166
}
169
- fn post ( & self , s : & mut pprust :: State < ' _ > , node : pprust :: AnnNode < ' _ > ) {
167
+ fn post ( & self , s : & mut pprust_ast :: State < ' _ > , node : pprust_ast :: AnnNode < ' _ > ) {
170
168
match node {
171
- pprust:: AnnNode :: Crate ( _) | pprust:: AnnNode :: Ident ( _) | pprust:: AnnNode :: Name ( _) => { }
169
+ pprust_ast:: AnnNode :: Crate ( _)
170
+ | pprust_ast:: AnnNode :: Ident ( _)
171
+ | pprust_ast:: AnnNode :: Name ( _) => { }
172
172
173
- pprust :: AnnNode :: Item ( item) => {
173
+ pprust_ast :: AnnNode :: Item ( item) => {
174
174
s. s . space ( ) ;
175
175
s. synth_comment ( item. id . to_string ( ) )
176
176
}
177
- pprust :: AnnNode :: SubItem ( id) => {
177
+ pprust_ast :: AnnNode :: SubItem ( id) => {
178
178
s. s . space ( ) ;
179
179
s. synth_comment ( id. to_string ( ) )
180
180
}
181
- pprust :: AnnNode :: Block ( blk) => {
181
+ pprust_ast :: AnnNode :: Block ( blk) => {
182
182
s. s . space ( ) ;
183
183
s. synth_comment ( format ! ( "block {}" , blk. id) )
184
184
}
185
- pprust :: AnnNode :: Expr ( expr) => {
185
+ pprust_ast :: AnnNode :: Expr ( expr) => {
186
186
s. s . space ( ) ;
187
187
s. synth_comment ( expr. id . to_string ( ) ) ;
188
188
s. pclose ( )
189
189
}
190
- pprust :: AnnNode :: Pat ( pat) => {
190
+ pprust_ast :: AnnNode :: Pat ( pat) => {
191
191
s. s . space ( ) ;
192
192
s. synth_comment ( format ! ( "pat {}" , pat. id) ) ;
193
193
}
@@ -256,28 +256,28 @@ struct HygieneAnnotation<'a> {
256
256
sess : & ' a Session ,
257
257
}
258
258
259
- impl < ' a > PrinterSupport for HygieneAnnotation < ' a > {
259
+ impl < ' a > AstPrinterSupport for HygieneAnnotation < ' a > {
260
260
fn sess ( & self ) -> & Session {
261
261
self . sess
262
262
}
263
263
264
- fn pp_ann ( & self ) -> & dyn pprust :: PpAnn {
264
+ fn pp_ann ( & self ) -> & dyn pprust_ast :: PpAnn {
265
265
self
266
266
}
267
267
}
268
268
269
- impl < ' a > pprust :: PpAnn for HygieneAnnotation < ' a > {
270
- fn post ( & self , s : & mut pprust :: State < ' _ > , node : pprust :: AnnNode < ' _ > ) {
269
+ impl < ' a > pprust_ast :: PpAnn for HygieneAnnotation < ' a > {
270
+ fn post ( & self , s : & mut pprust_ast :: State < ' _ > , node : pprust_ast :: AnnNode < ' _ > ) {
271
271
match node {
272
- pprust :: AnnNode :: Ident ( & Ident { name, span } ) => {
272
+ pprust_ast :: AnnNode :: Ident ( & Ident { name, span } ) => {
273
273
s. s . space ( ) ;
274
274
s. synth_comment ( format ! ( "{}{:?}" , name. as_u32( ) , span. ctxt( ) ) )
275
275
}
276
- pprust :: AnnNode :: Name ( & name) => {
276
+ pprust_ast :: AnnNode :: Name ( & name) => {
277
277
s. s . space ( ) ;
278
278
s. synth_comment ( name. as_u32 ( ) . to_string ( ) )
279
279
}
280
- pprust :: AnnNode :: Crate ( _) => {
280
+ pprust_ast :: AnnNode :: Crate ( _) => {
281
281
s. s . hardbreak ( ) ;
282
282
let verbose = self . sess . verbose ( ) ;
283
283
s. synth_comment ( rustc_span:: hygiene:: debug_hygiene_data ( verbose) ) ;
@@ -366,11 +366,11 @@ pub fn print_after_parsing(sess: &Session, krate: &ast::Crate, ppm: PpMode) {
366
366
let out = match ppm {
367
367
Source ( s) => {
368
368
// Silently ignores an identified node.
369
- call_with_pp_support ( & s, sess, None , move |annotation| {
369
+ call_with_pp_support_ast ( & s, sess, None , move |annotation| {
370
370
debug ! ( "pretty printing source code {:?}" , s) ;
371
371
let sess = annotation. sess ( ) ;
372
372
let parse = & sess. parse_sess ;
373
- pprust :: print_crate (
373
+ pprust_ast :: print_crate (
374
374
sess. source_map ( ) ,
375
375
krate,
376
376
src_name,
@@ -403,11 +403,11 @@ pub fn print_after_hir_lowering<'tcx>(tcx: TyCtxt<'tcx>, ppm: PpMode) {
403
403
let out = match ppm {
404
404
Source ( s) => {
405
405
// Silently ignores an identified node.
406
- call_with_pp_support ( & s, tcx. sess , Some ( tcx) , move |annotation| {
406
+ call_with_pp_support_ast ( & s, tcx. sess , Some ( tcx) , move |annotation| {
407
407
debug ! ( "pretty printing source code {:?}" , s) ;
408
408
let sess = annotation. sess ( ) ;
409
409
let parse = & sess. parse_sess ;
410
- pprust :: print_crate (
410
+ pprust_ast :: print_crate (
411
411
sess. source_map ( ) ,
412
412
& tcx. resolver_for_lowering ( ( ) ) . borrow ( ) . 1 ,
413
413
src_name,
0 commit comments