Files
rust/tests/coverage/match.coverage
Zalathar f521dd4ed9 Switch over to hybrid HIR-aware coverage spans
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.
2026-09-06 10:24:48 +10:00

43 lines
1.4 KiB
Plaintext

LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2024
LL| |
LL| |// Basic test for `match` expressions with various kinds of arms and guards.
LL| |
LL| 16|fn match_expr(x: Option<u32>, cond: bool) {
LL| 16| match x {
LL| 0| Some(0) => say("zero"),
LL| | Some(1) => {
LL| | // (block with a trailing expression)
LL| 1| say("one")
LL| | }
LL| | Some(2) => {
LL| 2| say("two");
LL| | }
LL| 3| Some(3) if cond => {
LL| 0| say("three-cond");
LL| | }
LL| 3| Some(3) => say("three"),
LL| 9| Some(other) if other == 4 => {
LL| 4| say("four");
LL| | }
LL| 5| Some(other) => say("other"),
LL| 1| None => say("none"),
LL| | }
LL| 16|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | for i in 0..=5 {
LL| | for _ in 0..i {
LL| | match_expr(Some(i), false);
LL| | }
LL| | }
LL| | match_expr(None, true);
LL| |}
LL| |
LL| |#[coverage(off)]
LL| |fn say(msg: &str) {
LL| | println!("{msg}");
LL| |}