Skip to content

enum_variant_names does not consider encapsulated type #13637

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

Closed
chrysn opened this issue Oct 31, 2024 · 1 comment · Fixed by #14619
Closed

enum_variant_names does not consider encapsulated type #13637

chrysn opened this issue Oct 31, 2024 · 1 comment · Fixed by #14619
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy

Comments

@chrysn
Copy link
Contributor

chrysn commented Oct 31, 2024

Clippy is unhappy with this perfectly reasonable enum:

pub enum Error {
    RecvError(udp::RecvError),
    SendError(udp::SendError),
    BindError(udp::BindError),
    AddressFamilyUnavailable,
}

The lint enum_variant_names fires because RecvError, SendError and BindError variants are named like the type. That's the fundamental point of the lint, but it fails to consider information that'd be available to the linter: That that substring is also part of the encapsulated type.

I'm not well enough familiar with clippy to come up with code, but I'd like to suggest the following addition to the lint's rules:

If the variant contains a single item, and any component of the contained item's path is identical to the variant's name, then the lint does not trigger.

By including the full path, it would even protect a hypothetical enum Cbor { MiniCbor(minicbor::Something), SerdeCbor(serde_cbor::Something) }; I can't tell how much going-out-of-the-way it would need to catch SerdeCbor to be justified by serde_cbor, so maybe a simpler version that just doesn't trigger on the real example above suffices.

@samueltardieu samueltardieu added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy labels Apr 8, 2025
@aaron-ang
Copy link
Contributor

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue May 6, 2025
…mponents (#14619)

fix #13637

As suggested in the PR above, we should not lint enum variants
containing matching path names.

changelog: [`item_name_repetitions`]: exclude enum variants with
identical path components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants