-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
-Zinstrument-coverage producing coverage report which claims line is never run #84180
Comments
Try to check with fresh nightly (there was some merges that touch coverage-related things), toolstate was fixed few days ago. |
Still reproduced at:
|
Ok, I minimized this, which makes me think it's a span issue. Here's the code: pub struct Foo(u32);
impl Foo {
pub fn foo(&self) -> Result<&Foo, ()> {
Ok(self)
}
pub fn bar(&self) -> Result<u32, ()> {
Ok(self.0)
}
}
pub fn bar(f: &Foo) -> Result<u32, ()> {
let x = f
.foo()?
.bar()?;
Ok(x + 3)
}
#[cfg(test)]
mod tests {
use super::{bar, Foo};
#[test]
fn test_it() {
let f = Foo(5);
let result = bar(&f);
assert_eq!(result, Ok(8))
}
} And here's the coverage results (look to line 16 specifically, though line 29 is also weird to me):
And for convenience, the script I used to drive coverage: #!/bin/sh -ex
env RUSTFLAGS="-Zinstrument-coverage" cargo +nightly test
llvm-profdata merge -sparse default.profraw -o default.profdata
llvm-cov show ./target/debug/deps/kangaroo-f715d112c2e2f815 -instr-profile=default.profdata --ignore-filename-regex='/.cargo/registry' --ignore-filename-regex='/.rustup/toolchains/' |
I guess one important note that's not visible in the text version is that the |
Improve coverage spans for chained function calls Fixes: rust-lang#84180 For chained function calls separated by the `?` try operator, the function call following the try operator produced a MIR `Call` span that matched the span of the first call. The `?` try operator started a new span, so the second call got no span. It turns out the MIR `Call` terminator has a `func` `Operand` for the `Constant` representing the function name, and the function name's Span can be used to reset the starting position of the span. r? `@tmandry` cc: `@wesleywiser`
this was written this way to work around rust-lang/rust#84180, which is fixed
this was written this way to work around rust-lang/rust#84180, which is fixed
I'm attempting to use
-Zinstrument-coverage
to measure coverage in a Python extension module (using pyo3). This is mostly working well. Except... there's a line that's getting recorded as not being executed, even though it is.Exact steps for reproducing this can be seen in pyca/cryptography#5970. Specifically it's claimed that this line isn't covered: https://github.com/pyca/cryptography/blob/main/src/rust/src/asn1.rs#L40
That is line 40, a chained method call.
(I realize this is a somewhat involved example (there's Python! and numerous crates!), but I'm also not sure how to minimize it further. If there's any intermediate outputs I can produce, just ask!))
Looking at the raw
llvm-cov show
output, I see the following:This confirms the same thing, that coverage thinks line 40 isn't being run. But we can tell it is, Line 42 is being run, and we can't get to line 42 without going through line 40 :-)
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: