-
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 lint that disallow renaming parameters in trait functions #11540
Conversation
r? @Jarcho (rustbot has picked a reviewer for you, use r? to override) |
I haven't looked at the implementation, so this might already be implemented: I would recommend that it allows removing leading underscores from the names. Here is an example, of what I mean: trait Foo {
fn foo(_param: u32) {}
}
struct FooImpl;
impl Foo for FooImpl {
// vvvvv This should be allowed
fn foo(param: u32) {
println!("{param}");
}
} Potentially, it could also allow adding an underscore, but here I'm uncertain if that's a good idea. Still, this would be the example for that case: trait Bar {
fn bar(param: u32) {
println!("{param}");
}
}
struct BarImpl;
impl Bar for BarImpl {
// vvvvvv Maybe this could be allowed?
fn bar(_param: u32) {}
} |
It should already be implemented :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.
Just some minor nits.
I still think we should restrict this to some traits (by default) using an attribute like clippy::cant_rename
(bikeshedding pending!). We can add this to many libstd traits and crate authors can opt into this if they really want. Consistency isn't as big of a deal when the trait is rarely used already.
d1fc8d5
to
1d4f27b
Compare
☔ The latest upstream changes (presumably #11550) made this pull request unmergeable. Please resolve the merge conflicts. |
Since you've already looked at this. r? @Centri3 |
Perhaps this was forgotten 😭 , even I couldn't remember what I did Plus, seems like she's busy btw? so... umm @rustbot r? @rust-lang/clippy |
ec3b457
to
5a03c9b
Compare
some extra info: there are 2644 occurance of this lint after running |
r? clippy still busy |
Sure, it's on my todo list for the next week :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.
Thank you for the implementation, this looks good to me. Time to get the FCP started.
@rustbot label +S-final-comment-period -S-waiting-on-author
On zulip it was mentioned that this lint should ideally have a configuration to ignore some lints, like
I like the current name, but can understand the reasoning :) |
@xFrednet Finally got some time working on this~ I've added a configuration for it, but again... not confident about that config's name, which is some time I really wish there's an AI that could tell me what should I name my variables/functions/lint/config lol |
|
||
use super::RENAMED_FUNCTION_PARAMS; | ||
|
||
static IGNORED_TRAIT_IDS: OnceLock<DefIdSet> = OnceLock::new(); |
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 if I should use OnceLock
here, haven't seen them in other lints, maybe there's some kind of concern? idk
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 believe some other lints store this in the lint pass struct instead. The IDs can then be collected in fn check_crate()
. I would prefer that solution over having a static object. Otherwise, I don't believe there is a reason against OnceLock
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.
Oh I see, I just thought it might be redundant to having a list of trait paths, and a set of their ids stored in the same struct
nvm, it does seems very common
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.
Two NITs that should hopefully be easy to fix and then this should be good to go :D
(Sorry for the delay with the review, my past few weeks have been busy)
clippy_config/src/conf.rs
Outdated
/// - By default, the following traits are ignored: `From`, `TryFrom`, `FromStr` | ||
/// - `".."` can be used as part of the list to indicate that the configured values should be appended to the | ||
/// default configuration of Clippy. By default, any configuration will replace the default value. | ||
(ignored_traits: Vec<String> = DEFAULT_IGNORED_TRAITS.iter().map(ToString::to_string).collect()), |
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.
This name is too general, maybe allow_renamed_params_for
or renamed_function_params_alllowed_for
?
clippy_config/src/conf.rs
Outdated
@@ -671,6 +688,7 @@ fn deserialize(file: &SourceFile) -> TryConf { | |||
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS); | |||
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES); | |||
extend_vec_if_indicator_present(&mut conf.conf.allowed_prefixes, DEFAULT_ALLOWED_PREFIXES); | |||
extend_vec_if_indicator_present(&mut conf.conf.ignored_traits, DEFAULT_IGNORED_TRAITS); |
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.
Nice! :D
|
||
use super::RENAMED_FUNCTION_PARAMS; | ||
|
||
static IGNORED_TRAIT_IDS: OnceLock<DefIdSet> = OnceLock::new(); |
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 believe some other lints store this in the lint pass struct instead. The IDs can then be collected in fn check_crate()
. I would prefer that solution over having a static object. Otherwise, I don't believe there is a reason against OnceLock
apply review suggestions by @Centri3: use multi suggestion; change output message format; add macro expansion check & tests;
no worries, me too XD ping @xFrednet |
In Clippy's realm, a rule takes flight, =^.^= |
💔 Test failed - checks-action_test |
ahh, forgot the |
:P Feel free to @bors delegate+ |
✌️ @J-ZhengLi, you can now approve this pull request! If @xFrednet told you to " |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #11443
fixes: #486
changelog: add new lint [
renamed_function_params
]Note that the lint name is not final, because I have a bad reputation in naming things, and I don't trust myself.