Skip to content

Commit 5f8a112

Browse files
committed
Be smarter about error handling in run().
`run()` returns `Result<(), String>`. But on failure it always returns an empty string, and then `wrap_return()` treats an empty string specially, by not reporting the error. It turns out we already have the `ErrorReported` type for this sort of behaviour. This commit changes `run()` to use it.
1 parent af4e3e0 commit 5f8a112

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/librustdoc/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,7 @@ fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> MainRes
443443
match res {
444444
Ok(()) => Ok(()),
445445
Err(err) => {
446-
if !err.is_empty() {
447-
diag.struct_err(&err).emit();
448-
}
446+
diag.struct_err(&err).emit();
449447
Err(ErrorReported)
450448
}
451449
}
@@ -478,7 +476,7 @@ fn main_options(options: config::Options) -> MainResult {
478476

479477
match (options.should_test, options.markdown_input()) {
480478
(true, true) => return wrap_return(&diag, markdown::test(options)),
481-
(true, false) => return wrap_return(&diag, test::run(options)),
479+
(true, false) => return test::run(options),
482480
(false, true) => {
483481
return wrap_return(
484482
&diag,

src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct TestOptions {
4242
pub attrs: Vec<String>,
4343
}
4444

45-
pub fn run(options: Options) -> Result<(), String> {
45+
pub fn run(options: Options) -> Result<(), ErrorReported> {
4646
let input = config::Input::File(options.input.clone());
4747

4848
let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
@@ -150,7 +150,7 @@ pub fn run(options: Options) -> Result<(), String> {
150150
});
151151
let tests = match tests {
152152
Ok(tests) => tests,
153-
Err(ErrorReported) => return Err(String::new()),
153+
Err(ErrorReported) => return Err(ErrorReported),
154154
};
155155

156156
test_args.insert(0, "rustdoctest".to_string());

0 commit comments

Comments
 (0)