Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage spans should not overlap nested items #126626

Closed
Zalathar opened this issue Jun 18, 2024 · 1 comment · Fixed by #127199
Closed

Coverage spans should not overlap nested items #126626

Zalathar opened this issue Jun 18, 2024 · 1 comment · Fixed by #127199
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Zalathar
Copy link
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

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) labels Jun 18, 2024
@RustChainBuilder
Copy link

Can I take this?

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 18, 2024
@bors bors closed this as completed in cfd7cf5 Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants