rust-lang / rust-lang/rust-clippy

`struct_field_names` not triggered when 2 or less fields

Open
#12,089 5 comments 0 reactions 1 assignee View on GitHub

@alexis-langlet is already working on this.

Since Jan 4, 2024.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

As mentioned in #12035, struct_field_names lint is only triggered when struct contains more than 3 fields.
It should be triggered no matter the fields' number.

Lint Name

struct_field_names

Reproducer

I tried this code:

#![warn(clippy::pedantic)]
struct A {
    a_group: String,
    a_location: String,
}

struct_field_names
I expected to see this happen: warning: field name starts with the struct's name

Instead, this happened: no warning about it

Version
rustc 1.76.0-nightly (87e1447aa 2023-11-30)
binary: rustc
commit-hash: 87e1447aadaa2899ff6ccabe1fa669eb50fb60a1
commit-date: 2023-11-30
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.