1
Fork 0

coverage: Allow #[coverage(..)] on impl and mod

These attributes apply to all enclosed functions/methods/closures, unless
explicitly overridden by another coverage attribute.
This commit is contained in:
Zalathar 2024-06-21 21:59:02 +10:00
parent 3262611cc5
commit 7f37f8af5f
13 changed files with 253 additions and 170 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,