Skip to content

Commit 2917463

Browse files
Improve check for --output-format combinations and add ui regression test
1 parent a5d66e0 commit 2917463

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

src/librustdoc/config.rs

+42-31
Original file line numberDiff line numberDiff line change
@@ -447,22 +447,49 @@ impl Options {
447447
}
448448
}
449449

450+
let show_coverage = matches.opt_present("show-coverage");
451+
let output_format_s = matches.opt_str("output-format");
452+
let output_format = match output_format_s {
453+
Some(ref s) => match OutputFormat::try_from(s.as_str()) {
454+
Ok(out_fmt) => {
455+
if !out_fmt.is_json() && show_coverage {
456+
dcx.fatal(
457+
"html output format isn't supported for the --show-coverage option",
458+
);
459+
}
460+
out_fmt
461+
}
462+
Err(e) => dcx.fatal(e),
463+
},
464+
None => OutputFormat::default(),
465+
};
466+
450467
// check for `--output-format=json`
451-
if let Some(format) = matches.opt_str("output-format").as_deref()
452-
&& format != "html"
453-
&& !matches.opt_present("show-coverage")
454-
&& !nightly_options::is_unstable_enabled(matches)
455-
{
456-
let extra = match format {
457-
"json" => " (see https://github.com./rust-lang/rust/issues/76578)",
458-
"doctest" => " (see https://github.com./rust-lang/rust/issues/134529)",
459-
_ => "",
460-
};
461-
dcx.fatal(
462-
format!(
463-
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation{extra}",
464-
),
465-
);
468+
match (
469+
output_format_s.as_ref().map(|_| output_format),
470+
show_coverage,
471+
nightly_options::is_unstable_enabled(matches),
472+
) {
473+
(None | Some(OutputFormat::Json), true, _) => {}
474+
(_, true, _) => {
475+
dcx.fatal(format!(
476+
"`--output-format={}` is not supported for the `--show-coverage` option",
477+
output_format_s.unwrap_or_default(),
478+
));
479+
}
480+
// If `-Zunstable-options` is used, nothing to check after this point.
481+
(_, false, true) => {}
482+
(None | Some(OutputFormat::Html), false, _) => {}
483+
(Some(OutputFormat::Json), false, false) => {
484+
dcx.fatal(
485+
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com./rust-lang/rust/issues/76578)",
486+
);
487+
}
488+
(Some(OutputFormat::Doctest), false, false) => {
489+
dcx.fatal(
490+
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com./rust-lang/rust/issues/134529)",
491+
);
492+
}
466493
}
467494

468495
let to_check = matches.opt_strs("check-theme");
@@ -714,29 +741,13 @@ impl Options {
714741
})
715742
.collect();
716743

717-
let show_coverage = matches.opt_present("show-coverage");
718-
719744
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
720745
Ok(types) => types,
721746
Err(e) => {
722747
dcx.fatal(format!("unknown crate type: {e}"));
723748
}
724749
};
725750

726-
let output_format = match matches.opt_str("output-format") {
727-
Some(s) => match OutputFormat::try_from(s.as_str()) {
728-
Ok(out_fmt) => {
729-
if !out_fmt.is_json() && show_coverage {
730-
dcx.fatal(
731-
"html output format isn't supported for the --show-coverage option",
732-
);
733-
}
734-
out_fmt
735-
}
736-
Err(e) => dcx.fatal(e),
737-
},
738-
None => OutputFormat::default(),
739-
};
740751
let crate_name = matches.opt_str("crate-name");
741752
let bin_crate = crate_types.contains(&CrateType::Executable);
742753
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);

tests/rustdoc-ui/doctest-output.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//@ compile-flags:-Z unstable-options --show-coverage --output-format=doctest
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: html output format isn't supported for the --show-coverage option
2+

0 commit comments

Comments
 (0)