Description
Consider this source file from the coverage test suite:
rust/tests/coverage/test_harness.rs
Lines 9 to 10 in 6bf600b
When we instrument this file for coverage, we generate coverage mappings for my_test
as expected. However, we also generate coverage mappings for a mysterious closure inside my_test
:
rust/tests/coverage/test_harness.cov-map
Lines 9 to 15 in 6bf600b
This closure turns out to have been added by the builtin macro that expands #[test]
attributes.
Adding coverage instrumentation to this closure is not useful, and we should not be doing it.
Right now this only causes minor problems in the final coverage reports, because coverage for the closure shows up on its own line with the span of the attribute. But while working on some other changes to how we handle macro-expanded closure bodies, I found that some of my changes had the side-effect of causing these test closures to show up and start interfering with the reports.
We should have some way for the coverage instrumentor to know that it should ignore closures introduced by #[test]
attributes, and not instrument them at all.