Open emilyyyylime opened 5 months ago
also related
struct Foo {
foo_type: FooType,
}
renaming to type
would not be possible as it's a reserved identifier
I think this should be also no error since the field name is identical to the type name (except snake vs. pascal case)
struct Foo {
foo_client: FooClient,
}
Regardless of whether the name matches the type, if there is only a single field with a match, I don't think this lint should trigger. Example,
struct Foo {
foo: String,
bar: i64,
... more or not
}
Yes, "foo" could be replaced by "inner" or some such, but perhaps that should be a different lint. The example in the clippy explainer suggests that this is (and I interporeted it as) primarily about unnecessary repetition as in the example struct Cake { cake_sugar: u8, cake_flour: u8, cake_eggs: u8 }
.
Thanks!
rustc 1.78.0 (9b00956e5 2024-04-29)
Summary
I propose that the
clippy::struct_field_names
lint, which checks for struct fields whose names share words with the struct's name, check the type name of the struct field—and forego emitting the lint if the field name matches its type (especially from a different scope).Lint Name
struct_field_names
Reproducer
Some motivating examples:
Version
Additional Labels
No response