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

identity_op in some scenarios #13813

Open
pacak opened this issue Dec 11, 2024 · 1 comment
Open

identity_op in some scenarios #13813

pacak opened this issue Dec 11, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@pacak
Copy link
Contributor

pacak commented Dec 11, 2024

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

@pacak pacak added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 11, 2024
@pacak
Copy link
Contributor Author

pacak commented Dec 11, 2024

#3430 - similar case was resolved by allowing it with constants: #5602 but in my case those are bools and other bit packing constructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant