rust/compiler/rustc_lint/src
Aaron Hill ac384ac2db
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
..
nonstandard_style mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
array_into_iter.rs Auto-generate lint documentation. 2020-09-13 08:48:03 -07:00
builtin.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
context.rs Remove unused code from remaining compiler crates 2020-10-14 04:14:32 +02:00
early.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
internal.rs add test 2020-09-21 20:36:05 +02:00
late.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
levels.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
lib.rs Auto merge of #77119 - GuillaumeGomez:unclosed-html-tag-lint, r=jyn514 2020-10-07 09:56:51 +00:00
non_ascii_idents.rs Auto merge of #76541 - matthiaskrgr:unstable_sort, r=davidtwco 2020-09-14 21:43:17 +00:00
nonstandard_style.rs use array_windows instead of windows in the compiler 2020-09-20 08:11:05 +02:00
passes.rs Add check_generic_arg early pass 2020-10-16 17:14:36 -03:00
redundant_semicolon.rs Auto-generate lint documentation. 2020-09-13 08:48:03 -07:00
traits.rs Uplift drop-bounds lint from clippy 2020-10-01 12:06:33 -07:00
types.rs Make {u,}int_range functions a bit nicer 2020-10-20 19:36:44 +02:00
unused.rs Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov 2020-10-20 12:11:06 +09:00