@@ -24,8 +24,11 @@ mod verbose_bit_mask;
2424pub ( crate ) mod arithmetic_side_effects;
2525
2626use clippy_config:: Conf ;
27+ use clippy_utils:: def_path_def_ids;
28+ use rustc_hir:: def_id:: DefIdSet ;
2729use rustc_hir:: { Body , Expr , ExprKind , UnOp } ;
2830use rustc_lint:: { LateContext , LateLintPass } ;
31+ use rustc_middle:: ty:: TyCtxt ;
2932use rustc_session:: impl_lint_pass;
3033
3134declare_clippy_lint ! {
@@ -774,9 +777,8 @@ declare_clippy_lint! {
774777 "explicit self-assignment"
775778}
776779
777- #[ derive( Clone , Copy ) ]
778780struct FloatCmpConfig {
779- ignore_named_constants : bool ,
781+ allowed_constants : DefIdSet ,
780782 ignore_constant_comparisons : bool ,
781783 ignore_change_detection : bool ,
782784}
@@ -788,13 +790,17 @@ pub struct Operators {
788790 float_cmp_config : FloatCmpConfig ,
789791}
790792impl Operators {
791- pub fn new ( conf : & ' static Conf ) -> Self {
793+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
792794 Self {
793795 arithmetic_context : numeric_arithmetic:: Context :: default ( ) ,
794796 verbose_bit_mask_threshold : conf. verbose_bit_mask_threshold ,
795797 modulo_arithmetic_allow_comparison_to_zero : conf. allow_comparison_to_zero ,
796798 float_cmp_config : FloatCmpConfig {
797- ignore_named_constants : conf. float_cmp_ignore_named_constants ,
799+ allowed_constants : conf
800+ . float_cmp_allowed_constants
801+ . iter ( )
802+ . flat_map ( |x| def_path_def_ids ( tcx, & x. split ( "::" ) . collect :: < Vec < _ > > ( ) ) )
803+ . collect ( ) ,
798804 ignore_constant_comparisons : conf. float_cmp_ignore_constant_comparisons ,
799805 ignore_change_detection : conf. float_cmp_ignore_change_detection ,
800806 } ,
@@ -854,7 +860,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
854860 float_equality_without_abs:: check ( cx, e, op. node , lhs, rhs) ;
855861 integer_division:: check ( cx, e, op. node , lhs, rhs) ;
856862 cmp_owned:: check ( cx, op. node , lhs, rhs) ;
857- float_cmp:: check ( cx, self . float_cmp_config , e, op. node , lhs, rhs) ;
863+ float_cmp:: check ( cx, & self . float_cmp_config , e, op. node , lhs, rhs) ;
858864 modulo_one:: check ( cx, e, op. node , rhs) ;
859865 modulo_arithmetic:: check (
860866 cx,
0 commit comments