Description
So found an interesting thing when developing cargo-tarpaulin and confirmed it exists also with cargo-llvm-cov and using the raw llvm tools. When #[tracing::instrument]
is added to a function the function body is not included in the coverage instrumentation. This doesn't happen with #[tokio::main]
and I'm yet to create a more minimal reproduction with a less intense proc macro.
Project setup:
cargo new --lib tracing-instrument
cargo add tracing
In src/lib.rs
use tracing::instrument;
#[instrument]
fn instrumented_function() {
println!("Hello");
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_it_hit() {
instrumented_function();
}
}
If you run something like cargo llvm-cov --html
on this project you'll see only #[instrument]
is marked as covered. If we comment out #[instrument]
then the function signature, body and closing brace are marked as covered regions of codes.
This suggests to me there's something a bit wrong with the llvm instrumentation setup and how it interacts with procedural macros.