Files
rust/tests/coverage/if-let-chain.two.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

40 lines
1.2 KiB
Plaintext

LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2024
LL| |//@ revisions: none one two
LL| |//@[one] ignore-coverage-map
LL| |//@[two] ignore-coverage-map
LL| |
LL| |// Basic test for if-let chains.
LL| |
LL| 1|fn if_let_chain(opt_opt_msg: Option<Option<&str>>) {
LL| 1| if let Some(opt_msg) = opt_opt_msg
LL| 1| && let Some(msg) = opt_msg
LL| | {
LL| 1| say(msg);
LL| 0| }
LL| |
LL| 1| if let Some(opt_msg) = opt_opt_msg
LL| 1| && let Some(msg) = opt_msg
LL| | {
LL| 1| say(msg)
LL| 0| }
LL| |
LL| 1| say("goodbye");
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | let opt_opt_msg = cfg_select!(
LL| | none => None,
LL| | one => Some(None),
LL| | two => Some(Some("hello")),
LL| | );
LL| | if_let_chain(opt_opt_msg);
LL| |}
LL| |
LL| |#[coverage(off)]
LL| |fn say(msg: &str) {
LL| | println!("{msg}");
LL| |}