@@ -107,9 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
107107 } ) = higher:: If :: hir ( expr)
108108 && let ExprKind :: Binary ( ref cond_op, cond_left, cond_right) = cond. kind
109109 {
110- check_manual_check (
111- cx, expr, cond_op, cond_left, cond_right, if_block, else_block, & self . msrv ,
112- ) ;
110+ check_manual_check ( cx, cond_op, cond_left, cond_right, if_block, else_block, & self . msrv ) ;
113111 }
114112 }
115113
@@ -119,7 +117,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
119117#[ allow( clippy:: too_many_arguments) ]
120118fn check_manual_check < ' tcx > (
121119 cx : & LateContext < ' tcx > ,
122- expr : & Expr < ' tcx > ,
123120 condition : & BinOp ,
124121 left_hand : & Expr < ' tcx > ,
125122 right_hand : & Expr < ' tcx > ,
@@ -130,26 +127,12 @@ fn check_manual_check<'tcx>(
130127 let ty = cx. typeck_results ( ) . expr_ty ( left_hand) ;
131128 if ty. is_numeric ( ) && !ty. is_signed ( ) {
132129 match condition. node {
133- BinOpKind :: Gt | BinOpKind :: Ge => check_gt (
134- cx,
135- condition. span ,
136- expr. span ,
137- left_hand,
138- right_hand,
139- if_block,
140- else_block,
141- msrv,
142- ) ,
143- BinOpKind :: Lt | BinOpKind :: Le => check_gt (
144- cx,
145- condition. span ,
146- expr. span ,
147- right_hand,
148- left_hand,
149- if_block,
150- else_block,
151- msrv,
152- ) ,
130+ BinOpKind :: Gt | BinOpKind :: Ge => {
131+ check_gt ( cx, condition. span , left_hand, right_hand, if_block, else_block, msrv) ;
132+ } ,
133+ BinOpKind :: Lt | BinOpKind :: Le => {
134+ check_gt ( cx, condition. span , right_hand, left_hand, if_block, else_block, msrv) ;
135+ } ,
153136 _ => { } ,
154137 }
155138 }
@@ -159,7 +142,6 @@ fn check_manual_check<'tcx>(
159142fn check_gt (
160143 cx : & LateContext < ' _ > ,
161144 condition_span : Span ,
162- expr_span : Span ,
163145 big_var : & Expr < ' _ > ,
164146 little_var : & Expr < ' _ > ,
165147 if_block : & Expr < ' _ > ,
@@ -169,16 +151,7 @@ fn check_gt(
169151 if let Some ( big_var) = Var :: new ( big_var)
170152 && let Some ( little_var) = Var :: new ( little_var)
171153 {
172- check_subtraction (
173- cx,
174- condition_span,
175- expr_span,
176- big_var,
177- little_var,
178- if_block,
179- else_block,
180- msrv,
181- ) ;
154+ check_subtraction ( cx, condition_span, big_var, little_var, if_block, else_block, msrv) ;
182155 }
183156}
184157
@@ -200,7 +173,6 @@ impl Var {
200173fn check_subtraction (
201174 cx : & LateContext < ' _ > ,
202175 condition_span : Span ,
203- expr_span : Span ,
204176 big_var : Var ,
205177 little_var : Var ,
206178 if_block : & Expr < ' _ > ,
@@ -217,16 +189,7 @@ fn check_subtraction(
217189 }
218190 // If the subtraction is done in the `else` block, then we need to also revert the two
219191 // variables as it means that the check was reverted too.
220- check_subtraction (
221- cx,
222- condition_span,
223- expr_span,
224- little_var,
225- big_var,
226- else_block,
227- if_block,
228- msrv,
229- ) ;
192+ check_subtraction ( cx, condition_span, little_var, big_var, else_block, if_block, msrv) ;
230193 return ;
231194 }
232195 if is_integer_literal ( else_block, 0 )
@@ -245,7 +208,7 @@ fn check_subtraction(
245208 span_lint_and_sugg (
246209 cx,
247210 IMPLICIT_SATURATING_SUB ,
248- expr_span ,
211+ else_block . span ,
249212 "manual arithmetic check found" ,
250213 "replace it with" ,
251214 format ! ( "{big_var_snippet}.saturating_sub({little_var_snippet})" ) ,
0 commit comments