@@ -18,24 +18,27 @@ pub use self::PpMode::*;
18
18
pub use self :: PpSourceMode :: * ;
19
19
use crate :: abort_on_err;
20
20
21
- struct NoAnn < ' tcx > {
22
- tcx : Option < TyCtxt < ' tcx > > ,
21
+ struct AstNoAnn ;
22
+
23
+ impl pprust_ast:: PpAnn for AstNoAnn { }
24
+
25
+ struct HirNoAnn < ' tcx > {
26
+ tcx : TyCtxt < ' tcx > ,
23
27
}
24
28
25
- impl < ' tcx > pprust_ast:: PpAnn for NoAnn < ' tcx > { }
26
- impl < ' tcx > pprust_hir:: PpAnn for NoAnn < ' tcx > {
29
+ impl < ' tcx > pprust_hir:: PpAnn for HirNoAnn < ' tcx > {
27
30
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
28
- if let Some ( tcx) = self . tcx {
29
- pprust_hir:: PpAnn :: nested ( & ( & tcx. hir ( ) as & dyn hir:: intravisit:: Map < ' _ > ) , state, nested)
30
- }
31
+ pprust_hir:: PpAnn :: nested (
32
+ & ( & self . tcx . hir ( ) as & dyn hir:: intravisit:: Map < ' _ > ) ,
33
+ state,
34
+ nested,
35
+ )
31
36
}
32
37
}
33
38
34
- struct IdentifiedAnnotation < ' tcx > {
35
- tcx : Option < TyCtxt < ' tcx > > ,
36
- }
39
+ struct AstIdentifiedAnn ;
37
40
38
- impl < ' tcx > pprust_ast:: PpAnn for IdentifiedAnnotation < ' tcx > {
41
+ impl pprust_ast:: PpAnn for AstIdentifiedAnn {
39
42
fn pre ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
40
43
if let pprust_ast:: AnnNode :: Expr ( _) = node {
41
44
s. popen ( ) ;
@@ -73,11 +76,17 @@ impl<'tcx> pprust_ast::PpAnn for IdentifiedAnnotation<'tcx> {
73
76
}
74
77
}
75
78
76
- impl < ' tcx > pprust_hir:: PpAnn for IdentifiedAnnotation < ' tcx > {
79
+ struct HirIdentifiedAnn < ' tcx > {
80
+ tcx : TyCtxt < ' tcx > ,
81
+ }
82
+
83
+ impl < ' tcx > pprust_hir:: PpAnn for HirIdentifiedAnn < ' tcx > {
77
84
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
78
- if let Some ( ref tcx) = self . tcx {
79
- pprust_hir:: PpAnn :: nested ( & ( & tcx. hir ( ) as & dyn hir:: intravisit:: Map < ' _ > ) , state, nested)
80
- }
85
+ pprust_hir:: PpAnn :: nested (
86
+ & ( & self . tcx . hir ( ) as & dyn hir:: intravisit:: Map < ' _ > ) ,
87
+ state,
88
+ nested,
89
+ )
81
90
}
82
91
83
92
fn pre ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
@@ -118,11 +127,11 @@ impl<'tcx> pprust_hir::PpAnn for IdentifiedAnnotation<'tcx> {
118
127
}
119
128
}
120
129
121
- struct HygieneAnnotation < ' a > {
130
+ struct AstHygieneAnn < ' a > {
122
131
sess : & ' a Session ,
123
132
}
124
133
125
- impl < ' a > pprust_ast:: PpAnn for HygieneAnnotation < ' a > {
134
+ impl < ' a > pprust_ast:: PpAnn for AstHygieneAnn < ' a > {
126
135
fn post ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
127
136
match node {
128
137
pprust_ast:: AnnNode :: Ident ( & Ident { name, span } ) => {
@@ -144,12 +153,12 @@ impl<'a> pprust_ast::PpAnn for HygieneAnnotation<'a> {
144
153
}
145
154
}
146
155
147
- struct TypedAnnotation < ' tcx > {
156
+ struct HirTypedAnn < ' tcx > {
148
157
tcx : TyCtxt < ' tcx > ,
149
158
maybe_typeck_results : Cell < Option < & ' tcx ty:: TypeckResults < ' tcx > > > ,
150
159
}
151
160
152
- impl < ' tcx > pprust_hir:: PpAnn for TypedAnnotation < ' tcx > {
161
+ impl < ' tcx > pprust_hir:: PpAnn for HirTypedAnn < ' tcx > {
153
162
fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
154
163
let old_maybe_typeck_results = self . maybe_typeck_results . get ( ) ;
155
164
if let pprust_hir:: Nested :: Body ( id) = nested {
@@ -241,11 +250,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
241
250
Source ( s) => {
242
251
debug ! ( "pretty printing source code {:?}" , s) ;
243
252
let annotation: Box < dyn pprust_ast:: PpAnn > = match s {
244
- Normal => Box :: new ( NoAnn { tcx : None } ) ,
245
- Expanded => Box :: new ( NoAnn { tcx : Some ( ex . tcx ( ) ) } ) ,
246
- Identified => Box :: new ( IdentifiedAnnotation { tcx : None } ) ,
247
- ExpandedIdentified => Box :: new ( IdentifiedAnnotation { tcx : Some ( ex . tcx ( ) ) } ) ,
248
- ExpandedHygiene => Box :: new ( HygieneAnnotation { sess } ) ,
253
+ Normal => Box :: new ( AstNoAnn ) ,
254
+ Expanded => Box :: new ( AstNoAnn ) ,
255
+ Identified => Box :: new ( AstIdentifiedAnn ) ,
256
+ ExpandedIdentified => Box :: new ( AstIdentifiedAnn ) ,
257
+ ExpandedHygiene => Box :: new ( AstHygieneAnn { sess } ) ,
249
258
} ;
250
259
let parse = & sess. parse_sess ;
251
260
let is_expanded = ppm. needs_ast_map ( ) ;
@@ -288,15 +297,15 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
288
297
} ;
289
298
match s {
290
299
PpHirMode :: Normal => {
291
- let annotation = NoAnn { tcx : Some ( tcx ) } ;
300
+ let annotation = HirNoAnn { tcx } ;
292
301
f ( & annotation)
293
302
}
294
303
PpHirMode :: Identified => {
295
- let annotation = IdentifiedAnnotation { tcx : Some ( tcx ) } ;
304
+ let annotation = HirIdentifiedAnn { tcx } ;
296
305
f ( & annotation)
297
306
}
298
307
PpHirMode :: Typed => {
299
- let annotation = TypedAnnotation { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
308
+ let annotation = HirTypedAnn { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
300
309
tcx. dep_graph . with_ignore ( || f ( & annotation) )
301
310
}
302
311
}
0 commit comments