Skip to content

Commit 14997d5

Browse files
committed
Auto merge of #55933 - euclio:doc-panic, r=QuietMisdreavus
emit error when doc generation fails Fixes #41813. The diagnostic looks something like this: ``` error: couldn't generate documentation: No space left on device (os error 28) | = note: failed to create or modify "/path/to/crate/target/doc/src/lazycell" ```
2 parents b866f7d + c359f98 commit 14997d5

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ impl Impl {
202202

203203
#[derive(Debug)]
204204
pub struct Error {
205-
file: PathBuf,
206-
error: io::Error,
205+
pub file: PathBuf,
206+
pub error: io::Error,
207207
}
208208

209209
impl error::Error for Error {

src/librustdoc/lib.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,21 @@ fn main_args(args: &[String]) -> isize {
387387
info!("going to format");
388388
let (error_format, treat_err_as_bug, ui_testing) = diag_opts;
389389
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
390-
html::render::run(krate, renderopts, passes.into_iter().collect(), renderinfo, &diag)
391-
.expect("failed to generate documentation");
392-
0
390+
match html::render::run(
391+
krate,
392+
renderopts,
393+
passes.into_iter().collect(),
394+
renderinfo,
395+
&diag,
396+
) {
397+
Ok(_) => rustc_driver::EXIT_SUCCESS,
398+
Err(e) => {
399+
diag.struct_err(&format!("couldn't generate documentation: {}", e.error))
400+
.note(&format!("failed to create or modify \"{}\"", e.file.display()))
401+
.emit();
402+
rustc_driver::EXIT_FAILURE
403+
}
404+
}
393405
})
394406
}
395407

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-include ../tools.mk
2+
3+
# This test verifies that rustdoc doesn't ICE when it encounters an IO error
4+
# while generating files. Ideally this would be a rustdoc-ui test, so we could
5+
# verify the error message as well.
6+
7+
OUTPUT_DIR := "$(TMPDIR)/rustdoc-io-error"
8+
9+
# Ignore Windows: the test uses `chmod`.
10+
ifndef IS_WINDOWS
11+
12+
# This test operates by creating a temporary directory and modifying its
13+
# permissions so that it is not writable. We have to take special care to set
14+
# the permissions back to normal so that it's able to be deleted later.
15+
all:
16+
mkdir -p $(OUTPUT_DIR)
17+
chmod u-w $(OUTPUT_DIR)
18+
-$(shell $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs)
19+
chmod u+w $(OUTPUT_DIR)
20+
exit $($(.SHELLSTATUS) -eq 1)
21+
22+
else
23+
all:
24+
25+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub struct Foo;

0 commit comments

Comments
 (0)