Improve check for --output-format
combinations and add ui regression test
This commit is contained in:
parent
a5d66e07e1
commit
b7951380ca
4 changed files with 39 additions and 32 deletions
|
@ -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`
|
// check for `--output-format=json`
|
||||||
if let Some(format) = matches.opt_str("output-format").as_deref()
|
match (
|
||||||
&& format != "html"
|
output_format_s.as_ref().map(|_| output_format),
|
||||||
&& !matches.opt_present("show-coverage")
|
show_coverage,
|
||||||
&& !nightly_options::is_unstable_enabled(matches)
|
nightly_options::is_unstable_enabled(matches),
|
||||||
{
|
) {
|
||||||
let extra = match format {
|
(None | Some(OutputFormat::Json), true, _) => {}
|
||||||
"json" => " (see https://github.com/rust-lang/rust/issues/76578)",
|
(_, true, _) => {
|
||||||
"doctest" => " (see https://github.com/rust-lang/rust/issues/134529)",
|
dcx.fatal(format!(
|
||||||
_ => "",
|
"`--output-format={}` is not supported for the `--show-coverage` option",
|
||||||
};
|
output_format_s.unwrap_or_default(),
|
||||||
dcx.fatal(
|
));
|
||||||
format!(
|
}
|
||||||
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation{extra}",
|
// 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");
|
let to_check = matches.opt_strs("check-theme");
|
||||||
|
@ -714,8 +734,6 @@ impl Options {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let show_coverage = matches.opt_present("show-coverage");
|
|
||||||
|
|
||||||
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
|
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
|
||||||
Ok(types) => types,
|
Ok(types) => types,
|
||||||
Err(e) => {
|
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 crate_name = matches.opt_str("crate-name");
|
||||||
let bin_crate = crate_types.contains(&CrateType::Executable);
|
let bin_crate = crate_types.contains(&CrateType::Executable);
|
||||||
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
|
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
1
tests/rustdoc-ui/doctest-output.rs
Normal file
1
tests/rustdoc-ui/doctest-output.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//@ compile-flags:-Z unstable-options --show-coverage --output-format=doctest
|
2
tests/rustdoc-ui/doctest-output.stderr
Normal file
2
tests/rustdoc-ui/doctest-output.stderr
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
error: `--output-format=doctest` is not supported for the `--show-coverage` option
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue