@@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
99use rustc_middle:: hir:: map as hir_map;
1010use rustc_middle:: ty:: { self , TyCtxt } ;
1111use rustc_mir:: util:: { write_mir_graphviz, write_mir_pretty} ;
12- use rustc_session:: config:: { Input , PpMode , PpSourceMode } ;
12+ use rustc_session:: config:: { Input , PpHirMode , PpMode , PpSourceMode } ;
1313use rustc_session:: Session ;
1414use rustc_span:: symbol:: Ident ;
1515use rustc_span:: FileName ;
@@ -42,43 +42,41 @@ where
4242 F : FnOnce ( & dyn PrinterSupport ) -> A ,
4343{
4444 match * ppmode {
45- PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
45+ Normal | EveryBodyLoops | Expanded => {
4646 let annotation = NoAnn { sess, tcx } ;
4747 f ( & annotation)
4848 }
4949
50- PpmIdentified | PpmExpandedIdentified => {
50+ Identified | ExpandedIdentified => {
5151 let annotation = IdentifiedAnnotation { sess, tcx } ;
5252 f ( & annotation)
5353 }
54- PpmExpandedHygiene => {
54+ ExpandedHygiene => {
5555 let annotation = HygieneAnnotation { sess } ;
5656 f ( & annotation)
5757 }
58- _ => panic ! ( "Should use call_with_pp_support_hir" ) ,
5958 }
6059}
61- fn call_with_pp_support_hir < A , F > ( ppmode : & PpSourceMode , tcx : TyCtxt < ' _ > , f : F ) -> A
60+ fn call_with_pp_support_hir < A , F > ( ppmode : & PpHirMode , tcx : TyCtxt < ' _ > , f : F ) -> A
6261where
6362 F : FnOnce ( & dyn HirPrinterSupport < ' _ > , & hir:: Crate < ' _ > ) -> A ,
6463{
6564 match * ppmode {
66- PpmNormal => {
65+ PpHirMode :: Normal => {
6766 let annotation = NoAnn { sess : tcx. sess , tcx : Some ( tcx) } ;
6867 f ( & annotation, tcx. hir ( ) . krate ( ) )
6968 }
7069
71- PpmIdentified => {
70+ PpHirMode :: Identified => {
7271 let annotation = IdentifiedAnnotation { sess : tcx. sess , tcx : Some ( tcx) } ;
7372 f ( & annotation, tcx. hir ( ) . krate ( ) )
7473 }
75- PpmTyped => {
74+ PpHirMode :: Typed => {
7675 abort_on_err ( tcx. analysis ( LOCAL_CRATE ) , tcx. sess ) ;
7776
7877 let annotation = TypedAnnotation { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
7978 tcx. dep_graph . with_ignore ( || f ( & annotation, tcx. hir ( ) . krate ( ) ) )
8079 }
81- _ => panic ! ( "Should use call_with_pp_support" ) ,
8280 }
8381}
8482
@@ -393,16 +391,13 @@ pub fn print_after_parsing(
393391) {
394392 let ( src, src_name) = get_source ( input, sess) ;
395393
396- let mut out = String :: new ( ) ;
397-
398- if let PpmSource ( s) = ppm {
394+ let out = if let Source ( s) = ppm {
399395 // Silently ignores an identified node.
400- let out = & mut out;
401396 call_with_pp_support ( & s, sess, None , move |annotation| {
402397 debug ! ( "pretty printing source code {:?}" , s) ;
403398 let sess = annotation. sess ( ) ;
404399 let parse = & sess. parse_sess ;
405- * out = pprust:: print_crate (
400+ pprust:: print_crate (
406401 sess. source_map ( ) ,
407402 krate,
408403 src_name,
@@ -413,7 +408,7 @@ pub fn print_after_parsing(
413408 )
414409 } )
415410 } else {
416- unreachable ! ( ) ;
411+ unreachable ! ( )
417412 } ;
418413
419414 write_or_print ( & out, ofile) ;
@@ -433,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>(
433428
434429 let ( src, src_name) = get_source ( input, tcx. sess ) ;
435430
436- let mut out = String :: new ( ) ;
437-
438- match ppm {
439- PpmSource ( s) => {
431+ let out = match ppm {
432+ Source ( s) => {
440433 // Silently ignores an identified node.
441- let out = & mut out;
442434 call_with_pp_support ( & s, tcx. sess , Some ( tcx) , move |annotation| {
443435 debug ! ( "pretty printing source code {:?}" , s) ;
444436 let sess = annotation. sess ( ) ;
445437 let parse = & sess. parse_sess ;
446- * out = pprust:: print_crate (
438+ pprust:: print_crate (
447439 sess. source_map ( ) ,
448440 krate,
449441 src_name,
@@ -455,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>(
455447 } )
456448 }
457449
458- PpmHir ( s) => {
459- let out = & mut out;
460- call_with_pp_support_hir ( & s, tcx, move |annotation, krate| {
461- debug ! ( "pretty printing source code {:?}" , s) ;
462- let sess = annotation. sess ( ) ;
463- let sm = sess. source_map ( ) ;
464- * out = pprust_hir:: print_crate ( sm, krate, src_name, src, annotation. pp_ann ( ) )
465- } )
466- }
450+ Hir ( s) => call_with_pp_support_hir ( & s, tcx, move |annotation, krate| {
451+ debug ! ( "pretty printing HIR {:?}" , s) ;
452+ let sess = annotation. sess ( ) ;
453+ let sm = sess. source_map ( ) ;
454+ pprust_hir:: print_crate ( sm, krate, src_name, src, annotation. pp_ann ( ) )
455+ } ) ,
467456
468- PpmHirTree ( s) => {
469- let out = & mut out;
470- call_with_pp_support_hir ( & s, tcx, move |_annotation, krate| {
471- debug ! ( "pretty printing source code {:?}" , s) ;
472- * out = format ! ( "{:#?}" , krate) ;
473- } ) ;
474- }
457+ HirTree => call_with_pp_support_hir ( & PpHirMode :: Normal , tcx, move |_annotation, krate| {
458+ debug ! ( "pretty printing HIR tree" ) ;
459+ format ! ( "{:#?}" , krate)
460+ } ) ,
475461
476462 _ => unreachable ! ( ) ,
477- }
463+ } ;
478464
479465 write_or_print ( & out, ofile) ;
480466}
@@ -493,14 +479,10 @@ fn print_with_analysis(
493479 tcx. analysis ( LOCAL_CRATE ) ?;
494480
495481 match ppm {
496- PpmMir | PpmMirCFG => match ppm {
497- PpmMir => write_mir_pretty ( tcx, None , & mut out) ,
498- PpmMirCFG => write_mir_graphviz ( tcx, None , & mut out) ,
499- _ => unreachable ! ( ) ,
500- } ,
482+ Mir => write_mir_pretty ( tcx, None , & mut out) . unwrap ( ) ,
483+ MirCFG => write_mir_graphviz ( tcx, None , & mut out) . unwrap ( ) ,
501484 _ => unreachable ! ( ) ,
502485 }
503- . unwrap ( ) ;
504486
505487 let out = std:: str:: from_utf8 ( & out) . unwrap ( ) ;
506488 write_or_print ( out, ofile) ;
0 commit comments