Skip to content

Commit ab734a6

Browse files
committed
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
1 parent c78a294 commit ab734a6

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/librustdoc/core.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ pub(crate) fn create_config(
285285
crate_check_cfg: check_cfgs,
286286
input,
287287
output_file: None,
288-
output_dir: None,
288+
output_dir: if render_options.output_to_stdout {
289+
None
290+
} else {
291+
Some(render_options.output.clone())
292+
},
289293
file_loader: None,
290294
lint_caps,
291295
psess_created: None,

src/librustdoc/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern crate test;
6868
extern crate tikv_jemalloc_sys as _;
6969

7070
use std::env::{self, VarError};
71+
use std::fs;
7172
use std::io::{self, IsTerminal};
7273
use std::path::Path;
7374
use std::process::ExitCode;
@@ -932,6 +933,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
932933
}
933934

934935
if render_opts.dep_info().is_some() {
936+
if let Err(e) = fs::create_dir_all(&render_opts.output) {
937+
sess.dcx()
938+
.fatal(format!("{output}: {e}", output = render_opts.output.display()));
939+
}
935940
rustc_interface::passes::write_dep_info(tcx);
936941
}
937942

tests/run-make/rustdoc-dep-info/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
.emit("dep-info")
2121
.run();
2222

23-
let content = rfs::read_to_string("foo.d");
23+
let content = rfs::read_to_string("doc/foo.d");
2424
assert_contains(&content, "lib.rs:");
2525
assert_contains(&content, "foo.rs:");
2626
assert_contains(&content, "bar.rs:");

tests/run-make/rustdoc-scrape-examples-dep-info/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ fn main() {
1010
&["--emit=dep-info,invocation-specific"],
1111
);
1212

13-
let content = rfs::read_to_string("foobar.d").replace(r"\", "/");
13+
let content = rfs::read_to_string("rustdoc/foobar.d").replace(r"\", "/");
1414
assert_contains(&content, "lib.rs:");
1515
assert_contains(&content, "rustdoc/ex.calls:");
1616

17-
let content = rfs::read_to_string("ex.d").replace(r"\", "/");
17+
let content = rfs::read_to_string("rustdoc/ex.d").replace(r"\", "/");
1818
assert_contains(&content, "examples/ex.rs:");
1919
}

0 commit comments

Comments
 (0)