Skip to content

Commit

Permalink
Be smarter about error handling in run().
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
nnethercote committed Aug 5, 2020
1 parent af4e3e0 commit 5f8a112
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> MainRes
match res {
Ok(()) => Ok(()),
Err(err) => {
if !err.is_empty() {
diag.struct_err(&err).emit();
}
diag.struct_err(&err).emit();
Err(ErrorReported)
}
}
Expand Down Expand Up @@ -478,7 +476,7 @@ fn main_options(options: config::Options) -> MainResult {

match (options.should_test, options.markdown_input()) {
(true, true) => return wrap_return(&diag, markdown::test(options)),
(true, false) => return wrap_return(&diag, test::run(options)),
(true, false) => return test::run(options),
(false, true) => {
return wrap_return(
&diag,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct TestOptions {
pub attrs: Vec<String>,
}

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

let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name;
Expand Down Expand Up @@ -150,7 +150,7 @@ pub fn run(options: Options) -> Result<(), String> {
});
let tests = match tests {
Ok(tests) => tests,
Err(ErrorReported) => return Err(String::new()),
Err(ErrorReported) => return Err(ErrorReported),
};

test_args.insert(0, "rustdoctest".to_string());
Expand Down

0 comments on commit 5f8a112

Please sign in to comment.