Skip to content

Coverage spans should not overlap nested items #126626

Closed
@Zalathar

Description

@Zalathar

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

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

    No branches or pull requests

    Issue actions