rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

add new lint that disallow renaming parameters in trait functions

Open J-ZhengLi opened this issue 1 year ago • 11 comments

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.

J-ZhengLi avatar Sep 20 '23 11:09 J-ZhengLi

r? @Jarcho

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

rustbot avatar Sep 20 '23 11:09 rustbot

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) {}
}

xFrednet avatar Sep 20 '23 11:09 xFrednet

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 in fact any name starts with underscore will be skipped, that includes names in trait def and trait impl

J-ZhengLi avatar Sep 20 '23 13:09 J-ZhengLi

:umbrella: The latest upstream changes (presumably #11550) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Oct 08 '23 22:10 bors

Since you've already looked at this. r? @Centri3

Jarcho avatar Oct 30 '23 18:10 Jarcho

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

J-ZhengLi avatar Jan 18 '24 11:01 J-ZhengLi

some extra info: there are 2644 occurance of this lint after running lintcheck --recursive

J-ZhengLi avatar Mar 28 '24 09:03 J-ZhengLi

r? clippy

still busy

Manishearth avatar Mar 29 '24 16:03 Manishearth

Sure, it's on my todo list for the next week :D

xFrednet avatar Mar 31 '24 11:03 xFrednet

On zulip it was mentioned that this lint should ideally have a configuration to ignore some lints, like From, TryFrom, and FromStr. Once that is done I believe we can move forward with this. There was also this suggestion:

It looks a bit similar to disallowed_names. Perhaps the name could be disallow_parameter_renames or disallow_renames?

I like the current name, but can understand the reasoning :)

xFrednet avatar Apr 12 '24 09:04 xFrednet

@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 ignored-traits for now, if there's better name plz let me know~

some time I really wish there's an AI that could tell me what should I name my variables/functions/lint/config lol

J-ZhengLi avatar Apr 18 '24 09:04 J-ZhengLi

(Sorry for the delay with the review, my past few weeks have been busy)

no worries, me too XD

ping @xFrednet

J-ZhengLi avatar May 07 '24 09:05 J-ZhengLi

In Clippy's realm, a rule takes flight, No renaming parameters, to keep code tight. Thanks for the effort, I merge with delight.

=^.^=

xFrednet avatar May 12 '24 13:05 xFrednet

:pushpin: Commit 23581897ba77a905c00e644d5ed097706488042f has been approved by xFrednet

It is now in the queue for this repository.

bors avatar May 12 '24 13:05 bors

:hourglass: Testing commit 23581897ba77a905c00e644d5ed097706488042f with merge d47bc8a4d63a8352cbdb9399c5c59e6643184773...

bors avatar May 12 '24 13:05 bors

:broken_heart: Test failed - checks-action_test

bors avatar May 12 '24 14:05 bors

ahh, forgot the cargo collect-metadata again, third times a charm I guess~

J-ZhengLi avatar May 12 '24 14:05 J-ZhengLi

:P

Feel free to r=me after the collection :)

@bors delegate+

xFrednet avatar May 12 '24 14:05 xFrednet

:v: @J-ZhengLi, you can now approve this pull request!

If @xFrednet told you to "r=me" after making some further change, please make that change, then do @bors r=@xFrednet

bors avatar May 12 '24 14:05 bors

should be good now

@bors r=@xFrednet

J-ZhengLi avatar May 12 '24 14:05 J-ZhengLi

:pushpin: Commit 46659acdbde160324bae653e704203221df3b980 has been approved by xFrednet

It is now in the queue for this repository.

bors avatar May 12 '24 14:05 bors

:hourglass: Testing commit 46659acdbde160324bae653e704203221df3b980 with merge 7cfb9a0d6fee91ad636a091f6a425521259f776a...

bors avatar May 12 '24 14:05 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: xFrednet Pushing 7cfb9a0d6fee91ad636a091f6a425521259f776a to master...

bors avatar May 12 '24 14:05 bors