Skip to content

Commit cbe3eba

Browse files
authored
Rollup merge of #82497 - jyn514:json, r=CraftSpider
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. To get the test working I had to remove `-Z unstable-options`, which x.py passed to compiletest unconditionally. It was first added in 8c2ec68 so `-Z miri` would be allowed. -Z miri is no longer passed unconditionally, so hopefully removing it won't break anything. r? ```@aDotInTheVoid``` cc ```@HeroicKatora``` ```@CraftSpider``` Thanks to ```@memoryruins``` for pointing it out on Discord! cc ```@Mark-Simulacrum``` for the change to compiletest.
2 parents ef2ef92 + ffd7094 commit cbe3eba

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
@@ -378,6 +378,17 @@ impl Options {
378378
}
379379
}
380380

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

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

707712
for flag in deprecated_flags.iter() {
708713
if matches.opt_present(flag) {
709-
if *flag == "output-format"
710-
&& (matches.opt_present("show-coverage")
711-
|| nightly_options::match_is_nightly_build(matches))
712-
{
713-
continue;
714-
}
715714
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
716715
err.note(
717716
"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)