Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve hex literals in match ranges #11461

Closed
virtualritz opened this issue Sep 4, 2023 · 1 comment · Fixed by #11462
Closed

Preserve hex literals in match ranges #11461

virtualritz opened this issue Sep 4, 2023 · 1 comment · Fixed by #11462
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@virtualritz
Copy link

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

@Centri3
Copy link
Member

Centri3 commented Sep 4, 2023

There is the NumericLiteral type which handles this. It shouldn't be too difficult to switch to it.

Unfortunately this info isn't preserved when building the AST, so it must be lexed again. This is ok though.

@Centri3 Centri3 added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Sep 4, 2023
@bors bors closed this as completed in 6150bf5 Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants