From 22a0e06097b5b344949a572fac587bbe0b55af06 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 22 Feb 2026 21:52:29 -0700 Subject: [PATCH] rustdoc: make `--emit` and `--out-dir` mimic rustc The behavior in the test case matches rustc's: test-dingus % ls main.rs test-dingus % mkdir foobar test-dingus % rustc --emit=dep-info main.rs --out-dir=foobar test-dingus % ls foobar main.rs test-dingus % ls foobar main.d test-dingus % rustc --emit=dep-info=testfile.d main.rs --out-dir=foobar test-dingus % ls foobar main.rs testfile.d test-dingus % ls foobar main.d --- src/librustdoc/core.rs | 6 +++++- tests/run-make/rustdoc-dep-info/rmake.rs | 4 +++- tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 375f8338319b6..79dd50c4682de 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -285,7 +285,11 @@ pub(crate) fn create_config( crate_check_cfg: check_cfgs, input, output_file: None, - output_dir: None, + output_dir: if render_options.output_to_stdout { + None + } else { + Some(render_options.output.clone()) + }, file_loader: None, lint_caps, psess_created: None, diff --git a/tests/run-make/rustdoc-dep-info/rmake.rs b/tests/run-make/rustdoc-dep-info/rmake.rs index 5d6176b18e886..11901c97fd6a0 100644 --- a/tests/run-make/rustdoc-dep-info/rmake.rs +++ b/tests/run-make/rustdoc-dep-info/rmake.rs @@ -7,6 +7,8 @@ use run_make_support::assertion_helpers::assert_contains; use run_make_support::{path, rfs, rustdoc}; fn main() { + rfs::create_dir("doc"); + // We're only emitting dep info, so we shouldn't be running static analysis to // figure out that this program is erroneous. // Ensure that all kinds of input reading flags end up in dep-info. @@ -20,7 +22,7 @@ fn main() { .emit("dep-info") .run(); - let content = rfs::read_to_string("foo.d"); + let content = rfs::read_to_string("doc/foo.d"); assert_contains(&content, "lib.rs:"); assert_contains(&content, "foo.rs:"); assert_contains(&content, "bar.rs:"); diff --git a/tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs b/tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs index 00a87477ab5e4..5a612fd130052 100644 --- a/tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs +++ b/tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs @@ -5,15 +5,17 @@ use run_make_support::{assert_contains, rfs}; mod scrape; fn main() { + rfs::create_dir("rustdoc"); + scrape::scrape( &["--scrape-tests", "--emit=dep-info"], &["--emit=dep-info,invocation-specific"], ); - let content = rfs::read_to_string("foobar.d").replace(r"\", "/"); + let content = rfs::read_to_string("rustdoc/foobar.d").replace(r"\", "/"); assert_contains(&content, "lib.rs:"); assert_contains(&content, "rustdoc/ex.calls:"); - let content = rfs::read_to_string("ex.d").replace(r"\", "/"); + let content = rfs::read_to_string("rustdoc/ex.d").replace(r"\", "/"); assert_contains(&content, "examples/ex.rs:"); }