diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-03-28 15:21:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-28 15:21:58 +0100 |
| commit | bbd3634f5f22e3e58cc570c37626625ef4109c14 (patch) | |
| tree | db0fff6aff357a6d48c93d640735cb56576c8b50 | |
| parent | 1f13089bef91e8410bca87b2f42e6fbbc2bbfd9e (diff) | |
| parent | 6a744ea4d515a70c5c90fef85cfa4c7ba8ae7f53 (diff) | |
| download | rust-bbd3634f5f22e3e58cc570c37626625ef4109c14.tar.gz rust-bbd3634f5f22e3e58cc570c37626625ef4109c14.zip | |
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
| -rw-r--r-- | src/librustdoc/markdown.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index a41fdd2ff17..0a1b5f58815 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::fs::{create_dir_all, File}; use std::io::prelude::*; use std::path::PathBuf; @@ -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"); |
