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:
commit
70b69a2384
23 changed files with 344 additions and 344 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue