-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add new duplicated_attributes
lint
#12378
Conversation
r? @Manishearth rustbot has assigned @Manishearth. Use r? to explicitly pick a reviewer |
Manish said they're busy so let's pick someone else. r? @blyxyas |
☔ The latest upstream changes (presumably #12354) made this pull request unmergeable. Please resolve the merge conflicts. |
9b52084
to
3f4cbaf
Compare
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done some tinkering with that FIXME
and cfg_attr
, I think it wouldn't be too hard to support it.
Really good first iteration! :3
clippy_lints/src/attrs.rs
Outdated
@@ -512,6 +515,31 @@ declare_clippy_lint! { | |||
"item has both inner and outer attributes" | |||
} | |||
|
|||
declare_clippy_lint! { | |||
/// ### What it does | |||
/// Checks if an item has duplicated attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this also covers check_crate
.
/// Checks if an item has duplicated attributes. | |
/// Checks for attributes that appear two or more times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
clippy_lints/src/attrs.rs
Outdated
/// Checks if an item has duplicated attributes. | ||
/// | ||
/// ### Why is this bad? | ||
/// More code for no reason. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little more developed? Maybe something like this:
/// More code for no reason. | |
/// Repeating an attribute on the same item (or globally on the same crate) is unnecessary and doesn't have an effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better indeed. ^^'
clippy_lints/src/attrs.rs
Outdated
/// fn foo() {} | ||
/// ``` | ||
#[clippy::version = "1.78.0"] | ||
pub DUPLICATED_ATTR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the lint. It should be definitely plural to fit in with the naming convention ("Allow duplicated attributes"). But I'm not sure if it should be duplicated_attrs
or duplicated_attributes
.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the full version.
3f4cbaf
to
852311f
Compare
Applied suggestions. |
☔ The latest upstream changes (presumably #12394) made this pull request unmergeable. Please resolve the merge conflicts. |
852311f
to
0c167d5
Compare
duplicated_attr
lintduplicated_attributes
lint
Renamed the lint as suggested, fixed merge conflict and double checked: still doesn't work without the |
And even fixed CI. :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I was prioritizing newcomer's reviews, and then got lost in playing a little bit of Helldivers 2, I liked it.
This is good as it is, but please double-check that the update_lints.rs
change is necessary, because I removed it + the rename.rs
attribute and there was no change.
Maybe an artifact of previous versions? If there's black magic and on some platforms that forced attribute is necessary, we'll just keep it there, no big deal :)
Just checked, still not working. Giving the steps I'm doing to reproduce:
As you can see, it fails. So no, I confirm the change is needed. |
Having same issue with baldur's gate 3. :D
I rebased on the latest clippy version (locally) and ran the commands from my previous message, still not working as you can see. |
40507fa
to
ae52a9d
Compare
Meow meow meow |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
It's a lint idea that @llogiq gave me while reviewing another PR.
There are some limitations, in particular for the "output". Initially I wanted to make it possible for directly lint against the whole attribute if its parts were all duplicated, but then I realized that the output would be chaotic if the duplicates were coming from different attributes, so I preferred to go to the simplest way and simply emit a warning for each entry. Not the best, but makes the implementation much easier.
Another limitation is that
cfg_attr
would be a bit more tricky to implement because we need to check if twocfg
sets are exactly the same. I added a FIXME and will likely come back to it later.And finally, I updated the
cargo dev update_lints
command because the generatedtests/ui/rename.rs
file was emitting theduplicated_attributes
lint, so I allowed this lint inside it to prevent it from working.changelog: Add new
duplicated_attributes
lint