rust-lang / rust-lang/rust-clippy

enum_variant_names triggers when used with name-aware proc macros

Open
#9,998 0 comments 0 reactions 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

enum_variant_names is a false positive whenever it's used with proc macros such as structopt or serde, since the enum variant names are part of the UI or over-the-wire protocol being generated, not simply a matter of programmer style.

Lint Name

enum_variant_names

Reproducer
#[derive(StructOpt)]
enum Command {
    /// Pets a cat.
    PetCat,
    /// Pets a dog.
    PetDog,
    /// Pets a sheep.
    PetSheep,
}
/*
USAGE:
    animal-simulator <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help         Prints this message or the help of the given subcommand(s)
    pet-cat      Pets a cat
    pet-dog      Pets a dog
    pet-sheep    Pets a sheep
*/

One could argue about whether or not this prefix is appropriate from a UI/UX point of view, but I don't think that this is an appropriate decision for clippy to make about the program's behavior when it is intended to be enforcing code style.

Version
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.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

Start with the enum_variant_names lint and the StructOpt reproducer in the issue. Determine how name-aware proc macros such as StructOpt and serde should affect this lint, then verify that the reproducer no longer reports a false positive while ordinary enum naming cases remain covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.