@@ -2,7 +2,6 @@ use clippy_utils::consts::{constant_full_int, FullInt};
22use clippy_utils:: diagnostics:: span_lint_and_sugg;
33use clippy_utils:: source:: snippet_with_applicability;
44use clippy_utils:: { meets_msrv, msrvs, path_to_local} ;
5- use if_chain:: if_chain;
65use rustc_errors:: Applicability ;
76use rustc_hir:: { BinOpKind , Expr , ExprKind , Node , TyKind } ;
87use rustc_lint:: { LateContext , LateLintPass } ;
@@ -52,26 +51,22 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
5251 return ;
5352 }
5453
55- if_chain ! {
56- if let ExprKind :: Binary ( op1, ..) = expr. kind;
57- if op1. node == BinOpKind :: Rem ;
58- if let Some ( ( const1, expr1) ) = check_for_positive_int_constant( cx, expr, false ) ;
59- if let ExprKind :: Binary ( op2, ..) = expr1. kind;
60- if op2. node == BinOpKind :: Add ;
61- if let Some ( ( const2, expr2) ) = check_for_positive_int_constant( cx, expr1, true ) ;
62- if let ExprKind :: Binary ( op3, ..) = expr2. kind;
63- if op3. node == BinOpKind :: Rem ;
64- if let Some ( ( const3, expr3) ) = check_for_positive_int_constant( cx, expr2, false ) ;
65- if const1 == const2 && const2 == const3;
54+ if let ExprKind :: Binary ( op1, ..) = expr. kind
55+ && op1. node == BinOpKind :: Rem
56+ && let Some ( ( const1, expr1) ) = check_for_positive_int_constant ( cx, expr, false )
57+ && let ExprKind :: Binary ( op2, ..) = expr1. kind
58+ && op2. node == BinOpKind :: Add
59+ && let Some ( ( const2, expr2) ) = check_for_positive_int_constant ( cx, expr1, true )
60+ && let ExprKind :: Binary ( op3, ..) = expr2. kind
61+ && op3. node == BinOpKind :: Rem
62+ && let Some ( ( const3, expr3) ) = check_for_positive_int_constant ( cx, expr2, false )
63+ && const1 == const2 && const2 == const3
6664 // Only apply if we see an explicit type annotation on the local.
67- if let Some ( hir_id) = path_to_local( expr3) ;
68- let hir = cx. tcx. hir( ) ;
69- if let Some ( Node :: Binding ( _) ) = hir. find( hir_id) ;
70- let parent = hir. get_parent_node( hir_id) ;
71- if let Some ( Node :: Local ( local) ) = hir. find( parent) ;
72- if let Some ( ty) = local. ty;
73- if !matches!( ty. kind, TyKind :: Infer ) ;
74- then {
65+ && let Some ( hir_id) = path_to_local ( expr3)
66+ && let Some ( Node :: Binding ( _) ) = cx. tcx . hir ( ) . find ( hir_id)
67+ && let Some ( Node :: Local ( local) ) = cx. tcx . hir ( ) . find ( cx. tcx . hir ( ) . get_parent_node ( hir_id) )
68+ && let Some ( ty) = local. ty
69+ && !matches ! ( ty. kind, TyKind :: Infer ) {
7570 let mut app = Applicability :: MachineApplicable ;
7671 let rem_of = snippet_with_applicability ( cx, expr3. span , "_" , & mut app) ;
7772 span_lint_and_sugg (
@@ -83,7 +78,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
8378 format ! ( "{rem_of}.rem_euclid({const1})" ) ,
8479 app,
8580 ) ;
86- }
8781 }
8882 }
8983
0 commit comments