@@ -68,6 +68,7 @@ mod error;
68
68
mod fold;
69
69
crate mod formats;
70
70
pub mod html;
71
+ mod json;
71
72
mod markdown;
72
73
mod passes;
73
74
mod test;
@@ -450,6 +451,28 @@ fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> i32 {
450
451
}
451
452
}
452
453
454
+ fn run_renderer < T : formats:: FormatRenderer > (
455
+ krate : clean:: Crate ,
456
+ renderopts : config:: RenderOptions ,
457
+ render_info : config:: RenderInfo ,
458
+ diag : & rustc_errors:: Handler ,
459
+ edition : rustc_span:: edition:: Edition ,
460
+ ) -> i32 {
461
+ match formats:: run_format :: < T > ( krate, renderopts, render_info, & diag, edition) {
462
+ Ok ( _) => rustc_driver:: EXIT_SUCCESS ,
463
+ Err ( e) => {
464
+ let mut msg = diag. struct_err ( & format ! ( "couldn't generate documentation: {}" , e. error) ) ;
465
+ let file = e. file . display ( ) . to_string ( ) ;
466
+ if file. is_empty ( ) {
467
+ msg. emit ( )
468
+ } else {
469
+ msg. note ( & format ! ( "failed to create or modify \" {}\" " , file) ) . emit ( )
470
+ }
471
+ rustc_driver:: EXIT_FAILURE
472
+ }
473
+ }
474
+ }
475
+
453
476
fn main_options ( options : config:: Options ) -> i32 {
454
477
let diag = core:: new_handler ( options. error_format , None , & options. debugging_options ) ;
455
478
@@ -480,6 +503,7 @@ fn main_options(options: config::Options) -> i32 {
480
503
let result = rustc_driver:: catch_fatal_errors ( move || {
481
504
let crate_name = options. crate_name . clone ( ) ;
482
505
let crate_version = options. crate_version . clone ( ) ;
506
+ let output_format = options. output_format ;
483
507
let ( mut krate, renderinfo, renderopts) = core:: run_core ( options) ;
484
508
485
509
info ! ( "finished with rustc" ) ;
@@ -502,20 +526,12 @@ fn main_options(options: config::Options) -> i32 {
502
526
info ! ( "going to format" ) ;
503
527
let ( error_format, edition, debugging_options) = diag_opts;
504
528
let diag = core:: new_handler ( error_format, None , & debugging_options) ;
505
- match formats:: run_format :: < html:: render:: Context > (
506
- krate, renderopts, renderinfo, & diag, edition,
507
- ) {
508
- Ok ( _) => rustc_driver:: EXIT_SUCCESS ,
509
- Err ( e) => {
510
- let mut msg =
511
- diag. struct_err ( & format ! ( "couldn't generate documentation: {}" , e. error) ) ;
512
- let file = e. file . display ( ) . to_string ( ) ;
513
- if file. is_empty ( ) {
514
- msg. emit ( )
515
- } else {
516
- msg. note ( & format ! ( "failed to create or modify \" {}\" " , file) ) . emit ( )
517
- }
518
- rustc_driver:: EXIT_FAILURE
529
+ match output_format {
530
+ None | Some ( config:: OutputFormat :: Html ) => {
531
+ run_renderer :: < html:: render:: Context > ( krate, renderopts, renderinfo, & diag, edition)
532
+ }
533
+ Some ( config:: OutputFormat :: Json ) => {
534
+ run_renderer :: < json:: JsonRenderer > ( krate, renderopts, renderinfo, & diag, edition)
519
535
}
520
536
}
521
537
} ) ;
0 commit comments