disallowed_names for identifiers and not just variables · Issue #11306 · rust-lang/rust-clippy (original) (raw)

disallowed_names complains about variables, like the lint description explains:

echo 'fn main() { let foo = 0; }' | rustup run 1.71.1 clippy-driver -Aunused_variables -

However, it does not warn on identifiers in general:

echo 'struct foo; fn main() {}' | rustup run 1.71.1 clippy-driver -Adead_code -Anon_camel_case_types - echo 'fn foo() {} fn main() {}' | rustup run 1.71.1 clippy-driver -Adead_code -

This is particularly noticeable in a sample that may use a struct and then instantiate it. I have hit this in a Linux kernel example:

#![expect(clippy::disallowed_names)]

#[pin_data] struct Foo { #[pin] a: Mutex, b: u32, }

let foo = pin_init!(Foo { a <- new_mutex!(42, "Foo::a"), b: 24, });

Is it intended that the lint only covers variables? If yes, should there be a disallowed_idents even if it overlaps with this one? (disallowed_types and others seem to be intended to cover particular paths that should not be used for a given reason, rather than just a name on any path; and even if those lints supported it, then it would still require repeating the name for the different entities, which would not be ideal).

If it is not intended, and disallowed_names is expanded to cover more entities: