@@ -19,24 +19,27 @@ pub use self::PpMode::*;
1919pub use self :: PpSourceMode :: * ;
2020use crate :: abort_on_err;
2121
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 > ,
2428}
2529
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 > {
2831 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+ )
3237 }
3338}
3439
35- struct IdentifiedAnnotation < ' tcx > {
36- tcx : Option < TyCtxt < ' tcx > > ,
37- }
40+ struct AstIdentifiedAnn ;
3841
39- impl < ' tcx > pprust_ast:: PpAnn for IdentifiedAnnotation < ' tcx > {
42+ impl pprust_ast:: PpAnn for AstIdentifiedAnn {
4043 fn pre ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
4144 if let pprust_ast:: AnnNode :: Expr ( _) = node {
4245 s. popen ( ) ;
@@ -74,11 +77,17 @@ impl<'tcx> pprust_ast::PpAnn for IdentifiedAnnotation<'tcx> {
7477 }
7578}
7679
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 > {
7885 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+ )
8291 }
8392
8493 fn pre ( & self , s : & mut pprust_hir:: State < ' _ > , node : pprust_hir:: AnnNode < ' _ > ) {
@@ -119,11 +128,11 @@ impl<'tcx> pprust_hir::PpAnn for IdentifiedAnnotation<'tcx> {
119128 }
120129}
121130
122- struct HygieneAnnotation < ' a > {
131+ struct AstHygieneAnn < ' a > {
123132 sess : & ' a Session ,
124133}
125134
126- impl < ' a > pprust_ast:: PpAnn for HygieneAnnotation < ' a > {
135+ impl < ' a > pprust_ast:: PpAnn for AstHygieneAnn < ' a > {
127136 fn post ( & self , s : & mut pprust_ast:: State < ' _ > , node : pprust_ast:: AnnNode < ' _ > ) {
128137 match node {
129138 pprust_ast:: AnnNode :: Ident ( & Ident { name, span } ) => {
@@ -145,12 +154,12 @@ impl<'a> pprust_ast::PpAnn for HygieneAnnotation<'a> {
145154 }
146155}
147156
148- struct TypedAnnotation < ' tcx > {
157+ struct HirTypedAnn < ' tcx > {
149158 tcx : TyCtxt < ' tcx > ,
150159 maybe_typeck_results : Cell < Option < & ' tcx ty:: TypeckResults < ' tcx > > > ,
151160}
152161
153- impl < ' tcx > pprust_hir:: PpAnn for TypedAnnotation < ' tcx > {
162+ impl < ' tcx > pprust_hir:: PpAnn for HirTypedAnn < ' tcx > {
154163 fn nested ( & self , state : & mut pprust_hir:: State < ' _ > , nested : pprust_hir:: Nested ) {
155164 let old_maybe_typeck_results = self . maybe_typeck_results . get ( ) ;
156165 if let pprust_hir:: Nested :: Body ( id) = nested {
@@ -242,11 +251,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
242251 Source ( s) => {
243252 debug ! ( "pretty printing source code {:?}" , s) ;
244253 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 } ) ,
250259 } ;
251260 let parse = & sess. parse_sess ;
252261 let is_expanded = ppm. needs_ast_map ( ) ;
@@ -289,15 +298,15 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
289298 } ;
290299 match s {
291300 PpHirMode :: Normal => {
292- let annotation = NoAnn { tcx : Some ( tcx ) } ;
301+ let annotation = HirNoAnn { tcx } ;
293302 f ( & annotation)
294303 }
295304 PpHirMode :: Identified => {
296- let annotation = IdentifiedAnnotation { tcx : Some ( tcx ) } ;
305+ let annotation = HirIdentifiedAnn { tcx } ;
297306 f ( & annotation)
298307 }
299308 PpHirMode :: Typed => {
300- let annotation = TypedAnnotation { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
309+ let annotation = HirTypedAnn { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
301310 tcx. dep_graph . with_ignore ( || f ( & annotation) )
302311 }
303312 }
0 commit comments