Skip to content

Commit b5be644

Browse files
committed
Address comments, migrate more diagnostics
1 parent f1763af commit b5be644

File tree

10 files changed

+278
-92
lines changed

10 files changed

+278
-92
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'a> fmt::Display for Display<'a> {
439439
write!(fmt, "`{}`", feat)?;
440440
}
441441
} else {
442-
write_with_opt_paren(fmt, !sub_cfg.is_all(), Display(sub_cfg, self.1))?;
442+
write_with_opt_paren(fmt, !sub_cfg.is_all(), Display(&sub_cfg, self.1))?;
443443
}
444444
}
445445
Ok(())
@@ -476,7 +476,7 @@ impl<'a> fmt::Display for Display<'a> {
476476
write!(fmt, "`{}`", feat)?;
477477
}
478478
} else {
479-
write_with_opt_paren(fmt, !sub_cfg.is_simple(), Display(sub_cfg, self.1))?;
479+
write_with_opt_paren(fmt, !sub_cfg.is_simple(), Display(&sub_cfg, self.1))?;
480480
}
481481
}
482482
Ok(())

src/librustdoc/config.rs

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ use rustc_span::edition::Edition;
1919
use rustc_target::spec::TargetTriple;
2020

2121
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+
};
2231
use crate::externalfiles::ExternalHtml;
2332
use crate::html;
2433
use crate::html::markdown::IdMap;
@@ -381,7 +390,7 @@ impl Options {
381390
match kind.parse() {
382391
Ok(kind) => emit.push(kind),
383392
Err(()) => {
384-
diag.err(format!("unrecognized emission type: {}", kind));
393+
diag.emit_err(UnrecognizedEmissionType { kind });
385394
return Err(1);
386395
}
387396
}
@@ -406,6 +415,8 @@ impl Options {
406415
) {
407416
Ok(p) => p,
408417
Err(e) => {
418+
#[allow(rustc::untranslatable_diagnostic)]
419+
#[allow(rustc::diagnostic_outside_of_impl)]
409420
diag.struct_err(e).emit();
410421
return Err(1);
411422
}
@@ -437,10 +448,10 @@ impl Options {
437448
let input = PathBuf::from(if describe_lints {
438449
"" // dummy, this won't be used
439450
} else if matches.free.is_empty() {
440-
diag.struct_err("missing file operand").emit();
451+
diag.emit_err(MissingFileOperand);
441452
return Err(1);
442453
} else if matches.free.len() > 1 {
443-
diag.struct_err("too many file operands").emit();
454+
diag.emit_err(TooManyFileOperands);
444455
return Err(1);
445456
} else {
446457
&matches.free[0]
@@ -455,6 +466,8 @@ impl Options {
455466
let extern_html_root_urls = match parse_extern_html_roots(matches) {
456467
Ok(ex) => ex,
457468
Err(err) => {
469+
#[allow(rustc::untranslatable_diagnostic)]
470+
#[allow(rustc::diagnostic_outside_of_impl)]
458471
diag.struct_err(err).emit();
459472
return Err(1);
460473
}
@@ -514,15 +527,15 @@ impl Options {
514527
let no_run = matches.opt_present("no-run");
515528

516529
if !should_test && no_run {
517-
diag.err("the `--test` flag must be passed to enable `--no-run`");
530+
diag.emit_err(TestFlagMustBePassedToEnableNoRun);
518531
return Err(1);
519532
}
520533

521534
let out_dir = matches.opt_str("out-dir").map(|s| PathBuf::from(&s));
522535
let output = matches.opt_str("output").map(|s| PathBuf::from(&s));
523536
let output = match (out_dir, output) {
524537
(Some(_), Some(_)) => {
525-
diag.struct_err("cannot use both 'out-dir' and 'output' at once").emit();
538+
diag.emit_err(CannotUseBothOutDirAndOutputAtOnce);
526539
return Err(1);
527540
}
528541
(Some(out_dir), None) => out_dir,
@@ -537,7 +550,7 @@ impl Options {
537550

538551
if let Some(ref p) = extension_css {
539552
if !p.is_file() {
540-
diag.struct_err("option --extend-css argument must be a file").emit();
553+
diag.emit_err(ExtendCssArgMustBeAFile);
541554
return Err(1);
542555
}
543556
}
@@ -549,6 +562,8 @@ impl Options {
549562
) {
550563
Ok(p) => p,
551564
Err(e) => {
565+
#[allow(rustc::untranslatable_diagnostic)]
566+
#[allow(rustc::diagnostic_outside_of_impl)]
552567
diag.struct_err(e).emit();
553568
return Err(1);
554569
}
@@ -558,32 +573,19 @@ impl Options {
558573
matches.opt_strs("theme").iter().map(|s| (PathBuf::from(&s), s.to_owned()))
559574
{
560575
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 });
564577
return Err(1);
565578
}
566579
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 });
570581
return Err(1);
571582
}
572583
let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
573584
if !success {
574-
diag.struct_err(format!("error loading theme file: \"{}\"", theme_s)).emit();
585+
diag.emit_err(ErrorLoadingThemeFile { theme: theme_s });
575586
return Err(1);
576587
} 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 });
587589
}
588590
themes.push(StylePath { path: theme_file });
589591
}
@@ -610,15 +612,15 @@ impl Options {
610612
match matches.opt_str("r").as_deref() {
611613
Some("rust") | None => {}
612614
Some(s) => {
613-
diag.struct_err(format!("unknown input format: {}", s)).emit();
615+
diag.emit_err(UnknownInputFormat { format: s });
614616
return Err(1);
615617
}
616618
}
617619

618620
let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
619621
if let Some(ref index_page) = index_page {
620622
if !index_page.is_file() {
621-
diag.struct_err("option `--index-page` argument must be a file").emit();
623+
diag.emit_err(IndexPageArgMustBeAFile);
622624
return Err(1);
623625
}
624626
}
@@ -630,7 +632,7 @@ impl Options {
630632
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
631633
Ok(types) => types,
632634
Err(e) => {
633-
diag.struct_err(format!("unknown crate type: {}", e)).emit();
635+
diag.emit_err(UnknownCrateType { err: e });
634636
return Err(1);
635637
}
636638
};
@@ -639,15 +641,14 @@ impl Options {
639641
Some(s) => match OutputFormat::try_from(s.as_str()) {
640642
Ok(out_fmt) => {
641643
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);
646645
return Err(1);
647646
}
648647
out_fmt
649648
}
650649
Err(e) => {
650+
#[allow(rustc::untranslatable_diagnostic)]
651+
#[allow(rustc::diagnostic_outside_of_impl)]
651652
diag.struct_err(e).emit();
652653
return Err(1);
653654
}
@@ -692,10 +693,7 @@ impl Options {
692693
matches.opt_present("extern-html-root-takes-precedence");
693694

694695
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);
699697
return Err(1);
700698
}
701699

@@ -789,32 +787,15 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
789787

790788
for &flag in deprecated_flags.iter() {
791789
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 });
798791
}
799792
}
800793

801794
let removed_flags = ["plugins", "plugin-path", "no-defaults", "passes", "input-format"];
802795

803796
for &flag in removed_flags.iter() {
804797
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));
818799
}
819800
}
820801
}

src/librustdoc/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ pub(crate) fn create_config(
298298
}
299299
}
300300

301+
#[allow(rustc::untranslatable_diagnostic)]
302+
#[allow(rustc::diagnostic_outside_of_impl)]
301303
pub(crate) fn run_global_ctxt(
302304
tcx: TyCtxt<'_>,
303305
show_coverage: bool,

0 commit comments

Comments
 (0)