Skip to content

Commit

Permalink
Rollup merge of rust-lang#70448 - TimotheeGerber:rustdoc-create-outpu…
Browse files Browse the repository at this point in the history
…t-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 rust-lang#70431
  • Loading branch information
Dylan-DPC authored Mar 28, 2020
2 parents 1f13089 + 6a744ea commit bbd3634
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fs::File;
use std::fs::{create_dir_all, File};
use std::io::prelude::*;
use std::path::PathBuf;

Expand Down Expand Up @@ -40,6 +40,11 @@ pub fn render(
diag: &rustc_errors::Handler,
edition: Edition,
) -> i32 {
if let Err(e) = create_dir_all(&options.output) {
diag.struct_err(&format!("{}: {}", options.output.display(), e)).emit();
return 4;
}

let mut output = options.output;
output.push(input.file_name().unwrap());
output.set_extension("html");
Expand Down

0 comments on commit bbd3634

Please sign in to comment.