@@ -323,20 +323,20 @@ impl Options {
323
323
early_dcx : & mut EarlyDiagCtxt ,
324
324
matches : & getopts:: Matches ,
325
325
args : Vec < String > ,
326
- ) -> Result < ( Options , RenderOptions ) , i32 > {
326
+ ) -> Option < ( Options , RenderOptions ) > {
327
327
// Check for unstable options.
328
328
nightly_options:: check_nightly_options ( early_dcx, matches, & opts ( ) ) ;
329
329
330
330
if args. is_empty ( ) || matches. opt_present ( "h" ) || matches. opt_present ( "help" ) {
331
331
crate :: usage ( "rustdoc" ) ;
332
- return Err ( 0 ) ;
332
+ return None ;
333
333
} else if matches. opt_present ( "version" ) {
334
334
rustc_driver:: version!( & early_dcx, "rustdoc" , matches) ;
335
- return Err ( 0 ) ;
335
+ return None ;
336
336
}
337
337
338
338
if rustc_driver:: describe_flag_categories ( early_dcx, & matches) {
339
- return Err ( 0 ) ;
339
+ return None ;
340
340
}
341
341
342
342
let color = config:: parse_color ( early_dcx, matches) ;
@@ -382,18 +382,15 @@ impl Options {
382
382
}
383
383
}
384
384
385
- return Err ( 0 ) ;
385
+ return None ;
386
386
}
387
387
388
388
let mut emit = Vec :: new ( ) ;
389
389
for list in matches. opt_strs ( "emit" ) {
390
390
for kind in list. split ( ',' ) {
391
391
match kind. parse ( ) {
392
392
Ok ( kind) => emit. push ( kind) ,
393
- Err ( ( ) ) => {
394
- dcx. err ( format ! ( "unrecognized emission type: {kind}" ) ) ;
395
- return Err ( 1 ) ;
396
- }
393
+ Err ( ( ) ) => dcx. fatal ( format ! ( "unrecognized emission type: {kind}" ) ) ,
397
394
}
398
395
}
399
396
}
@@ -403,7 +400,7 @@ impl Options {
403
400
&& !matches. opt_present ( "show-coverage" )
404
401
&& !nightly_options:: is_unstable_enabled ( matches)
405
402
{
406
- early_dcx . early_fatal (
403
+ dcx . fatal (
407
404
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/76578)" ,
408
405
) ;
409
406
}
@@ -420,10 +417,7 @@ impl Options {
420
417
}
421
418
let paths = match theme:: load_css_paths ( content) {
422
419
Ok ( p) => p,
423
- Err ( e) => {
424
- dcx. err ( e) ;
425
- return Err ( 1 ) ;
426
- }
420
+ Err ( e) => dcx. fatal ( e) ,
427
421
} ;
428
422
let mut errors = 0 ;
429
423
@@ -442,21 +436,19 @@ impl Options {
442
436
}
443
437
}
444
438
if errors != 0 {
445
- return Err ( 1 ) ;
439
+ dcx . fatal ( "[check-theme] one or more tests failed" ) ;
446
440
}
447
- return Err ( 0 ) ;
441
+ return None ;
448
442
}
449
443
450
444
let ( lint_opts, describe_lints, lint_cap) = get_cmd_lint_options ( early_dcx, matches) ;
451
445
452
446
let input = PathBuf :: from ( if describe_lints {
453
447
"" // dummy, this won't be used
454
448
} else if matches. free . is_empty ( ) {
455
- dcx. err ( "missing file operand" ) ;
456
- return Err ( 1 ) ;
449
+ dcx. fatal ( "missing file operand" ) ;
457
450
} else if matches. free . len ( ) > 1 {
458
- dcx. err ( "too many file operands" ) ;
459
- return Err ( 1 ) ;
451
+ dcx. fatal ( "too many file operands" ) ;
460
452
} else {
461
453
& matches. free [ 0 ]
462
454
} ) ;
@@ -466,10 +458,7 @@ impl Options {
466
458
let externs = parse_externs ( early_dcx, matches, & unstable_opts) ;
467
459
let extern_html_root_urls = match parse_extern_html_roots ( matches) {
468
460
Ok ( ex) => ex,
469
- Err ( err) => {
470
- dcx. err ( err) ;
471
- return Err ( 1 ) ;
472
- }
461
+ Err ( err) => dcx. fatal ( err) ,
473
462
} ;
474
463
475
464
let default_settings: Vec < Vec < ( String , String ) > > = vec ! [
@@ -526,16 +515,14 @@ impl Options {
526
515
let no_run = matches. opt_present ( "no-run" ) ;
527
516
528
517
if !should_test && no_run {
529
- dcx. err ( "the `--test` flag must be passed to enable `--no-run`" ) ;
530
- return Err ( 1 ) ;
518
+ dcx. fatal ( "the `--test` flag must be passed to enable `--no-run`" ) ;
531
519
}
532
520
533
521
let out_dir = matches. opt_str ( "out-dir" ) . map ( |s| PathBuf :: from ( & s) ) ;
534
522
let output = matches. opt_str ( "output" ) . map ( |s| PathBuf :: from ( & s) ) ;
535
523
let output = match ( out_dir, output) {
536
524
( Some ( _) , Some ( _) ) => {
537
- dcx. err ( "cannot use both 'out-dir' and 'output' at once" ) ;
538
- return Err ( 1 ) ;
525
+ dcx. fatal ( "cannot use both 'out-dir' and 'output' at once" ) ;
539
526
}
540
527
( Some ( out_dir) , None ) => out_dir,
541
528
( None , Some ( output) ) => output,
@@ -549,8 +536,7 @@ impl Options {
549
536
550
537
if let Some ( ref p) = extension_css {
551
538
if !p. is_file ( ) {
552
- dcx. err ( "option --extend-css argument must be a file" ) ;
553
- return Err ( 1 ) ;
539
+ dcx. fatal ( "option --extend-css argument must be a file" ) ;
554
540
}
555
541
}
556
542
@@ -566,31 +552,25 @@ impl Options {
566
552
}
567
553
let paths = match theme:: load_css_paths ( content) {
568
554
Ok ( p) => p,
569
- Err ( e) => {
570
- dcx. err ( e) ;
571
- return Err ( 1 ) ;
572
- }
555
+ Err ( e) => dcx. fatal ( e) ,
573
556
} ;
574
557
575
558
for ( theme_file, theme_s) in
576
559
matches. opt_strs ( "theme" ) . iter ( ) . map ( |s| ( PathBuf :: from ( & s) , s. to_owned ( ) ) )
577
560
{
578
561
if !theme_file. is_file ( ) {
579
- dcx. struct_err ( format ! ( "invalid argument: \" {theme_s}\" " ) )
562
+ dcx. struct_fatal ( format ! ( "invalid argument: \" {theme_s}\" " ) )
580
563
. with_help ( "arguments to --theme must be files" )
581
564
. emit ( ) ;
582
- return Err ( 1 ) ;
583
565
}
584
566
if theme_file. extension ( ) != Some ( OsStr :: new ( "css" ) ) {
585
- dcx. struct_err ( format ! ( "invalid argument: \" {theme_s}\" " ) )
567
+ dcx. struct_fatal ( format ! ( "invalid argument: \" {theme_s}\" " ) )
586
568
. with_help ( "arguments to --theme must have a .css extension" )
587
569
. emit ( ) ;
588
- return Err ( 1 ) ;
589
570
}
590
571
let ( success, ret) = theme:: test_theme_against ( & theme_file, & paths, & dcx) ;
591
572
if !success {
592
- dcx. err ( format ! ( "error loading theme file: \" {theme_s}\" " ) ) ;
593
- return Err ( 1 ) ;
573
+ dcx. fatal ( format ! ( "error loading theme file: \" {theme_s}\" " ) ) ;
594
574
} else if !ret. is_empty ( ) {
595
575
dcx. struct_warn ( format ! (
596
576
"theme file \" {theme_s}\" is missing CSS rules from the default theme" ,
@@ -620,22 +600,18 @@ impl Options {
620
600
edition,
621
601
& None ,
622
602
) else {
623
- return Err ( 3 ) ;
603
+ dcx . fatal ( "`ExternalHtml::load` failed" ) ;
624
604
} ;
625
605
626
606
match matches. opt_str ( "r" ) . as_deref ( ) {
627
607
Some ( "rust" ) | None => { }
628
- Some ( s) => {
629
- dcx. err ( format ! ( "unknown input format: {s}" ) ) ;
630
- return Err ( 1 ) ;
631
- }
608
+ Some ( s) => dcx. fatal ( format ! ( "unknown input format: {s}" ) ) ,
632
609
}
633
610
634
611
let index_page = matches. opt_str ( "index-page" ) . map ( |s| PathBuf :: from ( & s) ) ;
635
612
if let Some ( ref index_page) = index_page {
636
613
if !index_page. is_file ( ) {
637
- dcx. err ( "option `--index-page` argument must be a file" ) ;
638
- return Err ( 1 ) ;
614
+ dcx. fatal ( "option `--index-page` argument must be a file" ) ;
639
615
}
640
616
}
641
617
@@ -646,27 +622,21 @@ impl Options {
646
622
let crate_types = match parse_crate_types_from_list ( matches. opt_strs ( "crate-type" ) ) {
647
623
Ok ( types) => types,
648
624
Err ( e) => {
649
- dcx. err ( format ! ( "unknown crate type: {e}" ) ) ;
650
- return Err ( 1 ) ;
625
+ dcx. fatal ( format ! ( "unknown crate type: {e}" ) ) ;
651
626
}
652
627
} ;
653
628
654
629
let output_format = match matches. opt_str ( "output-format" ) {
655
630
Some ( s) => match OutputFormat :: try_from ( s. as_str ( ) ) {
656
631
Ok ( out_fmt) => {
657
632
if !out_fmt. is_json ( ) && show_coverage {
658
- dcx. struct_err (
633
+ dcx. fatal (
659
634
"html output format isn't supported for the --show-coverage option" ,
660
- )
661
- . emit ( ) ;
662
- return Err ( 1 ) ;
635
+ ) ;
663
636
}
664
637
out_fmt
665
638
}
666
- Err ( e) => {
667
- dcx. err ( e) ;
668
- return Err ( 1 ) ;
669
- }
639
+ Err ( e) => dcx. fatal ( e) ,
670
640
} ,
671
641
None => OutputFormat :: default ( ) ,
672
642
} ;
@@ -709,16 +679,14 @@ impl Options {
709
679
let html_no_source = matches. opt_present ( "html-no-source" ) ;
710
680
711
681
if generate_link_to_definition && ( show_coverage || output_format != OutputFormat :: Html ) {
712
- dcx. struct_err (
682
+ dcx. fatal (
713
683
"--generate-link-to-definition option can only be used with HTML output format" ,
714
- )
715
- . emit ( ) ;
716
- return Err ( 1 ) ;
684
+ ) ;
717
685
}
718
686
719
- let scrape_examples_options = ScrapeExamplesOptions :: new ( matches, & dcx) ? ;
687
+ let scrape_examples_options = ScrapeExamplesOptions :: new ( matches, & dcx) ;
720
688
let with_examples = matches. opt_strs ( "with-examples" ) ;
721
- let call_locations = crate :: scrape_examples:: load_call_locations ( with_examples, & dcx) ? ;
689
+ let call_locations = crate :: scrape_examples:: load_call_locations ( with_examples, & dcx) ;
722
690
723
691
let unstable_features =
724
692
rustc_feature:: UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
@@ -793,7 +761,7 @@ impl Options {
793
761
no_emit_shared : false ,
794
762
html_no_source,
795
763
} ;
796
- Ok ( ( options, render_options) )
764
+ Some ( ( options, render_options) )
797
765
}
798
766
799
767
/// Returns `true` if the file given as `self.input` is a Markdown file.
0 commit comments