From 7e95a22e1f6c3aae57da66c38c0b1bc0f1207893 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 26 Mar 2026 22:02:11 +0800 Subject: [PATCH] rustdoc rejects html emits with json output --- src/librustdoc/config.rs | 12 ++++++++++++ ...tput-format-json-emit-html.html_non_static.stderr | 2 ++ .../output-format-json-emit-html.html_static.stderr | 2 ++ tests/rustdoc-ui/output-format-json-emit-html.rs | 8 ++++++++ .../show-coverage-json-emit-html-non-static.rs | 5 +++++ .../show-coverage-json-emit-html-non-static.stderr | 2 ++ 6 files changed, 31 insertions(+) create mode 100644 tests/rustdoc-ui/output-format-json-emit-html.html_non_static.stderr create mode 100644 tests/rustdoc-ui/output-format-json-emit-html.html_static.stderr create mode 100644 tests/rustdoc-ui/output-format-json-emit-html.rs create mode 100644 tests/rustdoc-ui/show-coverage-json-emit-html-non-static.rs create mode 100644 tests/rustdoc-ui/show-coverage-json-emit-html-non-static.stderr diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index d721034c2d71..3caff6edd504 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -522,6 +522,18 @@ fn println_condition(condition: Condition) { } } + if output_format == OutputFormat::Json { + if let Some(emit_flag) = emit.iter().find_map(|emit| match emit { + EmitType::HtmlStaticFiles => Some("html-static-files"), + EmitType::HtmlNonStaticFiles => Some("html-non-static-files"), + EmitType::DepInfo(_) => None, + }) { + dcx.fatal(format!( + "the `--emit={emit_flag}` flag is not supported with `--output-format=json`", + )); + } + } + let to_check = matches.opt_strs("check-theme"); if !to_check.is_empty() { let mut content = diff --git a/tests/rustdoc-ui/output-format-json-emit-html.html_non_static.stderr b/tests/rustdoc-ui/output-format-json-emit-html.html_non_static.stderr new file mode 100644 index 000000000000..8d8e8c6d1228 --- /dev/null +++ b/tests/rustdoc-ui/output-format-json-emit-html.html_non_static.stderr @@ -0,0 +1,2 @@ +error: the `--emit=html-non-static-files` flag is not supported with `--output-format=json` + diff --git a/tests/rustdoc-ui/output-format-json-emit-html.html_static.stderr b/tests/rustdoc-ui/output-format-json-emit-html.html_static.stderr new file mode 100644 index 000000000000..bc1ddc1b155d --- /dev/null +++ b/tests/rustdoc-ui/output-format-json-emit-html.html_static.stderr @@ -0,0 +1,2 @@ +error: the `--emit=html-static-files` flag is not supported with `--output-format=json` + diff --git a/tests/rustdoc-ui/output-format-json-emit-html.rs b/tests/rustdoc-ui/output-format-json-emit-html.rs new file mode 100644 index 000000000000..7a99cbd91ba6 --- /dev/null +++ b/tests/rustdoc-ui/output-format-json-emit-html.rs @@ -0,0 +1,8 @@ +//@ revisions: html_static html_non_static +//@ check-fail +//@[html_static] compile-flags: -Z unstable-options --output-format=json --emit=html-static-files +//@[html_non_static] compile-flags: -Z unstable-options --output-format=json --emit=html-non-static-files +//[html_static]~? ERROR the `--emit=html-static-files` flag is not supported with `--output-format=json` +//[html_non_static]~? ERROR the `--emit=html-non-static-files` flag is not supported with `--output-format=json` + +pub struct Foo; diff --git a/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.rs b/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.rs new file mode 100644 index 000000000000..b0f67a3b4195 --- /dev/null +++ b/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.rs @@ -0,0 +1,5 @@ +//@ compile-flags: -Z unstable-options --show-coverage --output-format=json --emit=html-non-static-files +//@ check-fail +//~? ERROR the `--emit=html-non-static-files` flag is not supported with `--output-format=json` + +pub struct Foo; diff --git a/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.stderr b/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.stderr new file mode 100644 index 000000000000..8d8e8c6d1228 --- /dev/null +++ b/tests/rustdoc-ui/show-coverage-json-emit-html-non-static.stderr @@ -0,0 +1,2 @@ +error: the `--emit=html-non-static-files` flag is not supported with `--output-format=json` +