rust-lang / rust-lang/rust-clippy

Large enum variant: print size of all other variants?

Open
#9,009 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

For enums where all variants are quite large, the lint seems pretty misfirey e.g. I've an enum where the largest member is 7200 bytes, but the second largest is 6800, and the third is probably 6500.

The lint currently only prints the first and second, which is less informative than it could be.

An other option would be to suggest boxing the entire enum if many / most variants are very large, even if it triggers very large allocation for a small number of small variants it seems like it'd not be much of an issue. Maybe that could be part of a "large struct" lint if there is one?

Version
rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0
Additional Labels

@rustbot label +C-question

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 by locating the Clippy implementation and tests for the large enum variant lint, then read how its diagnostic selects the reported variants. The issue is done when the diagnostic provides useful size information for all relevant large variants, with tests covering enums whose largest variants are similarly sized.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
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.