Open Fran314 opened 2 years ago
I have encountered the same issue, as well as similar ones, for which I was able to extract minimal working examples. I have the feeling that Tarpaulin just get very confused with generics.
struct S1 { v: Option<i32>, }
fn f1<T>() {
let s = S1 { v: Some(0) };
Box::new(S1 {
v: s
.v
.map(|v| 42),
});
}
#[test]
fn test1() { f1::<()>(); }
struct S2 { u: i32, }
fn f2<T>() {
Box::new(S2 {
u: 0,
});
}
#[test]
fn test2() { f2::<()>(); }
fn f3<T>() {
Some(0)
.map(
|
v
|
42
);
}
#[test]
fn test3() { f3::<()>(); }
Note that Box
is needed, probably to avoid optimization that will remove all code. I get:
Note we can just use 'a
instead of T
:
struct S1 { v: Option<i32>, }
fn f1<'a>() {
let s = S1 { v: Some(0) };
Box::new(S1 {
v: s
.v
.map(|v| 42),
});
}
#[test]
fn test1() { f1(); }
struct S2 { u: i32, }
fn f2<'a>() {
Box::new(S2 {
u: 0,
});
}
#[test]
fn test2() { f2(); }
fn f3<'a>() {
Some(0)
.map(
|
v
|
42
);
}
#[test]
fn test3() { f3(); }
gets me
Here is another MWE with --engine llvm
(the 0;
is also marked as not covered without --engine llvm
):
fn f<'a>() {
let a = if true { 0 } else { 0 };
0;
}
#[test]
fn test() {
f();
}
I'm seeing this in my project zirco-lang/zrc as well:
The image doesn't show it well, but the two matchers are not covered
Describe the bug Tarpaulin doesn't recognise some lines as covered even though they are. In particular, in the example tarpaulin says that line
10
and16
(just those lines, not the whole blocks) are not covered.This does not happen if the match branches are oneline (that is, if instead of
I use
Ok(()) => Ok(())
the line is marked as covered)This does not happen also if the function that wraps the match does not use a generic type: the two functions in the example
do_nothing_generic
anddo_nothing_str
are practically the same, the only exception being that one takes a type that implementsto_string()
while the other takes a&str
, but the bug happens only in the function that takes a generic type.To Reproduce [./Cargo.toml]
[./src/lib.rs]
On calling
cargo tarpaulin
the output is the followingI'm reproducing this on Linux Mint 20.3, and this is the output of
uname -a
The version of rustc used is
rustc 1.61.0 (fe5b13d68 2022-05-18)
Expected behavior The lines
10
,16
should be counted as covered, so the Total Lines forsrc/lib.rs
should be19/19
, and the coverage should be100%
instead of89.47%