From 77eea39d459ef5a7dd91584f8560984e3b8dd960 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 14 Mar 2026 18:58:58 -0700 Subject: [PATCH] rustdoc: error out on `--test` with `--emit` These options don't behave reasonably when combined right now, and there are no tests and no docs for how they should. For the short term, make this a fatal error. If we decide to assign this some semantics, then we can do that at any time. --- src/librustdoc/config.rs | 6 +++++- tests/rustdoc-ui/doctest/emit-test.rs | 5 +++++ tests/rustdoc-ui/doctest/emit-test.stderr | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-ui/doctest/emit-test.rs create mode 100644 tests/rustdoc-ui/doctest/emit-test.stderr diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index f1fdce48181c2..d721034c2d71d 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -462,8 +462,13 @@ impl Options { return None; } + let should_test = matches.opt_present("test"); + let mut emit = FxIndexMap::<_, EmitType>::default(); for list in matches.opt_strs("emit") { + if should_test { + dcx.fatal("the `--test` flag and the `--emit` flag are not supported together"); + } for kind in list.split(',') { match kind.parse() { Ok(kind) => { @@ -634,7 +639,6 @@ impl Options { let test_args: Vec = test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect(); - let should_test = matches.opt_present("test"); let no_run = matches.opt_present("no-run"); if !should_test && no_run { diff --git a/tests/rustdoc-ui/doctest/emit-test.rs b/tests/rustdoc-ui/doctest/emit-test.rs new file mode 100644 index 0000000000000..4e40bde4648ba --- /dev/null +++ b/tests/rustdoc-ui/doctest/emit-test.rs @@ -0,0 +1,5 @@ +//@ compile-flags:--test --emit=dep-info -Z unstable-options +//@ check-fail +//~? ERROR the `--test` flag and the `--emit` flag + +//! This example intentionally left blank. diff --git a/tests/rustdoc-ui/doctest/emit-test.stderr b/tests/rustdoc-ui/doctest/emit-test.stderr new file mode 100644 index 0000000000000..2b1ebae5b1399 --- /dev/null +++ b/tests/rustdoc-ui/doctest/emit-test.stderr @@ -0,0 +1,2 @@ +error: the `--test` flag and the `--emit` flag are not supported together +