Skip to content

Fix min_ident_chars: ignore on trait impl. #15275

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

Merged
merged 1 commit into from
Jul 30, 2025

Conversation

t-webber
Copy link
Contributor

@t-webber t-webber commented Jul 14, 2025

fixes #13396

changelog: [min_ident_chars]: ignore lint when implementing a trait, to respect [renamed_function_params]

@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2025

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 14, 2025
Copy link

github-actions bot commented Jul 14, 2025

Lintcheck changes for e8db4aa

Lint Added Removed Changed
clippy::min_ident_chars 89 2454 39

This comment will be updated if you push new changes

@t-webber t-webber changed the title Min idents char Fix min_ident_chars: ignore on trait impl. Jul 14, 2025
@samueltardieu
Copy link
Member

For a local trait, it should warn about the short parameter name in the trait method definition. I don't see a test for this, and I suspect it won't warn. To suppress warnings about trait implementations, we should ensure it warns at the trait definition so that users are warned at least once about the usage of short identifiers.

@t-webber
Copy link
Contributor Author

t-webber commented Jul 15, 2025

Yes, I didn't look at that case, and it seems it never fired the lint even before my PR:

#![allow(dead_code)]
#![warn(clippy::min_ident_chars)]

trait Trait {
    fn func(x: u32) -> u32;
}

struct Struct;

impl Trait for Struct {
    fn func(x: u32) -> u32 {
        x
    }
}

fn main() {}

This code doesn't produce any warnings.

For functions with one char, it works though, and it warns on trait definition only, so I guess I should do the same thing for one-char-long params

@t-webber
Copy link
Contributor Author

t-webber commented Jul 28, 2025

My previous message wasn't correct, as x is allowed as a single char by default. If you change my code and put another variable than x, the lint fires. It lints only on the implementation of the function, not the definition though.

Strange thing that the CIs stopped passing on an error in the source file, that I didn't change on this commit

Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a "Limitations" section to the lint definition, after the "Example"? Something like

    /// ### Limitations
    /// Trait implementations which use the same function or parameter name as the trait declaration will
    /// not be warned about, even if the name is below the configured limit.

Also, it would be great to open an issue with label C-enhancement suggesting to add a new configuration option for this lint so that it triggers when using short parameter names even in the case of trait implementation: while we cannot do anything about the function names themselves, we can suggest renaming the function parameters in the implementation.

@samueltardieu
Copy link
Member

r? samueltardieu
@rustbot author

@rustbot rustbot assigned samueltardieu and unassigned dswij Jul 29, 2025
@rustbot rustbot 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 Jul 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 29, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@t-webber
Copy link
Contributor Author

Also, it would be great to open an issue with label C-enhancement suggesting to add a new configuration option for this lint so that it triggers when using short parameter names even in the case of trait implementation: while we cannot do anything about the function names themselves, we can suggest renaming the function parameters in the implementation.

cf. #15365

@t-webber
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot 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 Jul 29, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is starting to look good. Could you test the suggested change (and added tests), and tell me what you think about it? Also, you may squash the commits into one, that will be necessary before merging.

@rustbot rustbot 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 Jul 29, 2025
@t-webber t-webber force-pushed the min_idents_char branch 2 times, most recently from 31c16c6 to 31d829d Compare July 30, 2025 05:08
@t-webber
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Jul 30, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2025
@samueltardieu
Copy link
Member

Thanks. That makes it a large change, with many more changes in output too, but for a restriction lint I think this is fine.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2025
@samueltardieu samueltardieu reopened this Jul 30, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2025
@samueltardieu samueltardieu enabled auto-merge July 30, 2025 07:53
@samueltardieu samueltardieu added this pull request to the merge queue Jul 30, 2025
Merged via the queue into rust-lang:master with commit 436efbb Jul 30, 2025
22 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 30, 2025
@t-webber
Copy link
Contributor Author

Thank you for your help!

@t-webber t-webber deleted the min_idents_char branch July 30, 2025 08:09
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.

min_ident_chars triggers on implementation block for foreign traits
4 participants