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

Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] #3123

Merged
merged 9 commits into from
Nov 3, 2018

Conversation

flip1995
Copy link
Member

@flip1995 flip1995 commented Sep 3, 2018

Closes #3121

@flip1995 flip1995 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 4, 2018
@phansch
Copy link
Member

phansch commented Sep 13, 2018

If I understand it correctly, this would also produce the same warnings as in #3159, right? Should we wait until tool_lints are stable to merge this?

@flip1995
Copy link
Member Author

No this is a tool_attribute, which is already stable. But I realized yesterday that #![rustfmt::skip] does make sense. So I want to look into this problem first, before merging this.

@flip1995 flip1995 changed the title Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] WIP: Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] Sep 15, 2018
@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 15, 2018
@flip1995
Copy link
Member Author

Ok, I looked into this a little more:

cfg_attrs already get processed here:

830  let (mut krate, features) = syntax::config::features(
831      krate,
832      &sess.parse_sess,
833      sess.edition(),
834  );

while PreExpansionPass lints are executed here:

942  time(sess, "pre ast expansion lint checks", || {
943      lint::check_ast_crate(sess, &krate, true)
944  });

The reason only inner/crate attributes are effected by this, is that the compiler only looks at Crate-level attributes and not on Item-level attributes in the config::features() function. That would mean, that this should get linted. Let's add a test for it!

@flip1995
Copy link
Member Author

flip1995 commented Sep 18, 2018

Since having #![rustfmt::skip] as a crate level attribute really doesn't make any sense, I think this is ready to merge. tool_attributes should be stable in 1.30.

@flip1995 flip1995 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Sep 18, 2018
@flip1995 flip1995 changed the title WIP: Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] Sep 18, 2018
@flip1995
Copy link
Member Author

tool_attributes are stable on 1.30.beta.1: Playground

flip1995 added a commit to flip1995/rustfmt that referenced this pull request Oct 29, 2018
`tool_attributes` are stable since 1.30. The old `cfg_attr(rustfmt, rustfmt_skip)` attributes aren't necessary anymore and everyone should switch to `#[rustfmt::skip]` sooner or later.

There is also a Clippy lint in the making for this: rust-lang/rust-clippy#3123
@flip1995
Copy link
Member Author

tool_attributes are stable now! The issue that cfg_attr lints can't handle crate level attributes, can only be resolved by a non trivial change in the compiler. But since crate level rustfmt attributes shouldn't be a thing (IMO), this shouldn't be a blocker for this lint.

tests/ui/cfg_attr_lint.rs Outdated Show resolved Hide resolved
@flip1995
Copy link
Member Author

flip1995 commented Nov 1, 2018

I added a few tests from rustfmt. Now also #[cfg_attr(rustfmt, rustfmt::skip)] gets linted.

I just realized, that we don't have a check for the copyright statement in test and clippy source files. We should add such a check (for easier reviews). Since it is hard to write lints for comments, we should probably add this check in clippy_dev?

@flip1995
Copy link
Member Author

flip1995 commented Nov 2, 2018

bors try

bors bot added a commit that referenced this pull request Nov 2, 2018
@bors
Copy link
Contributor

bors bot commented Nov 2, 2018

try

Build failed

@flip1995 flip1995 force-pushed the cfg_attr_rustfmt branch 2 times, most recently from d1538cc to edc8706 Compare November 2, 2018 14:27
@phansch
Copy link
Member

phansch commented Nov 3, 2018

LGTM!

bors r+

bors bot added a commit that referenced this pull request Nov 3, 2018
3123: Lint #[cfg_attr(rustfmt, rustfmt_skip)] and suggest #[rustfmt::skip] r=phansch a=flip1995

Closes #3121 

Co-authored-by: flip1995 <[email protected]>
Co-authored-by: flip1995 <[email protected]>
@phansch phansch removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 3, 2018
@bors
Copy link
Contributor

bors bot commented Nov 3, 2018

@bors bors bot merged commit 318f84f into rust-lang:master Nov 3, 2018
@flip1995 flip1995 deleted the cfg_attr_rustfmt branch November 3, 2018 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants