@@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
9
9
use rustc_middle:: hir:: map as hir_map;
10
10
use rustc_middle:: ty:: { self , TyCtxt } ;
11
11
use 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 } ;
13
13
use rustc_session:: Session ;
14
14
use rustc_span:: symbol:: Ident ;
15
15
use rustc_span:: FileName ;
@@ -42,43 +42,41 @@ where
42
42
F : FnOnce ( & dyn PrinterSupport ) -> A ,
43
43
{
44
44
match * ppmode {
45
- PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
45
+ Normal | EveryBodyLoops | Expanded => {
46
46
let annotation = NoAnn { sess, tcx } ;
47
47
f ( & annotation)
48
48
}
49
49
50
- PpmIdentified | PpmExpandedIdentified => {
50
+ Identified | ExpandedIdentified => {
51
51
let annotation = IdentifiedAnnotation { sess, tcx } ;
52
52
f ( & annotation)
53
53
}
54
- PpmExpandedHygiene => {
54
+ ExpandedHygiene => {
55
55
let annotation = HygieneAnnotation { sess } ;
56
56
f ( & annotation)
57
57
}
58
- _ => panic ! ( "Should use call_with_pp_support_hir" ) ,
59
58
}
60
59
}
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
62
61
where
63
62
F : FnOnce ( & dyn HirPrinterSupport < ' _ > , & hir:: Crate < ' _ > ) -> A ,
64
63
{
65
64
match * ppmode {
66
- PpmNormal => {
65
+ PpHirMode :: Normal => {
67
66
let annotation = NoAnn { sess : tcx. sess , tcx : Some ( tcx) } ;
68
67
f ( & annotation, tcx. hir ( ) . krate ( ) )
69
68
}
70
69
71
- PpmIdentified => {
70
+ PpHirMode :: Identified => {
72
71
let annotation = IdentifiedAnnotation { sess : tcx. sess , tcx : Some ( tcx) } ;
73
72
f ( & annotation, tcx. hir ( ) . krate ( ) )
74
73
}
75
- PpmTyped => {
74
+ PpHirMode :: Typed => {
76
75
abort_on_err ( tcx. analysis ( LOCAL_CRATE ) , tcx. sess ) ;
77
76
78
77
let annotation = TypedAnnotation { tcx, maybe_typeck_results : Cell :: new ( None ) } ;
79
78
tcx. dep_graph . with_ignore ( || f ( & annotation, tcx. hir ( ) . krate ( ) ) )
80
79
}
81
- _ => panic ! ( "Should use call_with_pp_support" ) ,
82
80
}
83
81
}
84
82
@@ -393,16 +391,13 @@ pub fn print_after_parsing(
393
391
) {
394
392
let ( src, src_name) = get_source ( input, sess) ;
395
393
396
- let mut out = String :: new ( ) ;
397
-
398
- if let PpmSource ( s) = ppm {
394
+ let out = if let Source ( s) = ppm {
399
395
// Silently ignores an identified node.
400
- let out = & mut out;
401
396
call_with_pp_support ( & s, sess, None , move |annotation| {
402
397
debug ! ( "pretty printing source code {:?}" , s) ;
403
398
let sess = annotation. sess ( ) ;
404
399
let parse = & sess. parse_sess ;
405
- * out = pprust:: print_crate (
400
+ pprust:: print_crate (
406
401
sess. source_map ( ) ,
407
402
krate,
408
403
src_name,
@@ -413,7 +408,7 @@ pub fn print_after_parsing(
413
408
)
414
409
} )
415
410
} else {
416
- unreachable ! ( ) ;
411
+ unreachable ! ( )
417
412
} ;
418
413
419
414
write_or_print ( & out, ofile) ;
@@ -433,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>(
433
428
434
429
let ( src, src_name) = get_source ( input, tcx. sess ) ;
435
430
436
- let mut out = String :: new ( ) ;
437
-
438
- match ppm {
439
- PpmSource ( s) => {
431
+ let out = match ppm {
432
+ Source ( s) => {
440
433
// Silently ignores an identified node.
441
- let out = & mut out;
442
434
call_with_pp_support ( & s, tcx. sess , Some ( tcx) , move |annotation| {
443
435
debug ! ( "pretty printing source code {:?}" , s) ;
444
436
let sess = annotation. sess ( ) ;
445
437
let parse = & sess. parse_sess ;
446
- * out = pprust:: print_crate (
438
+ pprust:: print_crate (
447
439
sess. source_map ( ) ,
448
440
krate,
449
441
src_name,
@@ -455,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>(
455
447
} )
456
448
}
457
449
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
+ } ) ,
467
456
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
+ } ) ,
475
461
476
462
_ => unreachable ! ( ) ,
477
- }
463
+ } ;
478
464
479
465
write_or_print ( & out, ofile) ;
480
466
}
@@ -493,14 +479,10 @@ fn print_with_analysis(
493
479
tcx. analysis ( LOCAL_CRATE ) ?;
494
480
495
481
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 ( ) ,
501
484
_ => unreachable ! ( ) ,
502
485
}
503
- . unwrap ( ) ;
504
486
505
487
let out = std:: str:: from_utf8 ( & out) . unwrap ( ) ;
506
488
write_or_print ( out, ofile) ;
0 commit comments