-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Downgrade integer_division to restriction #4210
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
Conversation
I feel like there needs to be more justification for this. But I'm largely okay with this. |
The lint's justification is:
I question whether there is evidence that this is "very often" the case. Out of the number of times that integer division has been used in Rust, what fraction of them were mistakes that should have used float division instead? Less than 1%? I have no problem with it as a restriction for someone who consciously decides they want to avoid integer division in their code. |
error: integer division
--> $DIR/integer_division.rs:7:13
|
7 | let p = a / b;
| ^^^^^
|
= help: division of integers may cause loss of precision. consider using floats. Consider whether pushing people to use float division will fix more problems than it solves. In reality, using unnecessary float division instead of integer division is what often causes loss of precision. fn main() {
let numerator: u32 = 12_345_678 * 3;
let denominator = 3;
println!("integer quotient: {}", numerator / denominator);
println!("float quotient: {}", numerator as f32 / denominator as f32);
} integer quotient: 12345678
float quotient: 12345677 The integer quotient is exactly correct while the float quotient loses precision. This lint seems intended to help people who don't yet have a firm grasp of the difference between integer and float, but I think it will do more harm than good for that group. |
This lint will have 99% false positive rate. (It triggers on all integer division which means every instance of integer division is either a bug or a false positive.) In its current form, it's just going to annoy people. It would be great if we could move this to restriction before 1.36 is released. |
@bors r+ |
📌 Commit f88a387 has been approved by |
Downgrade integer_division to restriction I believe that this lint falls outside of the scope of opinionated pedantism of the other pedantic lints. changelog: Downgrade integer_division lint from pedantic to restriction
☀️ Test successful - checks-travis, status-appveyor |
I believe that this lint falls outside of the scope of opinionated pedantism of the other pedantic lints.
changelog: Downgrade integer_division lint from pedantic to restriction