Skip to content

Preserve hex literals in match ranges #11461

@virtualritz

Description

@virtualritz

Description

I am sorry if there is a lint/option for this already. I couldn't find any though.

Below is code from DNGlab, a CLI to convert camera RAW files to DNG format.

Hex literals are used with intent in the codebase to match vendor documentation about hardware, e.g. lenses:

    let lensdata = match version {
      0x100 => ...,
      0x101 => ...,
      0x201 | 0x202 | 0x203 => { ... }
      [...]

clippy --fix turns this into this:

``` rust
    let lensdata = match version {
      0x100 => ...,
      0x101 => ...,
      513..=515 => { ... }
      [...]

It would be great if the hex literals could be preserved here, i.e. clippy would instead suggest/generate:

    let lensdata = match version {
      0x100 => ...,
      0x101 => ...,
      0x201..=0x203 => { ... },
      [...]

Version

rustc 1.74.0-nightly (58e967a9c 2023-09-03)
binary: rustc
commit-hash: 58e967a9cc3bd39122e8cb728e8cec6e3a4eeef2
commit-date: 2023-09-03
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions