rust-lang / rust-lang/rust-clippy

Exception to `struct_field_names`

Open
#12,922 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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:

pub struct App {
    app: widgetui::App, // field name starts with the struct's name
    // ...
}
pub struct Client {
    http_client: reqwest::Client, // field name ends with the struct's name
    // ...
}
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Additional Labels

No response

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.

Research direction

Locate the implementation and tests for the clippy::struct_field_names lint, then read how it currently compares struct and field names. Add coverage for fields whose names match their types, including types from another scope, and verify that the lint is not emitted for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.