diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-08-05 11:25:57 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-08-05 11:25:57 +1000 |
| commit | 5f8a11279d75dc0078edbd8fa9d1fd1184c3f4ec (patch) | |
| tree | 4994a4b0348c45a27a3afa36b5d42e457c4acbda | |
| parent | af4e3e08ea3d9739e5af541b737527584cea1d8f (diff) | |
| download | rust-5f8a11279d75dc0078edbd8fa9d1fd1184c3f4ec.tar.gz rust-5f8a11279d75dc0078edbd8fa9d1fd1184c3f4ec.zip | |
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.
| -rw-r--r-- | src/librustdoc/lib.rs | 6 | ||||
| -rw-r--r-- | 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 04c6dd2f206..6e9d5421c24 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 e8ea7199710..d8d5136fd9b 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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; @@ -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()); |
