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

min_ident_chars triggers on implementation block for foreign traits #13396

Open
Passeriform opened this issue Sep 14, 2024 · 0 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Passeriform
Copy link

Passeriform commented Sep 14, 2024

Summary

I have renamed_function_params lint enabled for foreign traits implementations, which means that a sample impl block for Display trait looks something like this:

impl Display for Foo {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        write!(f, "{}", self.bar())
    }
}

Enabling min_ident_chars on this code correctly flags f argument for fmt method.

I can disable this on the impl block, but I'm implementing this multiple times across the crate. Adding to each implementation can become needless noise. However, I still want to flag any instances of single-character arguments on my traits.

Using the configuration allowed-idents-below-min-chars also doesn't make sense as I'd still want to flag f as an argument name on my traits.

I believe this lint should not be triggering on function arguments on impl blocks as their implementation details are provided by the crate owners.

In case this is not in the scope of this lint, may I propose a configuration option to disable triggering this lint on impl blocks min-ident-chars-ignore-impl

Lint Name

min_ident_chars

Reproducer

I tried this code:

impl Display for Foo {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        write!(f, "{}", self.bar())
    }
}

I saw this happen:

warning: this ident consists of a single char
   --> src\core\card.rs:263:19
    |
20  |     fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
    |                   ^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars
    = note: requested on the command line with `-W clippy::min-ident-chars`

I expected to see this happen:
The lint should not trigger

Version

rustc 1.83.0-nightly (adaff5368 2024-09-12)
binary: rustc
commit-hash: adaff5368b0c7b328a0320a218751d65ab1bba97
commit-date: 2024-09-12
host: x86_64-pc-windows-msvc
release: 1.83.0-nightly
LLVM version: 19.1.0

Additional Labels

No response

@Passeriform Passeriform added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant