rust/src/librustdoc
Dylan DPC 13f47f608e
Rollup merge of #100451 - hovinen:no-panic-on-result-err-in-test, r=Mark-Simulacrum
Do not panic when a test function returns Result::Err.

Rust's test library allows test functions to return a `Result`, so that the test is deemed to have failed if the function returns a `Result::Err` variant. Currently, this works by having `Result` implement the `Termination` trait and asserting in assert_test_result that `Termination::report()` indicates successful completion. This turns a `Result::Err` into a panic, which is caught and unwound in the test library.

This approach is problematic in certain environments where one wishes to save on both binary size and compute resources when running tests by:

 * Compiling all code with `--panic=abort` to avoid having to generate unwinding tables, and
 * Running most tests in-process to avoid the overhead of spawning new processes.

This change removes the intermediate panic step and passes a `Result::Err` directly through to the test runner.

To do this, it modifies `assert_test_result` to return a `Result<(), String>` where the `Err` variant holds what was previously the panic message. It changes the types in the `TestFn` enum to return `Result<(), String>`.

This tries to minimise the changes to benchmark tests, so it calls `unwrap()` on the `Result` returned by `assert_test_result`, effectively keeping the same behaviour as before.

Some questions for reviewers:

 * Does the change to the return types in the enum `TestFn` constitute a breaking change for the library API? Namely, the enum definition is public but the test library indicates that "Currently, not much of this is meant for users" and most of the library API appears to be marked unstable.
 * Is there a way to test this change, i.e., to test that no panic occurs if a test returns `Result::Err`?
 * Is there a shorter, more idiomatic way to fold `Result<Result<T,E>,E>` into a `Result<T,E>` than the `fold_err` function I added?
2022-10-02 20:42:20 +05:30
..
clean Auto merge of #101887 - nnethercote:shrink-Res, r=spastorino 2022-09-29 22:45:24 +00:00
doctest Rename TestOptions to GlobalTestOptions 2021-12-12 17:46:19 -08:00
formats rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
html Rollup merge of #102525 - notriddle:notriddle/array-link, r=GuillaumeGomez,jsha 2022-10-02 03:16:39 +02:00
json rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
passes rustdoc: adopt to the new lint API 2022-10-01 10:03:06 +00:00
theme Correctly handle parens 2022-09-15 13:53:20 +02:00
askama.toml Move back templates into html folder 2022-01-19 11:13:24 +01:00
Cargo.toml Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec. 2022-08-29 15:42:13 +10:00
config.rs Simplify CSS parser to check themes 2022-09-14 19:36:03 +02:00
core.rs rustdoc: adopt to the new lint API 2022-10-01 10:03:06 +00:00
docfs.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
doctest.rs Do not panic when a test function returns Result::Err. 2022-09-16 14:36:00 +00:00
error.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
externalfiles.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
fold.rs rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
lib.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
lint.rs Feature gate the rustdoc::missing_doc_code_examples lint 2022-09-12 21:20:24 +02:00
markdown.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
scrape_examples.rs separate definitions and HIR owners 2022-09-24 23:21:19 +09:00
theme.rs Correctly handle parens 2022-09-15 13:53:20 +02:00
visit.rs rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
visit_ast.rs change AccessLevels representation 2022-09-14 18:11:00 +03:00
visit_lib.rs change AccessLevels representation 2022-09-14 18:11:00 +03:00

For more information about how librustdoc works, see the rustc dev guide.