Skip to content

rustdoc: make --emit and --out-dir mimic rustc#153003

Open
notriddle wants to merge 1 commit intorust-lang:mainfrom
notriddle:emit-outdir
Open

rustdoc: make --emit and --out-dir mimic rustc#153003
notriddle wants to merge 1 commit intorust-lang:mainfrom
notriddle:emit-outdir

Conversation

@notriddle
Copy link
Contributor

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

CC #146220 (comment)

@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2026

r? @camelid

rustbot has assigned @camelid.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 9 candidates
  • Random selection from GuillaumeGomez, camelid, fmease, lolbinarycat

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 23, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@notriddle
Copy link
Contributor Author

r? rustdoc

@rustbot rustbot assigned fmease and unassigned camelid Feb 28, 2026
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thanks! I have some questions about some behavioral differences from rustc but once they're cleared up this PR is good to go.

View changes since this review

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 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.

}

if render_opts.dep_info().is_some() {
if let Err(e) = fs::create_dir_all(&render_opts.output) {
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.

For some unknown reason, rustc doesn't actually try to create the outdir for depinfo files, not sure if that's intentional. E.g., --out-dir=nonexistent --emit=dep-info fails. This might warrant a quick investigation. Unless it's a bug in rustc, we should probably be consistent with rustc and not attempt to create the outdir? I'm split.

I don't know why but write_dep_info specifically contains a check to prevent create_dir_all from being called if DepInfo is the only requested emission type. However that runs after write_out_deps which by that point would've already bailed out with an error if the directory didn't exist...

write_out_deps(tcx, outputs, &output_paths);
let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
&& sess.opts.output_types.len() == 1;
if !only_dep_info {
if let Some(ref dir) = sess.io.output_dir {
if fs::create_dir_all(dir).is_err() {
sess.dcx().emit_fatal(errors::OutDirError);
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove it.

I put it in there because it seemed more consistent with rustdoc's behavior (we implicitly create the directory, but we do it after emitting depinfo while emitting html), but it's easy for build systems to create the directory themselves (cargo does).

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 28, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants