@@ -59,12 +59,9 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
59
59
60
60
let ( mut uncertain_count, mut negative_count) = ( 0 , 0 ) ;
61
61
// Peel off possible binary expressions, for example:
62
- // x * x * y => [x, x, y]
62
+ // x * x / y => [x, x, y]
63
63
// a % b => [a]
64
- let Some ( exprs) = exprs_with_selected_binop_peeled ( cast_op) else {
65
- // Assume cast sign lose if we cannot determine the sign of `cast_op`
66
- return true ;
67
- } ;
64
+ let exprs = exprs_with_selected_binop_peeled ( cast_op) ;
68
65
for expr in exprs {
69
66
let ty = cx. typeck_results ( ) . expr_ty ( expr) ;
70
67
match expr_sign ( cx, expr, ty) {
@@ -141,23 +138,24 @@ fn expr_sign(cx: &LateContext<'_>, expr: &Expr<'_>, ty: Ty<'_>) -> Sign {
141
138
/// otherwise if the exponent is an odd number, the result is always negative.
142
139
///
143
140
/// If either value can't be evaluated, [`Sign::Uncertain`] will be returned.
144
- fn pow_call_result_sign( cx : & LateContext < ' _ > , caller : & Expr < ' _ > , power_of : & Expr < ' _ > ) -> Sign {
145
- let caller_ty = cx. typeck_results ( ) . expr_ty ( caller ) ;
146
- let Some ( caller_val ) = get_const_int_eval ( cx, caller , caller_ty ) else {
141
+ fn pow_call_result_sign ( cx : & LateContext < ' _ > , base : & Expr < ' _ > , exponent : & Expr < ' _ > ) -> Sign {
142
+ let base_ty = cx. typeck_results ( ) . expr_ty ( base ) ;
143
+ let Some ( base_val ) = get_const_int_eval ( cx, base , base_ty ) else {
147
144
return Sign :: Uncertain ;
148
- }
149
- // Non-negative values raised to non-negative exponents are always non-negative, ignoring overflow.
145
+ } ;
146
+ // Non-negative bases raised to non-negative exponents are always non-negative, ignoring overflow.
150
147
// (Rust's integer pow() function takes an unsigned exponent.)
151
- if caller_val >= 0 {
148
+ if base_val >= 0 {
152
149
return Sign :: ZeroOrPositive ;
153
150
}
154
151
155
- let Some ( Constant :: Int ( n) ) = constant ( cx, cx. typeck_results ( ) , power_of ) else {
152
+ let Some ( Constant :: Int ( n) ) = constant ( cx, cx. typeck_results ( ) , exponent ) else {
156
153
return Sign :: Uncertain ;
157
- }
154
+ } ;
155
+
158
156
// A negative value raised to an even exponent is non-negative, and an odd exponent
159
157
// is negative, ignoring overflow.
160
- if clip ( cx. tcx , n, UintTy :: U32 ) % 2 == 0 0 {
158
+ if clip ( cx. tcx , n, UintTy :: U32 ) % 2 == 0 {
161
159
return Sign :: ZeroOrPositive ;
162
160
} else {
163
161
return Sign :: Negative ;
0 commit comments