Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

@fmease fmease Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, rustc & rustdoc (except the json backend) actually interpret the - passed to --out-dir literally. So under "normal execution" both place the artifacts into a file dir called - (I can't say I like that; I think ideally we would reject such a 'weird' path). Consequently, rustc tries to write to -/$FILESTEM.d given --emit=depinfo --out-dir=-.

I fear it would be more consistent to ignore output_to_stdout here (which is currently only used by the json backend). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json backend is usable with --emit=depinfo, though.

The problem is that --out is aliased to --out-dir in rustdoc, and it isn't in rustc. If #149365 was merged, there'd be a more principled way to handle this, but it isn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, #149365 seems like a nice step. Hmm, I guess it's fine for now even if it diverges from rustc. We should be able to fix this even after the stabilization of --emit since passing - to --out-dir is unlikely to happen in practice.

None
} else {
Some(render_options.output.clone())
},
file_loader: None,
lint_caps,
psess_created: None,
Expand Down
4 changes: 3 additions & 1 deletion tests/run-make/rustdoc-dep-info/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:");
Expand Down
6 changes: 4 additions & 2 deletions tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
}
Loading