rust/tests/coverage
León Orell Valerian Liehr 8bd126cb18
Rollup merge of #120185 - Zalathar:auto-derived, r=wesleywiser
coverage: Don't instrument `#[automatically_derived]` functions

This PR makes the coverage instrumentor detect and skip functions that have [`#[automatically_derived]`](https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute) on their enclosing impl block.

Most notably, this means that methods generated by built-in derives (e.g. `Clone`, `Debug`, `PartialEq`) are now ignored by coverage instrumentation, and won't appear as executed or not-executed in coverage reports.

This is a noticeable change in user-visible behaviour, but overall I think it's a net improvement. For example, we've had a few user requests for this sort of change (e.g. #105055, https://github.com/rust-lang/rust/issues/84605#issuecomment-1902069040), and I believe it's the behaviour that most users will expect/prefer by default.

It's possible to imagine situations where users would want to instrument these derived implementations, but I think it's OK to treat that as an opportunity to consider adding more fine-grained option flags to control the details of coverage instrumentation, while leaving this new behaviour as the default.

(Also note that while `-Cinstrument-coverage` is a stable feature, the exact details of coverage instrumentation are allowed to change. So we *can* make this change; the main question is whether we *should*.)

Fixes #105055.
2024-01-24 15:43:12 +01:00
..
auxiliary
abort.cov-map
abort.coverage
abort.rs
assert.cov-map
assert.coverage
assert.rs
assert_not.cov-map
assert_not.coverage
assert_not.rs
async.cov-map
async.coverage
async.rs
async2.cov-map
async2.coverage
async2.rs
async_block.cov-map
async_block.coverage
async_block.rs
bad_counter_ids.cov-map
bad_counter_ids.coverage
bad_counter_ids.rs
bench.cov-map
bench.coverage
bench.rs
closure.cov-map
closure.coverage
closure.rs
closure_bug.cov-map
closure_bug.coverage
closure_bug.rs
closure_macro.cov-map
closure_macro.coverage
closure_macro.rs
closure_macro_async.cov-map
closure_macro_async.coverage
closure_macro_async.rs
color.coverage
color.rs
conditions.cov-map
conditions.coverage
conditions.rs
continue.cov-map
continue.coverage
continue.rs
coroutine.cov-map
coroutine.coverage
coroutine.rs
dead_code.cov-map
dead_code.coverage
dead_code.rs
drop_trait.cov-map
drop_trait.coverage
drop_trait.rs
fn_sig_into_try.cov-map
fn_sig_into_try.coverage
fn_sig_into_try.rs
generics.cov-map
generics.coverage
generics.rs
if.cov-map
if.coverage
if.rs
if_else.cov-map
if_else.coverage
if_else.rs
if_not.cov-map
if_not.coverage
if_not.rs
ignore_map.coverage
ignore_map.rs
ignore_run.cov-map
ignore_run.rs
inline-dead.cov-map
inline-dead.coverage
inline-dead.rs
inline.cov-map
inline.coverage
inline.rs
inner_items.cov-map
inner_items.coverage
inner_items.rs
issue-83601.cov-map
issue-83601.coverage
issue-83601.rs
issue-84561.cov-map
issue-84561.coverage
issue-84561.rs
issue-85461.cov-map
issue-85461.coverage
issue-85461.rs
issue-93054.cov-map
issue-93054.coverage
issue-93054.rs
lazy_boolean.cov-map
lazy_boolean.coverage
lazy_boolean.rs
long_and_wide.cov-map
long_and_wide.coverage
long_and_wide.rs
loop_break_value.cov-map
loop_break_value.coverage
loop_break_value.rs
loops_branches.cov-map
loops_branches.coverage
loops_branches.rs
macro_name_span.cov-map
macro_name_span.coverage
macro_name_span.rs
match_or_pattern.cov-map
match_or_pattern.coverage
match_or_pattern.rs
nested_loops.cov-map
nested_loops.coverage
nested_loops.rs
no_cov_crate.cov-map
no_cov_crate.coverage
no_cov_crate.rs
no_spans.cov-map
no_spans.coverage
no_spans.rs
no_spans_if_not.cov-map
no_spans_if_not.coverage
no_spans_if_not.rs
overflow.cov-map
overflow.coverage
overflow.rs
panic_unwind.cov-map
panic_unwind.coverage
panic_unwind.rs
partial_eq.cov-map
partial_eq.coverage
partial_eq.rs
README.md
simple_loop.cov-map
simple_loop.coverage
simple_loop.rs
simple_match.cov-map
simple_match.coverage
simple_match.rs
sort_groups.cov-map
sort_groups.coverage
sort_groups.rs
test_harness.cov-map
test_harness.coverage
test_harness.rs
thin-lto.cov-map
thin-lto.coverage
thin-lto.rs
tight_inf_loop.cov-map
tight_inf_loop.coverage
tight_inf_loop.rs
trivial.cov-map
trivial.coverage
trivial.rs
try_error_result.cov-map
try_error_result.coverage
try_error_result.rs
unicode.cov-map
unicode.coverage
unicode.rs
unreachable.cov-map
unreachable.coverage
unreachable.rs
unused.cov-map
unused.coverage
unused.rs
unused_mod.cov-map
unused_mod.coverage
unused_mod.rs
uses_crate.cov-map
uses_crate.coverage
uses_crate.rs
uses_inline_crate.cov-map
uses_inline_crate.coverage
uses_inline_crate.rs
while.cov-map
while.coverage
while.rs
while_early_ret.cov-map
while_early_ret.coverage
while_early_ret.rs
yield.cov-map
yield.coverage
yield.rs

The tests in this directory are shared by two different test modes, and can be run in multiple different ways:

  • ./x.py test coverage-map (compiles to LLVM IR and checks coverage mappings)
  • ./x.py test coverage-run (runs a test binary and checks its coverage report)
  • ./x.py test coverage (runs both coverage-map and coverage-run)

Maintenance note

These tests can be sensitive to small changes in MIR spans or MIR control flow, especially in HIR-to-MIR lowering or MIR optimizations.

If you haven't touched the coverage code directly, and the tests still pass in coverage-run mode, then it should usually be OK to just re-bless the mappings as necessary with ./x.py test coverage-map --bless, without worrying too much about the exact changes.