-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)Area: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The fact that coverage is based on source ranges of function bodies means that an inner functions ranges are being "shadowed" by the outer function. When rendered, the source ranges appear to be covered (by the outer function) even though they are not.
An example from #92695:
pub fn outer(is_true: bool) {
println!("called and covered");
inner_not_covered(is_true);
#[no_coverage]
fn inner_not_covered(is_true: bool) {
if is_true {
println!("called but not covered");
} else {
println!("absolutely not covered");
}
}
}
Pretty printing the coverage report looks like this:
45| 1| pub fn outer(is_true: bool) {
46| 1| println!("called and covered");
47| 1| inner_not_covered(is_true);
48| 1|
49| 1| #[no_coverage]
50| 1| fn inner_not_covered(is_true: bool) {
51| 1| if is_true {
52| 1| println!("called but not covered");
53| 1| } else {
54| 1| println!("absolutely not covered");
55| 1| }
56| 1| }
57| 1| }
Metadata
Metadata
Assignees
Labels
A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)Area: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.