Skip to content

Commit bbd3634

Browse files
authored
Rollup merge of #70448 - TimotheeGerber:rustdoc-create-output-dir, r=GuillaumeGomez
Create output dir in rustdoc markdown render `rustdoc` command on a standalone markdown document fails because the output directory (which default to `doc/`) is not created, even when specified with the `--output` argument. This PR adds the creation of the output directory before the file creation to avoid an unexpected error which is unclear. I am not sure about the returned error code. I did not find a table explaining them. So I simply put the same error code that is returned when `File::create` fails because they are both related to file-system errors. Resolve #70431
2 parents 1f13089 + 6a744ea commit bbd3634

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/librustdoc/markdown.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs::File;
1+
use std::fs::{create_dir_all, File};
22
use std::io::prelude::*;
33
use std::path::PathBuf;
44

@@ -40,6 +40,11 @@ pub fn render(
4040
diag: &rustc_errors::Handler,
4141
edition: Edition,
4242
) -> i32 {
43+
if let Err(e) = create_dir_all(&options.output) {
44+
diag.struct_err(&format!("{}: {}", options.output.display(), e)).emit();
45+
return 4;
46+
}
47+
4348
let mut output = options.output;
4449
output.push(input.file_name().unwrap());
4550
output.set_extension("html");

0 commit comments

Comments
 (0)