From 5f8a11279d75dc0078edbd8fa9d1fd1184c3f4ec Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 5 Aug 2020 11:25:57 +1000 Subject: [PATCH] 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. --- src/librustdoc/lib.rs | 6 ++---- src/librustdoc/test.rs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 04c6dd2f20686..6e9d5421c2482 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -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) } } @@ -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, diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e8ea71997109a..d8d5136fd9bef 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -42,7 +42,7 @@ pub struct TestOptions { pub attrs: Vec, } -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; @@ -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());