Skip to content

Consider silencing struct_field_names for structs with derive(Serialize/Deserialize) #12035

Closed as not planned
@jyn514

Description

@jyn514

Summary

Clippy silences struct_field_names for public structs. This is good and makes sense; the field is part of the public API and renaming it would be a breaking change. However, it still emits the lint for structs with derive(Deserialize). I think these should also be silenced, because Serialize and Deserialize are "super public" - not just available to other crates, but to other programs as well.

Lint Name

struct_field_names

Reproducer

I tried this code:

#![warn(clippy::pedantic)]
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Resource {
    pub(crate) id: String,
    pub(crate) name: String,
    pub(crate) resource_group: String,
}

I saw this happen:

warning: field name starts with the struct's name
 --> src/lib.rs:9:5
  |
9 |     pub(crate) resource_group: String,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::pedantic)]
  |         ^^^^^^^^^^^^^^^^
  = note: `#[warn(clippy::struct_field_names)]` implied by `#[warn(clippy::pedantic)]`

I expected to see this happen: No lint is emitted.

As an aside, the lint stops firing if i remove id or name, which seems quite odd.

Version

clippy 0.1.75 (82e1608d 2023-12-21)
rustc 1.75.0 (82e1608df 2023-12-21)

Additional Labels

No response

Metadata

Metadata

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveS-needs-discussionStatus: Needs further discussion before merging or work can be startedT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions