Skip to content

Coverage spans should not overlap nested items #126626

Closed
@Zalathar

Description

@Zalathar
Contributor

Currently we have special-case code that detects closure expressions within a function, and truncates any coverage spans from the outer function that would overlap with the closure. This is needed to have execution counts from the outer function show up on lines associated with the closure, which would be confusion.

However, we don't have similar handling for other kinds of nested items, such as nested functions, nested data types, and nested macros.

This can result in confusing/silly execution counts for lines associated with the inner items, as seen in this contrived example:

   LL|       |#[coverage(off)]
   LL|       |fn dense_a() {
   LL|       |    dense_b();
   LL|       |    dense_b();
   LL|       |    #[coverage(on)]
   LL|      2|    fn dense_b() {
   LL|      2|        dense_c();
   LL|      2|        dense_c();
   LL|      2|        #[coverage(off)]
   LL|      2|        fn dense_c() {
   LL|      2|            do_stuff();
   LL|      2|        }
   LL|      2|    }
   LL|       |}

Notice that the lines associated with dense_c have an execution count of 2, even though this function is not instrumented for coverage, and the execution count of those lines is not actually 2.

@rustbot label +A-code-coverage

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)
on Jun 18, 2024
dmsoltech

dmsoltech commented on Jun 18, 2024

@dmsoltech

Can I take this?

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jun 18, 2024
added a commit that references this issue on Jul 8, 2024

Auto merge of rust-lang#127199 - Zalathar:hir-holes, r=oli-obk

cfd7cf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Zalathar@dmsoltech@jieyouxu@rustbot

      Issue actions

        Coverage spans should not overlap nested items · Issue #126626 · rust-lang/rust