rust-clippy/clippy_lints/src/utils
Aaron Hill 33f3cfcadc Fix inconsistencies in handling of inert attributes on statements
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-24 11:55:48 -04:00
..
ast_utils.rs Auto merge of #75800 - Aaron1011:feature/full-nt-tokens, r=petrochenkov 2020-09-11 02:35:01 +00:00
attrs.rs Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup 2020-08-11 17:50:45 +02:00
author.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
camel_case.rs new lints around #[must_use] fns 2019-10-14 12:09:04 +02:00
comparisons.rs Rustup to rust-lang/rust#67886 2020-01-07 01:46:33 +09:00
conf.rs Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup 2020-10-09 12:45:29 +02:00
constants.rs Remove all copyright license headers 2019-01-08 21:46:39 +01:00
diagnostics.rs Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup 2020-09-24 14:49:22 +02:00
eager_or_lazy.rs Handle ExprKind::ConstBlock on clippy 2020-10-16 17:14:34 -03:00
higher.rs Merge commit '3d0b0e66afdfaa519d8855b338b35b4605775945' into clippyup 2020-08-28 18:43:25 +02:00
hir_utils.rs Handle ExprKind::ConstBlock on clippy 2020-10-16 17:14:34 -03:00
inspector.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
internal_lints.rs Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup 2020-09-24 14:49:22 +02:00
mod.rs Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup 2020-10-09 12:45:29 +02:00
numeric_literal.rs Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup 2020-10-09 12:45:29 +02:00
paths.rs Appease the almightly lord clippy, hallowed be thy name 2020-10-17 13:48:54 -04:00
ptr.rs Use 'tcx for references to AccessLevels wherever possible. 2020-07-03 00:04:48 +03:00
qualify_min_const_fn.rs Refactor how SwitchInt stores jump targets 2020-10-10 17:46:11 +02:00
sugg.rs Handle ExprKind::ConstBlock on clippy 2020-10-16 17:14:34 -03:00
sym.rs Rustup to https://github.com/rust-lang/rust/pull/67853 2020-01-04 11:30:03 +01:00
usage.rs Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup 2020-09-24 14:49:22 +02:00