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

Use assoc int and float consts instead of module level ones #5429

Merged
merged 8 commits into from
Apr 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix float cmp to use assoc fxx::EPSILON
  • Loading branch information
faern committed Apr 7, 2020
commit 645b62e436fb5beb2cb03b646ae5d92fd13baecd
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
@@ -388,7 +388,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
),
Applicability::HasPlaceholders, // snippet
);
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
});
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
6 changes: 3 additions & 3 deletions tests/ui/float_cmp.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ 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: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp.rs:59:5
|
LL | ONE as f64 != 2.0;
@@ -17,7 +17,7 @@ error: strict comparison of `f32` or `f64`
LL | x == 1.0;
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp.rs:64:5
|
LL | x == 1.0;
@@ -29,7 +29,7 @@ error: strict comparison of `f32` or `f64`
LL | twice(x) != twice(ONE as f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp.rs:67:5
|
LL | twice(x) != twice(ONE as f64);
14 changes: 7 additions & 7 deletions tests/ui/float_cmp_const.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ LL | 1f32 == ONE;
| ^^^^^^^^^^^ help: consider comparing them within some error: `(1f32 - ONE).abs() < error`
|
= note: `-D clippy::float-cmp-const` implied by `-D warnings`
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:20:5
|
LL | 1f32 == ONE;
@@ -17,7 +17,7 @@ error: strict comparison of `f32` or `f64` constant
LL | TWO == ONE;
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:21:5
|
LL | TWO == ONE;
@@ -29,7 +29,7 @@ error: strict comparison of `f32` or `f64` constant
LL | TWO != ONE;
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:22:5
|
LL | TWO != ONE;
@@ -41,7 +41,7 @@ error: strict comparison of `f32` or `f64` constant
LL | ONE + ONE == TWO;
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:23:5
|
LL | ONE + ONE == TWO;
@@ -53,7 +53,7 @@ error: strict comparison of `f32` or `f64` constant
LL | x as f32 == ONE;
| ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:25:5
|
LL | x as f32 == ONE;
@@ -65,7 +65,7 @@ error: strict comparison of `f32` or `f64` constant
LL | v == ONE;
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:28:5
|
LL | v == ONE;
@@ -77,7 +77,7 @@ error: strict comparison of `f32` or `f64` constant
LL | v != ONE;
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error`
|
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
note: `f32::EPSILON` and `f64::EPSILON` are available.
--> $DIR/float_cmp_const.rs:29:5
|
LL | v != ONE;