about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/Linker.cpp
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-10-02 20:42:20 +0530
committerGitHub <noreply@github.com>2022-10-02 20:42:20 +0530
commit13f47f608e8e9fcdd60f64688e12f5f4c2f7c317 (patch)
treec9500bb016c78a89c38ea9c32cff473cf271575d /compiler/rustc_llvm/llvm-wrapper/Linker.cpp
parent756e7be5eb923ec955dfd8dec2a0d3ac81cfdf55 (diff)
parente19a98cff73cb18e974c145cb6d15c4860092140 (diff)
downloadrust-13f47f608e8e9fcdd60f64688e12f5f4c2f7c317.tar.gz
rust-13f47f608e8e9fcdd60f64688e12f5f4c2f7c317.zip
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?
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/Linker.cpp')
0 files changed, 0 insertions, 0 deletions