diff options
| author | Yamakaky <yamakaky@yamaworld.fr> | 2017-03-04 10:27:52 -0500 |
|---|---|---|
| committer | Yamakaky <yamakaky@yamaworld.fr> | 2017-05-09 19:51:50 +0200 |
| commit | ca8b75466cef854d30fdf7614c2358b1eb46816e (patch) | |
| tree | f2bfc45697fca40fadaa04346ed404598a7ad773 /src/libtest | |
| parent | f3fc547194d22dc673274ac20e9a7b1e607cb862 (diff) | |
| download | rust-ca8b75466cef854d30fdf7614c2358b1eb46816e.tar.gz rust-ca8b75466cef854d30fdf7614c2358b1eb46816e.zip | |
Don't show the std frames before user code on unwinding.
When `RUST_BACKTRACE=1`, remove all frames after `__rust_maybe_catch_panic`. Tested on `main`, threads, tests and benches. Cleaning of the top of the stacktrace is let to a future PR. Fixes #40201 See #41815
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 35f2fbca69f..0d615db3deb 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1314,12 +1314,16 @@ pub fn convert_benchmarks_to_tests(tests: Vec<TestDescAndFn>) -> Vec<TestDescAnd let testfn = match x.testfn { DynBenchFn(bench) => { DynTestFn(Box::new(move |()| { - bench::run_once(|b| bench.run(b)) + bench::run_once(|b| { + __rust_begin_short_backtrace(|| bench.run(b)) + }) })) } StaticBenchFn(benchfn) => { DynTestFn(Box::new(move |()| { - bench::run_once(|b| benchfn(b)) + bench::run_once(|b| { + __rust_begin_short_backtrace(|| benchfn(b)) + }) })) } f => f, @@ -1425,12 +1429,24 @@ pub fn run_test(opts: &TestOpts, monitor_ch.send((desc, TrMetrics(mm), Vec::new())).unwrap(); return; } - DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f), - StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, - Box::new(move |()| f())), + DynTestFn(f) => { + let cb = move |()| { + __rust_begin_short_backtrace(|| f.call_box(())) + }; + run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb)) + } + StaticTestFn(f) => + run_test_inner(desc, monitor_ch, opts.nocapture, + Box::new(move |()| __rust_begin_short_backtrace(f))), } } +/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. +#[inline(never)] +fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) { + f() +} + fn calc_result(desc: &TestDesc, task_result: Result<(), Box<Any + Send>>) -> TestResult { match (&desc.should_panic, task_result) { (&ShouldPanic::No, Ok(())) | |
