Make the epsilon note spanless
This commit is contained in:
parent
4e01ca35a0
commit
4449cc799b
@ -378,9 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||||||
let lhs = Sugg::hir(cx, left, "..");
|
let lhs = Sugg::hir(cx, left, "..");
|
||||||
let rhs = Sugg::hir(cx, right, "..");
|
let rhs = Sugg::hir(cx, right, "..");
|
||||||
|
|
||||||
if is_comparing_arrays {
|
if !is_comparing_arrays {
|
||||||
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
|
|
||||||
} else {
|
|
||||||
db.span_suggestion(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"consider comparing them within some error",
|
"consider comparing them within some error",
|
||||||
@ -391,8 +389,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||||||
),
|
),
|
||||||
Applicability::HasPlaceholders, // snippet
|
Applicability::HasPlaceholders, // snippet
|
||||||
);
|
);
|
||||||
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
|
|
||||||
}
|
}
|
||||||
|
db.note("`f32::EPSILON` and `f64::EPSILON` are available for the `error`");
|
||||||
});
|
});
|
||||||
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
|
} 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");
|
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
|
||||||
|
@ -5,11 +5,7 @@ LL | ONE as f64 != 2.0;
|
|||||||
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() > error`
|
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE as f64 - 2.0).abs() > error`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::float-cmp` implied by `-D warnings`
|
= note: `-D clippy::float-cmp` implied by `-D warnings`
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp.rs:65:5
|
|
||||||
|
|
|
||||||
LL | ONE as f64 != 2.0;
|
|
||||||
| ^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64`
|
error: strict comparison of `f32` or `f64`
|
||||||
--> $DIR/float_cmp.rs:70:5
|
--> $DIR/float_cmp.rs:70:5
|
||||||
@ -17,11 +13,7 @@ error: strict comparison of `f32` or `f64`
|
|||||||
LL | x == 1.0;
|
LL | x == 1.0;
|
||||||
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error`
|
| ^^^^^^^^ help: consider comparing them within some error: `(x - 1.0).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp.rs:70:5
|
|
||||||
|
|
|
||||||
LL | x == 1.0;
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64`
|
error: strict comparison of `f32` or `f64`
|
||||||
--> $DIR/float_cmp.rs:73:5
|
--> $DIR/float_cmp.rs:73:5
|
||||||
@ -29,11 +21,7 @@ error: strict comparison of `f32` or `f64`
|
|||||||
LL | twice(x) != twice(ONE as f64);
|
LL | twice(x) != twice(ONE as f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(twice(x) - twice(ONE as f64)).abs() > error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp.rs:73:5
|
|
||||||
|
|
|
||||||
LL | twice(x) != twice(ONE as f64);
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64`
|
error: strict comparison of `f32` or `f64`
|
||||||
--> $DIR/float_cmp.rs:93:5
|
--> $DIR/float_cmp.rs:93:5
|
||||||
@ -41,11 +29,7 @@ error: strict comparison of `f32` or `f64`
|
|||||||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
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`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp.rs:93:5
|
|
||||||
|
|
|
||||||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` arrays
|
error: strict comparison of `f32` or `f64` arrays
|
||||||
--> $DIR/float_cmp.rs:98:5
|
--> $DIR/float_cmp.rs:98:5
|
||||||
@ -53,7 +37,7 @@ error: strict comparison of `f32` or `f64` arrays
|
|||||||
LL | a1 == a2;
|
LL | a1 == a2;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64`
|
error: strict comparison of `f32` or `f64`
|
||||||
--> $DIR/float_cmp.rs:99:5
|
--> $DIR/float_cmp.rs:99:5
|
||||||
@ -61,11 +45,7 @@ error: strict comparison of `f32` or `f64`
|
|||||||
LL | a1[0] == a2[0];
|
LL | a1[0] == a2[0];
|
||||||
| ^^^^^^^^^^^^^^ help: consider comparing them within some error: `(a1[0] - a2[0]).abs() < error`
|
| ^^^^^^^^^^^^^^ help: consider comparing them within some error: `(a1[0] - a2[0]).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp.rs:99:5
|
|
||||||
|
|
|
||||||
LL | a1[0] == a2[0];
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
@ -5,11 +5,7 @@ LL | 1f32 == ONE;
|
|||||||
| ^^^^^^^^^^^ help: consider comparing them within some error: `(1f32 - ONE).abs() < error`
|
| ^^^^^^^^^^^ help: consider comparing them within some error: `(1f32 - ONE).abs() < error`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::float-cmp-const` implied by `-D warnings`
|
= note: `-D clippy::float-cmp-const` implied by `-D warnings`
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:20:5
|
|
||||||
|
|
|
||||||
LL | 1f32 == ONE;
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:21:5
|
--> $DIR/float_cmp_const.rs:21:5
|
||||||
@ -17,11 +13,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | TWO == ONE;
|
LL | TWO == ONE;
|
||||||
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error`
|
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:21:5
|
|
||||||
|
|
|
||||||
LL | TWO == ONE;
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:22:5
|
--> $DIR/float_cmp_const.rs:22:5
|
||||||
@ -29,11 +21,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | TWO != ONE;
|
LL | TWO != ONE;
|
||||||
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error`
|
| ^^^^^^^^^^ help: consider comparing them within some error: `(TWO - ONE).abs() > error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:22:5
|
|
||||||
|
|
|
||||||
LL | TWO != ONE;
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:23:5
|
--> $DIR/float_cmp_const.rs:23:5
|
||||||
@ -41,11 +29,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | ONE + ONE == TWO;
|
LL | ONE + ONE == TWO;
|
||||||
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error`
|
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(ONE + ONE - TWO).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:23:5
|
|
||||||
|
|
|
||||||
LL | ONE + ONE == TWO;
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:25:5
|
--> $DIR/float_cmp_const.rs:25:5
|
||||||
@ -53,11 +37,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | x as f32 == ONE;
|
LL | x as f32 == ONE;
|
||||||
| ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error`
|
| ^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(x as f32 - ONE).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:25:5
|
|
||||||
|
|
|
||||||
LL | x as f32 == ONE;
|
|
||||||
| ^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:28:5
|
--> $DIR/float_cmp_const.rs:28:5
|
||||||
@ -65,11 +45,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | v == ONE;
|
LL | v == ONE;
|
||||||
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error`
|
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() < error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:28:5
|
|
||||||
|
|
|
||||||
LL | v == ONE;
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant
|
error: strict comparison of `f32` or `f64` constant
|
||||||
--> $DIR/float_cmp_const.rs:29:5
|
--> $DIR/float_cmp_const.rs:29:5
|
||||||
@ -77,11 +53,7 @@ error: strict comparison of `f32` or `f64` constant
|
|||||||
LL | v != ONE;
|
LL | v != ONE;
|
||||||
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error`
|
| ^^^^^^^^ help: consider comparing them within some error: `(v - ONE).abs() > error`
|
||||||
|
|
|
|
||||||
note: `f32::EPSILON` and `f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
--> $DIR/float_cmp_const.rs:29:5
|
|
||||||
|
|
|
||||||
LL | v != ONE;
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
||||||
error: strict comparison of `f32` or `f64` constant arrays
|
error: strict comparison of `f32` or `f64` constant arrays
|
||||||
--> $DIR/float_cmp_const.rs:61:5
|
--> $DIR/float_cmp_const.rs:61:5
|
||||||
@ -89,7 +61,7 @@ error: strict comparison of `f32` or `f64` constant arrays
|
|||||||
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
|
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
|
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error`
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user