Skip to content

Commit 4449cc7

Browse files
committed
Make the epsilon note spanless
1 parent 4e01ca3 commit 4449cc7

File tree

3 files changed

+16
-66
lines changed

3 files changed

+16
-66
lines changed

clippy_lints/src/misc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
378378
let lhs = Sugg::hir(cx, left, "..");
379379
let rhs = Sugg::hir(cx, right, "..");
380380

381-
if is_comparing_arrays {
382-
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
383-
} else {
381+
if !is_comparing_arrays {
384382
db.span_suggestion(
385383
expr.span,
386384
"consider comparing them within some error",
@@ -391,8 +389,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
391389
),
392390
Applicability::HasPlaceholders, // snippet
393391
);
394-
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
395392
}
393+
db.note("`f32::EPSILON` and `f64::EPSILON` are available for the `error`");
396394
});
397395
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
398396
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");

tests/ui/float_cmp.stderr

+6-26
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,47 @@ 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: `f32::EPSILON` and `f64::EPSILON` are available.
9-
--> $DIR/float_cmp.rs:65:5
10-
|
11-
LL | ONE as f64 != 2.0;
12-
| ^^^^^^^^^^^^^^^^^
8+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
139

1410
error: strict comparison of `f32` or `f64`
1511
--> $DIR/float_cmp.rs:70:5
1612
|
1713
LL | x == 1.0;
1814
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error`
1915
|
20-
note: `f32::EPSILON` and `f64::EPSILON` are available.
21-
--> $DIR/float_cmp.rs:70:5
22-
|
23-
LL | x == 1.0;
24-
| ^^^^^^^^
16+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
2517

2618
error: strict comparison of `f32` or `f64`
2719
--> $DIR/float_cmp.rs:73:5
2820
|
2921
LL | twice(x) != twice(ONE as f64);
3022
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error`
3123
|
32-
note: `f32::EPSILON` and `f64::EPSILON` are available.
33-
--> $DIR/float_cmp.rs:73:5
34-
|
35-
LL | twice(x) != twice(ONE as f64);
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
3725

3826
error: strict comparison of `f32` or `f64`
3927
--> $DIR/float_cmp.rs:93:5
4028
|
4129
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
4230
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error`
4331
|
44-
note: `f32::EPSILON` and `f64::EPSILON` are available.
45-
--> $DIR/float_cmp.rs:93:5
46-
|
47-
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
48-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
4933

5034
error: strict comparison of `f32` or `f64` arrays
5135
--> $DIR/float_cmp.rs:98:5
5236
|
5337
LL | a1 == a2;
5438
| ^^^^^^^^
5539
|
56-
= note: `f32::EPSILON` and `f64::EPSILON` are available.
40+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
5741

5842
error: strict comparison of `f32` or `f64`
5943
--> $DIR/float_cmp.rs:99:5
6044
|
6145
LL | a1[0] == a2[0];
6246
| ^^^^^^^^^^^^^^ help: consider comparing them within some error: `(a1[0] - a2[0]).abs() < error`
6347
|
64-
note: `f32::EPSILON` and `f64::EPSILON` are available.
65-
--> $DIR/float_cmp.rs:99:5
66-
|
67-
LL | a1[0] == a2[0];
68-
| ^^^^^^^^^^^^^^
48+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
6949

7050
error: aborting due to 6 previous errors
7151

tests/ui/float_cmp_const.stderr

+8-36
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,63 @@ 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: `f32::EPSILON` and `f64::EPSILON` are available.
9-
--> $DIR/float_cmp_const.rs:20:5
10-
|
11-
LL | 1f32 == ONE;
12-
| ^^^^^^^^^^^
8+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
139

1410
error: strict comparison of `f32` or `f64` constant
1511
--> $DIR/float_cmp_const.rs:21:5
1612
|
1713
LL | TWO == ONE;
1814
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error`
1915
|
20-
note: `f32::EPSILON` and `f64::EPSILON` are available.
21-
--> $DIR/float_cmp_const.rs:21:5
22-
|
23-
LL | TWO == ONE;
24-
| ^^^^^^^^^^
16+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
2517

2618
error: strict comparison of `f32` or `f64` constant
2719
--> $DIR/float_cmp_const.rs:22:5
2820
|
2921
LL | TWO != ONE;
3022
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error`
3123
|
32-
note: `f32::EPSILON` and `f64::EPSILON` are available.
33-
--> $DIR/float_cmp_const.rs:22:5
34-
|
35-
LL | TWO != ONE;
36-
| ^^^^^^^^^^
24+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
3725

3826
error: strict comparison of `f32` or `f64` constant
3927
--> $DIR/float_cmp_const.rs:23:5
4028
|
4129
LL | ONE + ONE == TWO;
4230
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error`
4331
|
44-
note: `f32::EPSILON` and `f64::EPSILON` are available.
45-
--> $DIR/float_cmp_const.rs:23:5
46-
|
47-
LL | ONE + ONE == TWO;
48-
| ^^^^^^^^^^^^^^^^
32+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
4933

5034
error: strict comparison of `f32` or `f64` constant
5135
--> $DIR/float_cmp_const.rs:25:5
5236
|
5337
LL | x as f32 == ONE;
5438
| ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error`
5539
|
56-
note: `f32::EPSILON` and `f64::EPSILON` are available.
57-
--> $DIR/float_cmp_const.rs:25:5
58-
|
59-
LL | x as f32 == ONE;
60-
| ^^^^^^^^^^^^^^^
40+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
6141

6242
error: strict comparison of `f32` or `f64` constant
6343
--> $DIR/float_cmp_const.rs:28:5
6444
|
6545
LL | v == ONE;
6646
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error`
6747
|
68-
note: `f32::EPSILON` and `f64::EPSILON` are available.
69-
--> $DIR/float_cmp_const.rs:28:5
70-
|
71-
LL | v == ONE;
72-
| ^^^^^^^^
48+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
7349

7450
error: strict comparison of `f32` or `f64` constant
7551
--> $DIR/float_cmp_const.rs:29:5
7652
|
7753
LL | v != ONE;
7854
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error`
7955
|
80-
note: `f32::EPSILON` and `f64::EPSILON` are available.
81-
--> $DIR/float_cmp_const.rs:29:5
82-
|
83-
LL | v != ONE;
84-
| ^^^^^^^^
56+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
8557

8658
error: strict comparison of `f32` or `f64` constant arrays
8759
--> $DIR/float_cmp_const.rs:61:5
8860
|
8961
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
9062
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9163
|
92-
= note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
64+
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
9365

9466
error: aborting due to 8 previous errors
9567

0 commit comments

Comments
 (0)