rust-lang / rust-lang/rust-clippy

unusual_byte_groupings triggers for binary literals

Open
#11,749 7 comments 1 reaction 1 assignee View on GitHub

@nshah067 is already working on this.

Since May 16, 2025.

C-bug good first issue I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

This is kind of related to https://github.com/rust-lang/rust-clippy/issues/9183 and https://github.com/rust-lang/rust-clippy/issues/11243.

When I'm using binary literals for parsing formats, I usually don't use equal groupings but instead use groupings that reflect the underlying format.

It's easy enough to allow unusual_byte_groupings for these parts of the code, but I'm probably not the only one doing that and maybe the lint should be disabled completely for binary literals or only trigger in more restricted cases (all groups the same but one is off-by-one or so?).

Lint Name

unusual_byte_groupings

Reproducer

The following example is from parsing the header of an MP3 frame, specifically parsing the layer description bits.

The second byte of the header contains 4 groups: 3 bits, 2 bits, 2 bits (what we're interested in here) and another bit in the end so I'd use 0b000_00_11_0 as a mask.

fn main() {
    let data = [0u8; 4];
    
    let layer_desc = (data[1] & 0b000_00_11_0) >> 1;
    println!("meh {layer_desc}");
}

I saw this happen:

warning: digits of hex, binary or octal literal not in groups of equal size
 --> src/main.rs:4:33
  |
4 |     let layer_desc = (data[1] & 0b000_00_11_0) >> 1;
  |                                 ^^^^^^^^^^^^^ help: consider: `0b0000_0110`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings
  = note: `#[warn(clippy::unusual_byte_groupings)]` on by default

I expected to see this happen: [nothing]

Version
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.