@@ -192,7 +192,6 @@ fn pow_call_result_sign(cx: &LateContext<'_>, base: &Expr<'_>, exponent: &Expr<'
192
192
/// Returns the sign of the list of peeled expressions.
193
193
fn expr_muldiv_sign ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> Sign {
194
194
let mut negative_count = 0 ;
195
- let mut uncertain_count = 0 ;
196
195
197
196
// Peel off possible binary expressions, for example:
198
197
// x * x / y => [x, x, y]
@@ -201,18 +200,17 @@ fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
201
200
for expr in exprs {
202
201
match expr_sign ( cx, expr, None ) {
203
202
Sign :: Negative => negative_count += 1 ,
204
- Sign :: Uncertain => uncertain_count += 1 ,
203
+ // A mul/div is:
204
+ // - uncertain if there are any uncertain values (because they could be negative or positive),
205
+ Sign :: Uncertain => return Sign :: Uncertain ,
205
206
Sign :: ZeroOrPositive => ( ) ,
206
207
} ;
207
208
}
208
209
209
210
// A mul/div is:
210
- // - uncertain if there are any uncertain values (because they could be negative or positive),
211
211
// - negative if there are an odd number of negative values,
212
212
// - positive or zero otherwise.
213
- if uncertain_count > 0 {
214
- Sign :: Uncertain
215
- } else if negative_count % 2 == 1 {
213
+ if negative_count % 2 == 1 {
216
214
Sign :: Negative
217
215
} else {
218
216
Sign :: ZeroOrPositive
@@ -225,7 +223,6 @@ fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
225
223
/// Returns the sign of the list of peeled expressions.
226
224
fn expr_add_sign ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> Sign {
227
225
let mut negative_count = 0 ;
228
- let mut uncertain_count = 0 ;
229
226
let mut positive_count = 0 ;
230
227
231
228
// Peel off possible binary expressions, for example:
@@ -234,19 +231,19 @@ fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
234
231
for expr in exprs {
235
232
match expr_sign ( cx, expr, None ) {
236
233
Sign :: Negative => negative_count += 1 ,
237
- Sign :: Uncertain => uncertain_count += 1 ,
234
+ // A sum is:
235
+ // - uncertain if there are any uncertain values (because they could be negative or positive),
236
+ Sign :: Uncertain => return Sign :: Uncertain ,
238
237
Sign :: ZeroOrPositive => positive_count += 1 ,
239
238
} ;
240
239
}
241
240
242
241
// A sum is:
243
- // - uncertain if there are any uncertain values (because they could be negative or positive),
244
242
// - positive or zero if there are only positive (or zero) values,
245
- // - negative if there are only negative (or zero) values.
243
+ // - negative if there are only negative (or zero) values, or
244
+ // - uncertain if there are both.
246
245
// We could split Zero out into its own variant, but we don't yet.
247
- if uncertain_count > 0 {
248
- Sign :: Uncertain
249
- } else if negative_count == 0 {
246
+ if negative_count == 0 {
250
247
Sign :: ZeroOrPositive
251
248
} else if positive_count == 0 {
252
249
Sign :: Negative
0 commit comments