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

struct_field_names triggers when the field name *is* the struct name #13857

Open
marienz opened this issue Dec 20, 2024 · 0 comments
Open

struct_field_names triggers when the field name *is* the struct name #13857

marienz opened this issue Dec 20, 2024 · 0 comments
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

@marienz
Copy link

marienz commented Dec 20, 2024

Summary

I'm not sure if this is an actual false positive (looks like changing >= to > here might stop it from firing) or it's just not clear to me (even after reading the lint description) why it thinks this is bad.

The lint description says it checks for prefixes / suffixes, and suggests I delete them. That makes sense to me.

But if the field name is the struct name I can't delete the entire name, I'd have to come up with a different one. I could see the point in suggesting that I use a newtype if I had no other fields, but the lint actually won't fire unless I do have other fields, so that doesn't apply either.

That leaves "come up with a different name". If there is value to that, I'd appreciate the lint description explaining it.

Issue #12922 is somewhat related (not just because it's the same lint): the first example there (app in struct App) would also be allowed if this was changed.

Lint Name

struct_field_names

Reproducer

I tried this code:

struct Map {
    map: Vec<Vec<i32>>,
    rows: usize,
    cols: usize,
}

I saw this happen:

warning: field name starts with the struct's name
  --> foo.rs:89:5
   |
89 |     map: Vec<Vec<i32>>,
   |     ^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names

I expected to see this happen:

Either no lint or a better explanation of why this is bad and what I should do instead.

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

No response

@marienz marienz 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 Dec 20, 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