1
Fork 0

Rollup merge of #126721 - Zalathar:nested-cov-attr, r=oli-obk

coverage: Make `#[coverage(..)]` apply recursively to nested functions

This PR makes the (currently-unstable) `#[coverage(off)]` and `#[coverage(on)]` attributes apply recursively to all nested functions/closures, instead of just the function they are directly attached to.

Those attributes can now also be applied to modules and to impl/impl-trait blocks, where they have no direct effect, but will be inherited by all enclosed functions/closures/methods that don't override the inherited value.

---

Fixes #126625.
This commit is contained in:
Jacob Pratt 2024-06-27 02:06:18 -04:00 committed by GitHub
commit 70b69a2384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 344 additions and 344 deletions

View file

@ -369,13 +369,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
/// Checks that `#[coverage(..)]` is applied to a function or closure.
/// Checks that `#[coverage(..)]` is applied to a function/closure/method,
/// or to an impl block or module.
fn check_coverage(&self, attr: &Attribute, span: Span, target: Target) -> bool {
match target {
// #[coverage(..)] on function is fine
Target::Fn
| Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
| Target::Impl
| Target::Mod => true,
_ => {
self.dcx().emit_err(errors::CoverageNotFnOrClosure {
attr_span: attr.span,