1+ use super :: { FLOAT_ARITHMETIC , INTEGER_ARITHMETIC } ;
12use clippy_utils:: consts:: constant_simple;
23use clippy_utils:: diagnostics:: span_lint;
4+ use clippy_utils:: is_from_proc_macro;
35use clippy_utils:: is_integer_literal;
46use rustc_hir as hir;
57use rustc_lint:: LateContext ;
68use rustc_span:: source_map:: Span ;
79
8- use super :: { FLOAT_ARITHMETIC , INTEGER_ARITHMETIC } ;
9-
1010#[ derive( Default ) ]
1111pub struct Context {
1212 expr_id : Option < hir:: HirId > ,
@@ -19,6 +19,10 @@ impl Context {
1919 self . expr_id . is_some ( ) || self . const_span . map_or ( false , |span| span. contains ( e. span ) )
2020 }
2121
22+ fn skip_expr_involving_integers < ' tcx > ( cx : & LateContext < ' tcx > , e : & hir:: Expr < ' tcx > ) -> bool {
23+ is_from_proc_macro ( cx, e)
24+ }
25+
2226 pub fn check_binary < ' tcx > (
2327 & mut self ,
2428 cx : & LateContext < ' tcx > ,
@@ -47,6 +51,9 @@ impl Context {
4751
4852 let ( l_ty, r_ty) = ( cx. typeck_results ( ) . expr_ty ( l) , cx. typeck_results ( ) . expr_ty ( r) ) ;
4953 if l_ty. peel_refs ( ) . is_integral ( ) && r_ty. peel_refs ( ) . is_integral ( ) {
54+ if Self :: skip_expr_involving_integers ( cx, expr) {
55+ return ;
56+ }
5057 match op {
5158 hir:: BinOpKind :: Div | hir:: BinOpKind :: Rem => match & r. kind {
5259 hir:: ExprKind :: Lit ( _lit) => ( ) ,
@@ -79,6 +86,9 @@ impl Context {
7986 let ty = cx. typeck_results ( ) . expr_ty ( arg) ;
8087 if constant_simple ( cx, cx. typeck_results ( ) , expr) . is_none ( ) {
8188 if ty. is_integral ( ) {
89+ if Self :: skip_expr_involving_integers ( cx, expr) {
90+ return ;
91+ }
8292 span_lint ( cx, INTEGER_ARITHMETIC , expr. span , "integer arithmetic detected" ) ;
8393 self . expr_id = Some ( expr. hir_id ) ;
8494 } else if ty. is_floating_point ( ) {
0 commit comments