@@ -107,9 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
107
107
} ) = higher:: If :: hir ( expr)
108
108
&& let ExprKind :: Binary ( ref cond_op, cond_left, cond_right) = cond. kind
109
109
{
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 ) ;
113
111
}
114
112
}
115
113
@@ -119,7 +117,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
119
117
#[ allow( clippy:: too_many_arguments) ]
120
118
fn check_manual_check < ' tcx > (
121
119
cx : & LateContext < ' tcx > ,
122
- expr : & Expr < ' tcx > ,
123
120
condition : & BinOp ,
124
121
left_hand : & Expr < ' tcx > ,
125
122
right_hand : & Expr < ' tcx > ,
@@ -130,26 +127,12 @@ fn check_manual_check<'tcx>(
130
127
let ty = cx. typeck_results ( ) . expr_ty ( left_hand) ;
131
128
if ty. is_numeric ( ) && !ty. is_signed ( ) {
132
129
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
+ } ,
153
136
_ => { } ,
154
137
}
155
138
}
@@ -159,7 +142,6 @@ fn check_manual_check<'tcx>(
159
142
fn check_gt (
160
143
cx : & LateContext < ' _ > ,
161
144
condition_span : Span ,
162
- expr_span : Span ,
163
145
big_var : & Expr < ' _ > ,
164
146
little_var : & Expr < ' _ > ,
165
147
if_block : & Expr < ' _ > ,
@@ -169,16 +151,7 @@ fn check_gt(
169
151
if let Some ( big_var) = Var :: new ( big_var)
170
152
&& let Some ( little_var) = Var :: new ( little_var)
171
153
{
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) ;
182
155
}
183
156
}
184
157
@@ -200,7 +173,6 @@ impl Var {
200
173
fn check_subtraction (
201
174
cx : & LateContext < ' _ > ,
202
175
condition_span : Span ,
203
- expr_span : Span ,
204
176
big_var : Var ,
205
177
little_var : Var ,
206
178
if_block : & Expr < ' _ > ,
@@ -217,16 +189,7 @@ fn check_subtraction(
217
189
}
218
190
// If the subtraction is done in the `else` block, then we need to also revert the two
219
191
// 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) ;
230
193
return ;
231
194
}
232
195
if is_integer_literal ( else_block, 0 )
@@ -245,7 +208,7 @@ fn check_subtraction(
245
208
span_lint_and_sugg (
246
209
cx,
247
210
IMPLICIT_SATURATING_SUB ,
248
- expr_span ,
211
+ else_block . span ,
249
212
"manual arithmetic check found" ,
250
213
"replace it with" ,
251
214
format ! ( "{big_var_snippet}.saturating_sub({little_var_snippet})" ) ,
0 commit comments