Repository navigation
Conversation
The LLVM engine seeds traces from the debug info and from the lines it forces as coverable in generic, inline and generic impl functions. When the report had no region for such a line it stayed at zero, and when a line held several regions it took the first one's hits. rustc 1.100 stopped emitting regions for match arm patterns and `let` patterns, so every arm with a block body was reported as uncovered while its body ran, and a line whose closure never ran was reported as uncovered while its call did. Count a line by the most hits of any region on it, as llvm-cov does, and give a line no region covers the entries of the innermost function containing it when the compiler mapped that function. Lines of functions with no region at all stay uncovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xd009642
reviewed
Nov 14, 2026
xd009642
left a comment
Owner
There was a problem hiding this comment.
Another thing is I don't think this fully solves the issue you noticed. For example:
pub fn count_regions() -> u32 {
[1, 2, 3, 4].into_iter().map(|n| n + 1).sum()
}In a test which covers this the base and this PR both show 11 bits. But llvm-cov shows 4 hits. I think the helper just isn't actually called in every relevant place in the state machine and the unit tests are possibly not very useful (in that they call the helper directly).
| let result = report.files.get(file); | ||
| for line in analysis.cover.iter() { | ||
| if !self.traces.contains_location(file, *line as u64) { | ||
| let hits = result |
Owner
There was a problem hiding this comment.
Here an unmapped line ends up getting it's enclosing functions entry count even if it's not covered. Take this code for example:
pub fn uncalled_closure<T>() -> u32 {
let callback = || {
let n
= 42;
n
};
let _ = callback;
5
}Here let n would get marked as 1 hit despite being uncovered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since rustc 1.100 the LLVM engine reports lines as uncovered whose code ran. On a project at 100% under rustc 1.99.1 (cargo-tarpaulin 0.37.6,
--engine llvm), the same tests report 95.94% under 1.100. The lines are the heads of match arms with block bodies, such asShape::Circle(r) => {, whose bodies the tests run, in generic functions and in methods of impls with generics (lifetimes included).Cause
rustc 1.100 no longer emits coverage regions for match arm patterns and
letpatterns. For this crate:llvm-cov exportlists a region at9:23(r) under 1.99.1 and none on line 9 under 1.100. The LLVM engine seeds traces from the debug info and from the lines it forces as coverable in generic, inline and generic impl functions. A traced line with no region stays at zero, so the arm head is reported as missed.llvm-covcounts it as no line at all.Fix
llvm-covdoes, instead of the first one's.tests/data/generic_matchescovers both arms of a generic function and of a method in an impl with a lifetime, and is added tollvm_sanity_test. It mirrors the arms reported as missed on the project in the problem above. Unit tests cover the two helpers.On the project above, the reported coverage goes from 95.94% to 99.09% under rustc 1.100. The lines left are closures that never run, such as
.map_err(|e| e.to_string())on a line of its own. Since 1.100 the only region on such a line is the closure's, so this fix leaves them uncovered.🤖 Generated with Claude Code