-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 for warning on division of integer literals #109
Comments
Also, personally I'd like a lint for any integer division as well (not just literals). When I'm working on an application that specifically uses floating point numbers, every integer division I've done has been a bug. |
That's pretty easy – we already can get the (given or inferred) type of any expr using However, it's pretty easy to get around it, e.g. |
-1 on a lint for all integer division. I use it quite often, and would hate to add boilerplate just to get around a lint. I support a lint for literals, but I could see something like 1000/7 being more understandable than 142. |
That's pretty much what I think – the compiler cannot detect your intent, and there are many algorithms where integer division is intentional. |
I would like the lint to be off by default. There are only certain times I On Sat, Jul 11, 2015, 12:59 PM llogiq notifications@github.com wrote:
|
Also, I'd prefer On Sat, Jul 11, 2015, 2:06 PM Gulshan Singh gsingh_2011@yahoo.com wrote:
|
I also think this should not lint. Integer division used to be pretty confusing e.g. in Python because of dynamic typing, but in Rust it should be pretty much unneeded. |
I really don't see the problem with making this a lint that is off by default. I don't want this everywhere, just like everyone else. However, I've written multiple applications that have been very heavy on floating point divisions where I would have like to enable this feature. In these applications, not a single integer division was valid, but I accidentally made this mistake multiple times. |
In what language did you write those applications? |
FWIW I don't think there should be a high bar for inclusion of Allow lints in clippy 😄 |
Full ack. |
@llogiq Yes. Here's a small example of an integer division bug:
Obviously, not every application that needs to calculate the aspect ratio would enable this lint, but there are certain applications where I'd know ahead of time this lint would be useful. In the rare cases where I'd be wrong about the lint being useful, I'd disable it, possibly just for a particular function. |
Oops, I only meant to scale the x coordinate in the last example. Irrelevant to the example, but just in case someone calls me out on that later. |
Is this still relevant? I'd like to work on it if so. |
yes, we still want that, albeit as |
It would be nice to warn the user if they wrote an expression like
1/2
and meant0.5
. There is also an open issue for this in Rust: rust-lang/rust#21737The text was updated successfully, but these errors were encountered: