Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c891082

Browse files
committed
[Clippy] Swap float_equality_without_abs to use diagnostic items instead of paths
1 parent 5e47168 commit c891082

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ symbols! {
838838
f16_nan,
839839
f16c_target_feature,
840840
f32,
841+
f32_epsilon,
841842
f32_legacy_const_digits,
842843
f32_legacy_const_epsilon,
843844
f32_legacy_const_infinity,
@@ -854,6 +855,7 @@ symbols! {
854855
f32_legacy_const_radix,
855856
f32_nan,
856857
f64,
858+
f64_epsilon,
857859
f64_legacy_const_digits,
858860
f64_legacy_const_epsilon,
859861
f64_legacy_const_infinity,

library/core/src/num/f32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ impl f32 {
415415
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
416416
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
417417
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
418+
#[cfg_attr(not(test), rustc_diagnostic_item = "f32_epsilon")]
418419
pub const EPSILON: f32 = 1.19209290e-07_f32;
419420

420421
/// Smallest finite `f32` value.

library/core/src/num/f64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl f64 {
414414
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
415415
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
416416
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
417+
#[cfg_attr(not(test), rustc_diagnostic_item = "f64_epsilon")]
417418
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
418419

419420
/// Smallest finite `f64` value.

src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::{match_def_path, paths, sugg};
2+
use clippy_utils::sugg;
33
use rustc_ast::util::parser::AssocOp;
44
use rustc_errors::Applicability;
55
use rustc_hir::def::{DefKind, Res};
66
use rustc_hir::{BinOpKind, Expr, ExprKind};
77
use rustc_lint::LateContext;
88
use rustc_middle::ty;
9-
use rustc_span::source_map::Spanned;
9+
use rustc_span::{sym, source_map::Spanned};
1010

1111
use super::FLOAT_EQUALITY_WITHOUT_ABS;
1212

@@ -36,7 +36,7 @@ pub(crate) fn check<'tcx>(
3636
// right hand side matches either f32::EPSILON or f64::EPSILON
3737
&& let ExprKind::Path(ref epsilon_path) = rhs.kind
3838
&& let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id)
39-
&& (match_def_path(cx, def_id, &paths::F32_EPSILON) || match_def_path(cx, def_id, &paths::F64_EPSILON))
39+
&& ([sym::f32_epsilon, sym::f64_epsilon].into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, def_id)))
4040

4141
// values of the subtractions on the left hand side are of the type float
4242
&& let t_val_l = cx.typeck_results().expr_ty(val_l)

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1414
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
1515
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
1616
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
17-
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
18-
pub const F64_EPSILON: [&str; 4] = ["core", "f64", "<impl f64>", "EPSILON"];
1917
pub const FILE_OPTIONS: [&str; 4] = ["std", "fs", "File", "options"];
2018
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
2119
pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];

0 commit comments

Comments
 (0)