Skip to content

Commit 7f1405a

Browse files
committed
Fix float cmp to use assoc fxx::EPSILON
1 parent e7c9d64 commit 7f1405a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
388388
),
389389
Applicability::HasPlaceholders, // snippet
390390
);
391-
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
391+
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
392392
});
393393
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
394394
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");

tests/ui/float_cmp.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | ONE as f64 != 2.0;
55
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() > error`
66
|
77
= note: `-D clippy::float-cmp` implied by `-D warnings`
8-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
8+
note: `f32::EPSILON` and `f64::EPSILON` are available.
99
--> $DIR/float_cmp.rs:59:5
1010
|
1111
LL | ONE as f64 != 2.0;
@@ -17,7 +17,7 @@ error: strict comparison of `f32` or `f64`
1717
LL | x == 1.0;
1818
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error`
1919
|
20-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
20+
note: `f32::EPSILON` and `f64::EPSILON` are available.
2121
--> $DIR/float_cmp.rs:64:5
2222
|
2323
LL | x == 1.0;
@@ -29,7 +29,7 @@ error: strict comparison of `f32` or `f64`
2929
LL | twice(x) != twice(ONE as f64);
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error`
3131
|
32-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
32+
note: `f32::EPSILON` and `f64::EPSILON` are available.
3333
--> $DIR/float_cmp.rs:67:5
3434
|
3535
LL | twice(x) != twice(ONE as f64);

tests/ui/float_cmp_const.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | 1f32 == ONE;
55
| ^^^^^^^^^^^ help: consider comparing them within some error: `(1f32 - ONE).abs() < error`
66
|
77
= note: `-D clippy::float-cmp-const` implied by `-D warnings`
8-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
8+
note: `f32::EPSILON` and `f64::EPSILON` are available.
99
--> $DIR/float_cmp_const.rs:20:5
1010
|
1111
LL | 1f32 == ONE;
@@ -17,7 +17,7 @@ error: strict comparison of `f32` or `f64` constant
1717
LL | TWO == ONE;
1818
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error`
1919
|
20-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
20+
note: `f32::EPSILON` and `f64::EPSILON` are available.
2121
--> $DIR/float_cmp_const.rs:21:5
2222
|
2323
LL | TWO == ONE;
@@ -29,7 +29,7 @@ error: strict comparison of `f32` or `f64` constant
2929
LL | TWO != ONE;
3030
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error`
3131
|
32-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
32+
note: `f32::EPSILON` and `f64::EPSILON` are available.
3333
--> $DIR/float_cmp_const.rs:22:5
3434
|
3535
LL | TWO != ONE;
@@ -41,7 +41,7 @@ error: strict comparison of `f32` or `f64` constant
4141
LL | ONE + ONE == TWO;
4242
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error`
4343
|
44-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
44+
note: `f32::EPSILON` and `f64::EPSILON` are available.
4545
--> $DIR/float_cmp_const.rs:23:5
4646
|
4747
LL | ONE + ONE == TWO;
@@ -53,7 +53,7 @@ error: strict comparison of `f32` or `f64` constant
5353
LL | x as f32 == ONE;
5454
| ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error`
5555
|
56-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
56+
note: `f32::EPSILON` and `f64::EPSILON` are available.
5757
--> $DIR/float_cmp_const.rs:25:5
5858
|
5959
LL | x as f32 == ONE;
@@ -65,7 +65,7 @@ error: strict comparison of `f32` or `f64` constant
6565
LL | v == ONE;
6666
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error`
6767
|
68-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
68+
note: `f32::EPSILON` and `f64::EPSILON` are available.
6969
--> $DIR/float_cmp_const.rs:28:5
7070
|
7171
LL | v == ONE;
@@ -77,7 +77,7 @@ error: strict comparison of `f32` or `f64` constant
7777
LL | v != ONE;
7878
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error`
7979
|
80-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
80+
note: `f32::EPSILON` and `f64::EPSILON` are available.
8181
--> $DIR/float_cmp_const.rs:29:5
8282
|
8383
LL | v != ONE;

0 commit comments

Comments
 (0)