forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#5345 - Toxyxer:add-lint-for-float-in-array-co…
…mparison, r=flip1995 Add lint for float in array comparison Fixes rust-lang#4277 changelog: - Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal. - Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities. - Added appropriate tests for such cases.
- Loading branch information
Showing
6 changed files
with
200 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
error: strict comparison of `f32` or `f64` | ||
--> $DIR/float_cmp.rs:59:5 | ||
--> $DIR/float_cmp.rs:65:5 | ||
| | ||
LL | ONE as f64 != 2.0; | ||
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() > error` | ||
| | ||
= note: `-D clippy::float-cmp` implied by `-D warnings` | ||
note: `f32::EPSILON` and `f64::EPSILON` are available. | ||
--> $DIR/float_cmp.rs:59:5 | ||
| | ||
LL | ONE as f64 != 2.0; | ||
| ^^^^^^^^^^^^^^^^^ | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: strict comparison of `f32` or `f64` | ||
--> $DIR/float_cmp.rs:64:5 | ||
--> $DIR/float_cmp.rs:70:5 | ||
| | ||
LL | x == 1.0; | ||
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error` | ||
| | ||
note: `f32::EPSILON` and `f64::EPSILON` are available. | ||
--> $DIR/float_cmp.rs:64:5 | ||
| | ||
LL | x == 1.0; | ||
| ^^^^^^^^ | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: strict comparison of `f32` or `f64` | ||
--> $DIR/float_cmp.rs:67:5 | ||
--> $DIR/float_cmp.rs:73:5 | ||
| | ||
LL | twice(x) != twice(ONE as f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error` | ||
| | ||
note: `f32::EPSILON` and `f64::EPSILON` are available. | ||
--> $DIR/float_cmp.rs:67:5 | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: strict comparison of `f32` or `f64` | ||
--> $DIR/float_cmp.rs:93:5 | ||
| | ||
LL | twice(x) != twice(ONE as f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error` | ||
| | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: strict comparison of `f32` or `f64` arrays | ||
--> $DIR/float_cmp.rs:98:5 | ||
| | ||
LL | a1 == a2; | ||
| ^^^^^^^^ | ||
| | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: strict comparison of `f32` or `f64` | ||
--> $DIR/float_cmp.rs:99:5 | ||
| | ||
LL | a1[0] == a2[0]; | ||
| ^^^^^^^^^^^^^^ help: consider comparing them within some error: `(a1[0] - a2[0]).abs() < error` | ||
| | ||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error` | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.