@@ -24,8 +24,11 @@ mod verbose_bit_mask;
24
24
pub ( crate ) mod arithmetic_side_effects;
25
25
26
26
use clippy_config:: Conf ;
27
+ use clippy_utils:: def_path_def_ids;
28
+ use rustc_hir:: def_id:: DefIdSet ;
27
29
use rustc_hir:: { Body , Expr , ExprKind , UnOp } ;
28
30
use rustc_lint:: { LateContext , LateLintPass } ;
31
+ use rustc_middle:: ty:: TyCtxt ;
29
32
use rustc_session:: impl_lint_pass;
30
33
31
34
declare_clippy_lint ! {
@@ -774,9 +777,8 @@ declare_clippy_lint! {
774
777
"explicit self-assignment"
775
778
}
776
779
777
- #[ derive( Clone , Copy ) ]
778
780
struct FloatCmpConfig {
779
- ignore_named_constants : bool ,
781
+ allowed_constants : DefIdSet ,
780
782
ignore_constant_comparisons : bool ,
781
783
ignore_change_detection : bool ,
782
784
}
@@ -788,13 +790,17 @@ pub struct Operators {
788
790
float_cmp_config : FloatCmpConfig ,
789
791
}
790
792
impl Operators {
791
- pub fn new ( conf : & ' static Conf ) -> Self {
793
+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
792
794
Self {
793
795
arithmetic_context : numeric_arithmetic:: Context :: default ( ) ,
794
796
verbose_bit_mask_threshold : conf. verbose_bit_mask_threshold ,
795
797
modulo_arithmetic_allow_comparison_to_zero : conf. allow_comparison_to_zero ,
796
798
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 ( ) ,
798
804
ignore_constant_comparisons : conf. float_cmp_ignore_constant_comparisons ,
799
805
ignore_change_detection : conf. float_cmp_ignore_change_detection ,
800
806
} ,
@@ -854,7 +860,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
854
860
float_equality_without_abs:: check ( cx, e, op. node , lhs, rhs) ;
855
861
integer_division:: check ( cx, e, op. node , lhs, rhs) ;
856
862
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) ;
858
864
modulo_one:: check ( cx, e, op. node , rhs) ;
859
865
modulo_arithmetic:: check (
860
866
cx,
0 commit comments