1- use super :: { FLOAT_ARITHMETIC , INTEGER_ARITHMETIC } ;
1+ use super :: FLOAT_ARITHMETIC ;
22use clippy_utils:: consts:: constant_simple;
33use clippy_utils:: diagnostics:: span_lint;
4- use clippy_utils:: is_from_proc_macro;
5- use clippy_utils:: is_integer_literal;
64use rustc_hir as hir;
75use rustc_lint:: LateContext ;
86use rustc_span:: source_map:: Span ;
@@ -45,31 +43,8 @@ impl Context {
4543 _ => ( ) ,
4644 }
4745
48- let ( l_ty, r_ty) = ( cx. typeck_results ( ) . expr_ty ( l) , cx. typeck_results ( ) . expr_ty ( r) ) ;
49- if l_ty. peel_refs ( ) . is_integral ( ) && r_ty. peel_refs ( ) . is_integral ( ) {
50- if is_from_proc_macro ( cx, expr) {
51- return ;
52- }
53- match op {
54- hir:: BinOpKind :: Div | hir:: BinOpKind :: Rem => match & r. kind {
55- hir:: ExprKind :: Lit ( _lit) => ( ) ,
56- hir:: ExprKind :: Unary ( hir:: UnOp :: Neg , expr) => {
57- if is_integer_literal ( expr, 1 ) {
58- span_lint ( cx, INTEGER_ARITHMETIC , expr. span , "integer arithmetic detected" ) ;
59- self . expr_id = Some ( expr. hir_id ) ;
60- }
61- } ,
62- _ => {
63- span_lint ( cx, INTEGER_ARITHMETIC , expr. span , "integer arithmetic detected" ) ;
64- self . expr_id = Some ( expr. hir_id ) ;
65- } ,
66- } ,
67- _ => {
68- span_lint ( cx, INTEGER_ARITHMETIC , expr. span , "integer arithmetic detected" ) ;
69- self . expr_id = Some ( expr. hir_id ) ;
70- } ,
71- }
72- } else if r_ty. peel_refs ( ) . is_floating_point ( ) && r_ty. peel_refs ( ) . is_floating_point ( ) {
46+ let ( _, r_ty) = ( cx. typeck_results ( ) . expr_ty ( l) , cx. typeck_results ( ) . expr_ty ( r) ) ;
47+ if r_ty. peel_refs ( ) . is_floating_point ( ) && r_ty. peel_refs ( ) . is_floating_point ( ) {
7348 span_lint ( cx, FLOAT_ARITHMETIC , expr. span , "floating-point arithmetic detected" ) ;
7449 self . expr_id = Some ( expr. hir_id ) ;
7550 }
@@ -80,17 +55,9 @@ impl Context {
8055 return ;
8156 }
8257 let ty = cx. typeck_results ( ) . expr_ty ( arg) ;
83- if constant_simple ( cx, cx. typeck_results ( ) , expr) . is_none ( ) {
84- if ty. is_integral ( ) {
85- if is_from_proc_macro ( cx, expr) {
86- return ;
87- }
88- span_lint ( cx, INTEGER_ARITHMETIC , expr. span , "integer arithmetic detected" ) ;
89- self . expr_id = Some ( expr. hir_id ) ;
90- } else if ty. is_floating_point ( ) {
91- span_lint ( cx, FLOAT_ARITHMETIC , expr. span , "floating-point arithmetic detected" ) ;
92- self . expr_id = Some ( expr. hir_id ) ;
93- }
58+ if constant_simple ( cx, cx. typeck_results ( ) , expr) . is_none ( ) && ty. is_floating_point ( ) {
59+ span_lint ( cx, FLOAT_ARITHMETIC , expr. span , "floating-point arithmetic detected" ) ;
60+ self . expr_id = Some ( expr. hir_id ) ;
9461 }
9562 }
9663
0 commit comments