Skip to content

Commit 1e3c55e

Browse files
authored
Remove redundant uncertain_counts
1 parent 6bc7c96 commit 1e3c55e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

clippy_lints/src/casts/cast_sign_loss.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ fn pow_call_result_sign(cx: &LateContext<'_>, base: &Expr<'_>, exponent: &Expr<'
192192
/// Returns the sign of the list of peeled expressions.
193193
fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
194194
let mut negative_count = 0;
195-
let mut uncertain_count = 0;
196195

197196
// Peel off possible binary expressions, for example:
198197
// x * x / y => [x, x, y]
@@ -201,18 +200,17 @@ fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
201200
for expr in exprs {
202201
match expr_sign(cx, expr, None) {
203202
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,
205206
Sign::ZeroOrPositive => (),
206207
};
207208
}
208209

209210
// A mul/div is:
210-
// - uncertain if there are any uncertain values (because they could be negative or positive),
211211
// - negative if there are an odd number of negative values,
212212
// - 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 {
216214
Sign::Negative
217215
} else {
218216
Sign::ZeroOrPositive
@@ -225,7 +223,6 @@ fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
225223
/// Returns the sign of the list of peeled expressions.
226224
fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
227225
let mut negative_count = 0;
228-
let mut uncertain_count = 0;
229226
let mut positive_count = 0;
230227

231228
// Peel off possible binary expressions, for example:
@@ -234,19 +231,19 @@ fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign {
234231
for expr in exprs {
235232
match expr_sign(cx, expr, None) {
236233
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,
238237
Sign::ZeroOrPositive => positive_count += 1,
239238
};
240239
}
241240

242241
// A sum is:
243-
// - uncertain if there are any uncertain values (because they could be negative or positive),
244242
// - 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.
246245
// 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 {
250247
Sign::ZeroOrPositive
251248
} else if positive_count == 0 {
252249
Sign::Negative

0 commit comments

Comments
 (0)