Skip to content

identity_op in some scenarios #13813

Open
@pacak

Description

@pacak

Summary

I find myself disabling identity_op lint over and over again.

When complaining about identity ops clippy should look around. If there's a similar construct in nearby context but the op is not an identity - clippy should keep quiet.

Lint Name

clippy::identity_op

Reproducer

I tried this code:

             let mut v = 0;
              v |= (value.normal_market as u16) << 0;
              v |= (value.oddlot_market as u16) << 1;
              v |= (value.spot_market as u16) << 2;
              v |= (value.auction_market as u16) << 3;

I saw this happen:

consider reducing it to: `(value.normal_market as u16)`

I expected to see this happen:

Code is accepted as is - the op is identity, but it is there to maintain code uniformity

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions