about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-06-21 21:59:02 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-06-26 10:08:05 +1000
commit7f37f8af5f067e0f4f8d14adb7d76f013e3c4118 (patch)
treebf626edd2d408b287ad5f0ad522162dcdc09c431 /compiler/rustc_passes/src
parent3262611cc5db7ce83dee4268fb1901311b24e5fc (diff)
downloadrust-7f37f8af5f067e0f4f8d14adb7d76f013e3c4118.tar.gz
rust-7f37f8af5f067e0f4f8d14adb7d76f013e3c4118.zip
coverage: Allow `#[coverage(..)]` on `impl` and `mod`
These attributes apply to all enclosed functions/methods/closures, unless
explicitly overridden by another coverage attribute.
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/check_attr.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index d33f12a973f..5f8e4a8b7a7 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -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,