Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] Forbid derive attributes on invalid targets #78338

Closed
wants to merge 2 commits into from

Conversation

Aaron1011
Copy link
Member

cc #78331

Based on #78326

Opening for a Crater run

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 rust-lang#78306
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 24, 2020
@Aaron1011
Copy link
Member Author

r? @ghost

@Aaron1011
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Oct 24, 2020

⌛ Trying commit 4429d50 with merge ff044a3d65d25a17c3e14c1530004e1540179ba7...

@Aaron1011 Aaron1011 changed the title [EXPERIMENT] Deny derive attributes on invalid targets [EXPERIMENT] Forbid derive attributes on invalid targets Oct 24, 2020
@bors
Copy link
Contributor

bors commented Oct 25, 2020

☀️ Try build successful - checks-actions
Build commit: ff044a3d65d25a17c3e14c1530004e1540179ba7 (ff044a3d65d25a17c3e14c1530004e1540179ba7)

@Aaron1011
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-78338 created and queued.
🤖 Automatically detected try build ff044a3d65d25a17c3e14c1530004e1540179ba7
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2020
@craterbot
Copy link
Collaborator

🚧 Experiment pr-78338 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-78338 is completed!
📊 13 regressed and 5 fixed (127561 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Oct 28, 2020
@Aaron1011
Copy link
Member Author

There's a very small number of actual regressions. I'll open PRs to fix those crates

@estebank
Copy link
Contributor

Before landing this change we should at least change the lint to deny by default for a few versions. The change a priori seems significant enough (to me) to be gated on an edition boundary, but the actual impact seems low. (Let's take a look at the ICEs too.)

@Aaron1011
Copy link
Member Author

Before landing this change we should at least change the lint to deny by default for a few versions

I'm fine with doing this, but we'll need to introduce a new lint, since it's currently going through unused_attributes.

@crlf0710 crlf0710 added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 13, 2020
@petrochenkov
Copy link
Contributor

Closing in favor of #79078, which does the same thing.

@petrochenkov
Copy link
Contributor

I don't think this needs a further deprecation period, this was a warning for very long time and the affected projects are not maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants