Link-dead-code not working?

I created simple test to try cargo coverage:

pub fn f(i: i32) -> i32 { i + 1 }

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

As you see f do was not referenced and so was not called. But cargo coverage reports 100% coverage.

I found this topic and related merged PR, also I grep cargo coverage and it’s code contains std::env::set_var("RUSTFLAGS", "-C link-dead-code");, so is -C link-dead-code becomes broken?

I think the dead code linking is working just fine. If you place the function body on a separate line, you should see it as a miss in the report:

pub fn f(i: i32) -> i32 { 
    i + 1
}

I don’t know why the item definition is considered a hit.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.