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