Skip to content

Commit 63d5498

Browse files
committed
float_cmp: Change allow_named_constants to an allow list.
1 parent 72f8071 commit 63d5498

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

clippy_config/src/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ define_Conf! {
657657
/// x == VALUE
658658
/// }
659659
/// ```
660-
(float_cmp_ignore_named_constants: bool = true),
660+
(float_cmp_allowed_constants: Vec<String> = true),
661661
/// Lint: FLOAT_CMP
662662
///
663663
/// Whether to ignore comparisons which have a constant result.

clippy_lints/src/operators/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ mod verbose_bit_mask;
2424
pub(crate) mod arithmetic_side_effects;
2525

2626
use clippy_config::Conf;
27+
use clippy_utils::def_path_def_ids;
28+
use rustc_hir::def_id::DefIdSet;
2729
use rustc_hir::{Body, Expr, ExprKind, UnOp};
2830
use rustc_lint::{LateContext, LateLintPass};
2931
use rustc_session::impl_lint_pass;
@@ -774,9 +776,8 @@ declare_clippy_lint! {
774776
"explicit self-assignment"
775777
}
776778

777-
#[derive(Clone, Copy)]
778779
struct FloatCmpConfig {
779-
ignore_named_constants: bool,
780+
allowed_constants: DefIdSet,
780781
ignore_constant_comparisons: bool,
781782
ignore_change_detection: bool,
782783
}
@@ -794,7 +795,11 @@ impl Operators {
794795
verbose_bit_mask_threshold: conf.verbose_bit_mask_threshold,
795796
modulo_arithmetic_allow_comparison_to_zero: conf.allow_comparison_to_zero,
796797
float_cmp_config: FloatCmpConfig {
797-
ignore_named_constants: conf.float_cmp_ignore_named_constants,
798+
allowed_constants: conf
799+
.float_cmp_allowed_constants
800+
.iter()
801+
.flat_map(|x| def_path_def_ids(tcx, &x.split("::").collect::<Vec<_>>()))
802+
.collect(),
798803
ignore_constant_comparisons: conf.float_cmp_ignore_constant_comparisons,
799804
ignore_change_detection: conf.float_cmp_ignore_change_detection,
800805
},

0 commit comments

Comments
 (0)