diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-01-21 15:07:11 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-01-22 12:18:57 +1100 |
| commit | 41dcba805d8ea2c5142cce7044c146aa15d0358c (patch) | |
| tree | 8d0b381788ad29eefe275ac3f9539a88f1688e02 /compiler/rustc_mir_transform/src/coverage | |
| parent | ef71f1047e04438181d7cb925a833e2ada6ab390 (diff) | |
| download | rust-41dcba805d8ea2c5142cce7044c146aa15d0358c.tar.gz rust-41dcba805d8ea2c5142cce7044c146aa15d0358c.zip | |
coverage: Don't instrument `#[automatically_derived]` functions
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index a11d224e8f1..a495dcdbc4e 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -351,7 +351,18 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { return false; } + // Don't instrument functions with `#[automatically_derived]` on their + // enclosing impl block, on the assumption that most users won't care about + // coverage for derived impls. + if let Some(impl_of) = tcx.impl_of_method(def_id.to_def_id()) + && tcx.is_automatically_derived(impl_of) + { + trace!("InstrumentCoverage skipped for {def_id:?} (automatically derived)"); + return false; + } + if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) { + trace!("InstrumentCoverage skipped for {def_id:?} (`#[coverage(off)]`)"); return false; } |
