@@ -19,6 +19,15 @@ use rustc_span::edition::Edition;
19
19
use rustc_target:: spec:: TargetTriple ;
20
20
21
21
use crate :: core:: new_handler;
22
+ use crate :: errors:: {
23
+ ArgumentsToThemeMustBeFiles , ArgumentsToThemeMustHaveACssExtension ,
24
+ CannotUseBothOutDirAndOutputAtOnce , ErrorLoadingThemeFile , ExtendCssArgMustBeAFile ,
25
+ FlagIsDeprecated , FlagNoLongerFunctions ,
26
+ GenerateLinkToDefinitionOptionCanOnlyBeUsedWithHtmlOutputFormat ,
27
+ HtmlOutputFormatUnsupportedForShowCoverageOption , IndexPageArgMustBeAFile , MissingFileOperand ,
28
+ TestFlagMustBePassedToEnableNoRun , ThemeFileMissingCssRulesFromDefaultTheme ,
29
+ TooManyFileOperands , UnknownCrateType , UnknownInputFormat , UnrecognizedEmissionType ,
30
+ } ;
22
31
use crate :: externalfiles:: ExternalHtml ;
23
32
use crate :: html;
24
33
use crate :: html:: markdown:: IdMap ;
@@ -381,7 +390,7 @@ impl Options {
381
390
match kind. parse ( ) {
382
391
Ok ( kind) => emit. push ( kind) ,
383
392
Err ( ( ) ) => {
384
- diag. err ( format ! ( "unrecognized emission type: {}" , kind) ) ;
393
+ diag. emit_err ( UnrecognizedEmissionType { kind } ) ;
385
394
return Err ( 1 ) ;
386
395
}
387
396
}
@@ -406,6 +415,8 @@ impl Options {
406
415
) {
407
416
Ok ( p) => p,
408
417
Err ( e) => {
418
+ #[ allow( rustc:: untranslatable_diagnostic) ]
419
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
409
420
diag. struct_err ( e) . emit ( ) ;
410
421
return Err ( 1 ) ;
411
422
}
@@ -437,10 +448,10 @@ impl Options {
437
448
let input = PathBuf :: from ( if describe_lints {
438
449
"" // dummy, this won't be used
439
450
} else if matches. free . is_empty ( ) {
440
- diag. struct_err ( "missing file operand" ) . emit ( ) ;
451
+ diag. emit_err ( MissingFileOperand ) ;
441
452
return Err ( 1 ) ;
442
453
} else if matches. free . len ( ) > 1 {
443
- diag. struct_err ( "too many file operands" ) . emit ( ) ;
454
+ diag. emit_err ( TooManyFileOperands ) ;
444
455
return Err ( 1 ) ;
445
456
} else {
446
457
& matches. free [ 0 ]
@@ -455,6 +466,8 @@ impl Options {
455
466
let extern_html_root_urls = match parse_extern_html_roots ( matches) {
456
467
Ok ( ex) => ex,
457
468
Err ( err) => {
469
+ #[ allow( rustc:: untranslatable_diagnostic) ]
470
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
458
471
diag. struct_err ( err) . emit ( ) ;
459
472
return Err ( 1 ) ;
460
473
}
@@ -514,15 +527,15 @@ impl Options {
514
527
let no_run = matches. opt_present ( "no-run" ) ;
515
528
516
529
if !should_test && no_run {
517
- diag. err ( "the `--test` flag must be passed to enable `--no-run`" ) ;
530
+ diag. emit_err ( TestFlagMustBePassedToEnableNoRun ) ;
518
531
return Err ( 1 ) ;
519
532
}
520
533
521
534
let out_dir = matches. opt_str ( "out-dir" ) . map ( |s| PathBuf :: from ( & s) ) ;
522
535
let output = matches. opt_str ( "output" ) . map ( |s| PathBuf :: from ( & s) ) ;
523
536
let output = match ( out_dir, output) {
524
537
( Some ( _) , Some ( _) ) => {
525
- diag. struct_err ( "cannot use both 'out-dir' and 'output' at once" ) . emit ( ) ;
538
+ diag. emit_err ( CannotUseBothOutDirAndOutputAtOnce ) ;
526
539
return Err ( 1 ) ;
527
540
}
528
541
( Some ( out_dir) , None ) => out_dir,
@@ -537,7 +550,7 @@ impl Options {
537
550
538
551
if let Some ( ref p) = extension_css {
539
552
if !p. is_file ( ) {
540
- diag. struct_err ( "option --extend-css argument must be a file" ) . emit ( ) ;
553
+ diag. emit_err ( ExtendCssArgMustBeAFile ) ;
541
554
return Err ( 1 ) ;
542
555
}
543
556
}
@@ -549,6 +562,8 @@ impl Options {
549
562
) {
550
563
Ok ( p) => p,
551
564
Err ( e) => {
565
+ #[ allow( rustc:: untranslatable_diagnostic) ]
566
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
552
567
diag. struct_err ( e) . emit ( ) ;
553
568
return Err ( 1 ) ;
554
569
}
@@ -558,32 +573,19 @@ impl Options {
558
573
matches. opt_strs ( "theme" ) . iter ( ) . map ( |s| ( PathBuf :: from ( & s) , s. to_owned ( ) ) )
559
574
{
560
575
if !theme_file. is_file ( ) {
561
- diag. struct_err ( format ! ( "invalid argument: \" {}\" " , theme_s) )
562
- . help ( "arguments to --theme must be files" )
563
- . emit ( ) ;
576
+ diag. emit_err ( ArgumentsToThemeMustBeFiles { theme : theme_s } ) ;
564
577
return Err ( 1 ) ;
565
578
}
566
579
if theme_file. extension ( ) != Some ( OsStr :: new ( "css" ) ) {
567
- diag. struct_err ( format ! ( "invalid argument: \" {}\" " , theme_s) )
568
- . help ( "arguments to --theme must have a .css extension" )
569
- . emit ( ) ;
580
+ diag. emit_err ( ArgumentsToThemeMustHaveACssExtension { theme : theme_s } ) ;
570
581
return Err ( 1 ) ;
571
582
}
572
583
let ( success, ret) = theme:: test_theme_against ( & theme_file, & paths, & diag) ;
573
584
if !success {
574
- diag. struct_err ( format ! ( "error loading theme file: \" {} \" " , theme_s) ) . emit ( ) ;
585
+ diag. emit_err ( ErrorLoadingThemeFile { theme : theme_s } ) ;
575
586
return Err ( 1 ) ;
576
587
} else if !ret. is_empty ( ) {
577
- diag. struct_warn ( format ! (
578
- "theme file \" {}\" is missing CSS rules from the default theme" ,
579
- theme_s
580
- ) )
581
- . warn ( "the theme may appear incorrect when loaded" )
582
- . help ( format ! (
583
- "to see what rules are missing, call `rustdoc --check-theme \" {}\" `" ,
584
- theme_s
585
- ) )
586
- . emit ( ) ;
588
+ diag. emit_warning ( ThemeFileMissingCssRulesFromDefaultTheme { theme : theme_s } ) ;
587
589
}
588
590
themes. push ( StylePath { path : theme_file } ) ;
589
591
}
@@ -610,15 +612,15 @@ impl Options {
610
612
match matches. opt_str ( "r" ) . as_deref ( ) {
611
613
Some ( "rust" ) | None => { }
612
614
Some ( s) => {
613
- diag. struct_err ( format ! ( "unknown input format: {}" , s ) ) . emit ( ) ;
615
+ diag. emit_err ( UnknownInputFormat { format : s } ) ;
614
616
return Err ( 1 ) ;
615
617
}
616
618
}
617
619
618
620
let index_page = matches. opt_str ( "index-page" ) . map ( |s| PathBuf :: from ( & s) ) ;
619
621
if let Some ( ref index_page) = index_page {
620
622
if !index_page. is_file ( ) {
621
- diag. struct_err ( "option `--index-page` argument must be a file" ) . emit ( ) ;
623
+ diag. emit_err ( IndexPageArgMustBeAFile ) ;
622
624
return Err ( 1 ) ;
623
625
}
624
626
}
@@ -630,7 +632,7 @@ impl Options {
630
632
let crate_types = match parse_crate_types_from_list ( matches. opt_strs ( "crate-type" ) ) {
631
633
Ok ( types) => types,
632
634
Err ( e) => {
633
- diag. struct_err ( format ! ( "unknown crate type: {}" , e ) ) . emit ( ) ;
635
+ diag. emit_err ( UnknownCrateType { err : e } ) ;
634
636
return Err ( 1 ) ;
635
637
}
636
638
} ;
@@ -639,15 +641,14 @@ impl Options {
639
641
Some ( s) => match OutputFormat :: try_from ( s. as_str ( ) ) {
640
642
Ok ( out_fmt) => {
641
643
if !out_fmt. is_json ( ) && show_coverage {
642
- diag. struct_err (
643
- "html output format isn't supported for the --show-coverage option" ,
644
- )
645
- . emit ( ) ;
644
+ diag. emit_err ( HtmlOutputFormatUnsupportedForShowCoverageOption ) ;
646
645
return Err ( 1 ) ;
647
646
}
648
647
out_fmt
649
648
}
650
649
Err ( e) => {
650
+ #[ allow( rustc:: untranslatable_diagnostic) ]
651
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
651
652
diag. struct_err ( e) . emit ( ) ;
652
653
return Err ( 1 ) ;
653
654
}
@@ -692,10 +693,7 @@ impl Options {
692
693
matches. opt_present ( "extern-html-root-takes-precedence" ) ;
693
694
694
695
if generate_link_to_definition && ( show_coverage || output_format != OutputFormat :: Html ) {
695
- diag. struct_err (
696
- "--generate-link-to-definition option can only be used with HTML output format" ,
697
- )
698
- . emit ( ) ;
696
+ diag. emit_err ( GenerateLinkToDefinitionOptionCanOnlyBeUsedWithHtmlOutputFormat ) ;
699
697
return Err ( 1 ) ;
700
698
}
701
699
@@ -789,32 +787,15 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
789
787
790
788
for & flag in deprecated_flags. iter ( ) {
791
789
if matches. opt_present ( flag) {
792
- diag. struct_warn ( format ! ( "the `{}` flag is deprecated" , flag) )
793
- . note (
794
- "see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
795
- for more information",
796
- )
797
- . emit ( ) ;
790
+ diag. emit_warning ( FlagIsDeprecated { flag } ) ;
798
791
}
799
792
}
800
793
801
794
let removed_flags = [ "plugins" , "plugin-path" , "no-defaults" , "passes" , "input-format" ] ;
802
795
803
796
for & flag in removed_flags. iter ( ) {
804
797
if matches. opt_present ( flag) {
805
- let mut err = diag. struct_warn ( format ! ( "the `{}` flag no longer functions" , flag) ) ;
806
- err. note (
807
- "see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
808
- for more information",
809
- ) ;
810
-
811
- if flag == "no-defaults" || flag == "passes" {
812
- err. help ( "you may want to use --document-private-items" ) ;
813
- } else if flag == "plugins" || flag == "plugin-path" {
814
- err. warn ( "see CVE-2018-1000622" ) ;
815
- }
816
-
817
- err. emit ( ) ;
798
+ diag. emit_warning ( FlagNoLongerFunctions :: new ( flag) ) ;
818
799
}
819
800
}
820
801
}
0 commit comments