Improve check for --output-format combinations and add ui regression test

This commit is contained in:
Guillaume Gomez 2025-01-29 15:05:21 +01:00
parent a5d66e07e1
commit b7951380ca
4 changed files with 39 additions and 32 deletions

View file

@ -447,22 +447,42 @@ impl Options {
}
}
let show_coverage = matches.opt_present("show-coverage");
let output_format_s = matches.opt_str("output-format");
let output_format = match output_format_s {
Some(ref s) => match OutputFormat::try_from(s.as_str()) {
Ok(out_fmt) => out_fmt,
Err(e) => dcx.fatal(e),
},
None => OutputFormat::default(),
};
// check for `--output-format=json`
if let Some(format) = matches.opt_str("output-format").as_deref()
&& format != "html"
&& !matches.opt_present("show-coverage")
&& !nightly_options::is_unstable_enabled(matches)
{
let extra = match format {
"json" => " (see https://github.com/rust-lang/rust/issues/76578)",
"doctest" => " (see https://github.com/rust-lang/rust/issues/134529)",
_ => "",
};
dcx.fatal(
format!(
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation{extra}",
),
);
match (
output_format_s.as_ref().map(|_| output_format),
show_coverage,
nightly_options::is_unstable_enabled(matches),
) {
(None | Some(OutputFormat::Json), true, _) => {}
(_, true, _) => {
dcx.fatal(format!(
"`--output-format={}` is not supported for the `--show-coverage` option",
output_format_s.unwrap_or_default(),
));
}
// If `-Zunstable-options` is used, nothing to check after this point.
(_, false, true) => {}
(None | Some(OutputFormat::Html), false, _) => {}
(Some(OutputFormat::Json), false, false) => {
dcx.fatal(
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/76578)",
);
}
(Some(OutputFormat::Doctest), false, false) => {
dcx.fatal(
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/134529)",
);
}
}
let to_check = matches.opt_strs("check-theme");
@ -714,8 +734,6 @@ impl Options {
})
.collect();
let show_coverage = matches.opt_present("show-coverage");
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
Ok(types) => types,
Err(e) => {
@ -723,20 +741,6 @@ impl Options {
}
};
let output_format = match matches.opt_str("output-format") {
Some(s) => match OutputFormat::try_from(s.as_str()) {
Ok(out_fmt) => {
if !out_fmt.is_json() && show_coverage {
dcx.fatal(
"html output format isn't supported for the --show-coverage option",
);
}
out_fmt
}
Err(e) => dcx.fatal(e),
},
None => OutputFormat::default(),
};
let crate_name = matches.opt_str("crate-name");
let bin_crate = crate_types.contains(&CrateType::Executable);
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);

View file

@ -1,2 +1,2 @@
error: html output format isn't supported for the --show-coverage option
error: `--output-format=html` is not supported for the `--show-coverage` option

View file

@ -0,0 +1 @@
//@ compile-flags:-Z unstable-options --show-coverage --output-format=doctest

View file

@ -0,0 +1,2 @@
error: `--output-format=doctest` is not supported for the `--show-coverage` option