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

lint useless operands in binary operations #2086

Open
oli-obk opened this issue Sep 26, 2017 · 3 comments
Open

lint useless operands in binary operations #2086

oli-obk opened this issue Sep 26, 2017 · 3 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Sep 26, 2017

Things like x & 0 can be just 0. Basically any identity or erasing operation should be linted.

  • x + 0
  • x * 1
  • x | 0
  • x & 0
  • x & uint_max
  • x % uint_max
  • x / uint_max
  • x / x
  • x - x
  • ...
@oli-obk oli-obk added L-unnecessary Lint: Warn about unnecessary code good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Sep 26, 2017
@llogiq
Copy link
Contributor

llogiq commented Sep 26, 2017

We already have the ineffective_operation lint that catches some of those.

Also one needs to be careful, someone can overload the ops to mean something different.

@clarfonthey
Copy link
Contributor

x % uint_max isn't just x; it's if x == uint_max { 0 } else { x }

@ykrivopalov
Copy link

This checks is already exist: x + 0; x * 1; x | 0. I'll add few more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

6 participants