mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-01 01:26:32 +00:00
Instead of trying to heuristically recover source-code spans from MIR soup, we can now take advantage of the `CoverageKind::Point` statements injected for specific HIR expressions. This is a transitional implementation that lets us remove the old MIR-soup code, but still relies heavily on the existing span-refinement heuristics, and does not take advantage of the full possibilities of HIR-aware coverage instrumentation. In order to avoid annoying never-executed spans in code that contains assertions, a heuristic has been added that ignores any expression within the arguments of a macro-expanded function call that returns `!`. Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in how LLVM sorts the coverage mapping entries.
40 lines
1.1 KiB
Plaintext
40 lines
1.1 KiB
Plaintext
LL| |#![feature(coverage_attribute)]
|
|
LL| |//@ edition: 2021
|
|
LL| |//@ compile-flags: -Zcoverage-options=branch
|
|
LL| |//@ llvm-cov-flags: --show-branches=count
|
|
LL| |
|
|
LL| |macro_rules! no_merge {
|
|
LL| | () => {
|
|
LL| | for _ in 0..1 {}
|
|
LL| | };
|
|
LL| |}
|
|
LL| |
|
|
LL| 3|fn let_else(value: Option<&str>) {
|
|
LL| 3| no_merge!();
|
|
LL| |
|
|
LL| 3| let Some(x) = value else {
|
|
------------------
|
|
| Branch (LL:9): [True: 2, False: 1]
|
|
------------------
|
|
LL| 1| say("none");
|
|
LL| 1| return;
|
|
LL| | };
|
|
LL| |
|
|
LL| 2| say(x);
|
|
LL| 3|}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn say(message: &str) {
|
|
LL| | core::hint::black_box(message);
|
|
LL| |}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn main() {
|
|
LL| | let_else(Some("x"));
|
|
LL| | let_else(Some("x"));
|
|
LL| | let_else(None);
|
|
LL| |}
|
|
LL| |
|
|
LL| |// FIXME(#124118) Actually instrument let-else for branch coverage.
|
|
|