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

Missed coverage when function is inlined #1192

Open
Noratrieb opened this issue Jan 22, 2023 · 4 comments
Open

Missed coverage when function is inlined #1192

Noratrieb opened this issue Jan 22, 2023 · 4 comments
Assignees
Labels

Comments

@Noratrieb
Copy link

Noratrieb commented Jan 22, 2023

When a function is inlined, it's sometimes marked as not executed.

To Reproduce

fn lol() {}

pub fn uwu() {
    lol();
}

#[test]
fn wow() {
    uwu();
}

compiled using RUSTFLAGS='-Cpasses=inline' cargo tarpaulin

|| Uncovered Lines:
|| src/lib.rs: 3, 6
|| Tested/Total Lines:
|| src/lib.rs: 0/2 +0.00%
||
0.00% coverage, 0/2 lines covered, +0.00% change in coverage

Coverage image showing both functions in red

Expected behavior
I expect both lines in the functions to be covered, since they are tested.

I strongly think that this is a cargo-tarpaulin bug as the generated LLVM IR seems to contain the coverage statements correctly and cargo-llvm-cov also shows the entire file as covered.

@0xForerunner
Copy link

Bump on this as well! Also having this problem. @Nilstrieb did you find a solution?

@Noratrieb
Copy link
Author

no, I was just playing around so I didn't need one

@Sajjon
Copy link

Sajjon commented Nov 20, 2023

I have this problem, preventing me from getting my well deserved 95% code coverage (reported ca 81%) 😬

@Pier4413
Copy link

Pier4413 commented Jun 6, 2024

I just bumped into this problem too

logger::warn!(
                    "Error while processing message due to {}",
                    error.to_string()
                );

The report is somewhat very disturbing because the line

error.to_string()

is reported as covered but not

logger::warn!(

but if I inline the code like this:

logger::warn!("Error while processing message due to {}", error.to_string());

It works wonderfully. I wonder if any of you have a solution to avoid that? Because the first version is what cargo fmt produces, so it will be a little heavy to reformat everything after the default formatter

For information:

$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

$ cargo --version
cargo 1.76.0 (c84b36747 2024-01-18)

$ cargo tarpaulin --version
cargo-tarpaulin-tarpaulin 0.28.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants