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

Checking for (integer) constants in lints is inconsistent and does not handle all cases (e.g., static constants) #6365

Open
mlegner opened this issue Nov 22, 2020 · 2 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience.

Comments

@mlegner
Copy link
Contributor

mlegner commented Nov 22, 2020

Several lints such as the integer_arithmetic and modulo_one lint check for specific integer constants, typically +/-1, 0, MIN, MAX. However, this is currently implemented inconsistently, sometimes only checking for (+/-) literals (integer_arithmetic, see also #6209), sometimes also for constants (modulo_one). However, the modulo_one lint also fails to properly handle static constants (see also #6360); I am not sure, if this is due to some deeper reason I don't yet understand or if this is simply a bug.

I would suggest consolidating these checks for particular values to rely on a single constant-comparison function similar to (or replacing) the is_integer_const function, but also handling static constants. Likely, this could be used in other places as well.

@giraffate
Copy link
Contributor

@rustbot modify labels: +L-enhancement

@rustbot rustbot added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Nov 22, 2020
@flip1995 flip1995 added the E-medium Call for participation: Medium difficulty level problem and requires some initial experience. label Dec 6, 2020
@c410-f3r
Copy link
Contributor

arithmetic_side_effects does not suffer from this issue

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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience.
Projects
None yet
Development

No branches or pull requests

5 participants