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

Nested functions with #[no_coverage] lead to non-obvious results. #93319

Open
Swatinem opened this issue Jan 26, 2022 · 0 comments
Open

Nested functions with #[no_coverage] lead to non-obvious results. #93319

Swatinem opened this issue Jan 26, 2022 · 0 comments
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

@Swatinem
Copy link
Contributor

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|    }
@Swatinem Swatinem added the C-bug Category: This is a bug. label Jan 26, 2022
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) and removed needs-triage-legacy labels Jan 25, 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

No branches or pull requests

3 participants