Skip to content

Commit ffd7094

Browse files
committed
Fix handling of --output-format json flag
- Don't treat it as deprecated on stable and beta channels. Before, it would give confusing and incorrect output: ``` warning: the 'output-format' flag is considered deprecated | = warning: see issue #44136 <#44136> for more information error: json output format isn't supported for doc generation ``` Both of those are wrong: output-format isn't deprecated, and json output is supported. - Require -Z unstable-options for `--output-format json` Previously, it was allowed by default on nightly, which made it hard to realize the flag wouldn't be accepted on beta or stable. Note that this still allows `--output-format html`, which has been stable since 1.0. - Remove unnecessary double-checking of the feature gate when parsing the output format - Add custom run-make test since compiletest passes -Zunstable-options by default
1 parent 16143d1 commit ffd7094

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

src/librustdoc/config.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ impl Options {
379379
}
380380
}
381381

382+
// check for `--output-format=json`
383+
if !matches!(matches.opt_str("output-format").as_deref(), None | Some("html"))
384+
&& !matches.opt_present("show-coverage")
385+
&& !nightly_options::is_unstable_enabled(matches)
386+
{
387+
rustc_session::early_error(
388+
error_format,
389+
"the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/76578)",
390+
);
391+
}
392+
382393
let to_check = matches.opt_strs("check-theme");
383394
if !to_check.is_empty() {
384395
let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
@@ -575,13 +586,7 @@ impl Options {
575586
let output_format = match matches.opt_str("output-format") {
576587
Some(s) => match OutputFormat::try_from(s.as_str()) {
577588
Ok(out_fmt) => {
578-
if out_fmt.is_json()
579-
&& !(show_coverage || nightly_options::match_is_nightly_build(matches))
580-
{
581-
diag.struct_err("json output format isn't supported for doc generation")
582-
.emit();
583-
return Err(1);
584-
} else if !out_fmt.is_json() && show_coverage {
589+
if !out_fmt.is_json() && show_coverage {
585590
diag.struct_err(
586591
"html output format isn't supported for the --show-coverage option",
587592
)
@@ -703,16 +708,10 @@ impl Options {
703708

704709
/// Prints deprecation warnings for deprecated options
705710
fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Handler) {
706-
let deprecated_flags = ["input-format", "output-format", "no-defaults", "passes"];
711+
let deprecated_flags = ["input-format", "no-defaults", "passes"];
707712

708713
for flag in deprecated_flags.iter() {
709714
if matches.opt_present(flag) {
710-
if *flag == "output-format"
711-
&& (matches.opt_present("show-coverage")
712-
|| nightly_options::match_is_nightly_build(matches))
713-
{
714-
continue;
715-
}
716715
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
717716
err.note(
718717
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTDOC) --output-format=json x.html 2>&1 | diff - output-format-json.stderr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a collection of tests that verify `--unstable-options` is required.
2+
It should eventually be removed in favor of UI tests once compiletest stops
3+
passing --unstable-options by default (#82639).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: the -Z unstable-options flag must be passed to enable --output-format for documentation generation (see https://github.com/rust-lang/rust/issues/76578)
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing to see here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// compile-flags: --output-format html
2+
// check-pass
3+
// This tests that `--output-format html` is accepted without `-Z unstable-options`,
4+
// since it has been stable since 1.0.

src/tools/compiletest/src/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'test> TestCx<'test> {
16001600
.args(&self.props.compile_flags);
16011601

16021602
if self.config.mode == RustdocJson {
1603-
rustdoc.arg("--output-format").arg("json");
1603+
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
16041604
}
16051605

16061606
if let Some(ref linker) = self.config.linker {

0 commit comments

Comments
 (0)