Skip to content

Commit

Permalink
float_cmp: Change allow_named_constants to an allow list.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Jul 18, 2024
1 parent 72f8071 commit 63d5498
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ define_Conf! {
/// x == VALUE
/// }
/// ```
(float_cmp_ignore_named_constants: bool = true),
(float_cmp_allowed_constants: Vec<String> = true),
/// Lint: FLOAT_CMP
///
/// Whether to ignore comparisons which have a constant result.
Expand Down
11 changes: 8 additions & 3 deletions clippy_lints/src/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod verbose_bit_mask;
pub(crate) mod arithmetic_side_effects;

use clippy_config::Conf;
use clippy_utils::def_path_def_ids;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::{Body, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -774,9 +776,8 @@ declare_clippy_lint! {
"explicit self-assignment"
}

#[derive(Clone, Copy)]
struct FloatCmpConfig {
ignore_named_constants: bool,
allowed_constants: DefIdSet,
ignore_constant_comparisons: bool,
ignore_change_detection: bool,
}
Expand All @@ -794,7 +795,11 @@ impl Operators {
verbose_bit_mask_threshold: conf.verbose_bit_mask_threshold,
modulo_arithmetic_allow_comparison_to_zero: conf.allow_comparison_to_zero,
float_cmp_config: FloatCmpConfig {
ignore_named_constants: conf.float_cmp_ignore_named_constants,
allowed_constants: conf
.float_cmp_allowed_constants
.iter()
.flat_map(|x| def_path_def_ids(tcx, &x.split("::").collect::<Vec<_>>()))
.collect(),
ignore_constant_comparisons: conf.float_cmp_ignore_constant_comparisons,
ignore_change_detection: conf.float_cmp_ignore_change_detection,
},
Expand Down

0 comments on commit 63d5498

Please sign in to comment.