rust-lang / rust-lang/rust-clippy

struct_excessive_bools for different reasons?

Open
#16,409 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Using multiple bools like shown in the example seems like a complete beginner mistake to me.
I don't think I ever used multiple bools to mark progress. Even most beginners would just use a single number I guess.

(maybe this sometimes happens when some of the bools are supposed to be enabled at the same time, but not all of them)

I always get this error when creating settings.

For example the settings of a character in a game look like this:

struct PlayerSettings {
    can_jump: bool,
    can_run: bool,
    can_dash: bool,
    can_attack: bool,
    can_stomp: bool,
    ...
}

And in such a case, this implementation seems totally fine. That's probably why this lint is set to allow by default.

But I think using multiple bools in this case might still not be great. Because I got this lint, I turned such a struct into a bitset.

Something like this:

struct PlayerSettings {
    bits: u16
}

impl PlayerSettings {
    can_jump(&self) -> bool {
        self.bits & 1 > 0
    }

    can_run(&self) -> bool {
        self.bits & 2 > 0
    }

    can_dash(&self) -> bool {
        self.bits & 4 > 0
    }

    ...
}

So maybe instead of suggesting only state machines and enums, using bitsets could also be suggested here?

Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
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 by reviewing the struct_excessive_bools lint and the issue's discussion of state machines, enums, and bitsets. Determine the intended guidance and scope before identifying the relevant implementation and tests; the work is done when the agreed recommendation is documented in the lint behavior and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.