Skip to content

Commit f3288eb

Browse files
committed
Auto merge of #4851 - daxpedda:float-arithmetic, r=flip1995
Remove negative float literal checks. Fixes #4850. changelog: Remove negative float literal checks.
2 parents d377486 + e46bedc commit f3288eb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clippy_lints/src/arithmetic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
9292
},
9393
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
9494
let ty = cx.tables.expr_ty(arg);
95-
if ty.is_integral() {
96-
if constant_simple(cx, cx.tables, expr).is_none() {
95+
if constant_simple(cx, cx.tables, expr).is_none() {
96+
if ty.is_integral() {
9797
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
9898
self.expr_span = Some(expr.span);
99+
} else if ty.is_floating_point() {
100+
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
101+
self.expr_span = Some(expr.span);
99102
}
100-
} else if ty.is_floating_point() {
101-
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
102-
self.expr_span = Some(expr.span);
103103
}
104104
},
105105
_ => (),

tests/ui/arithmetic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ fn main() {
5555
f *= 2.0;
5656
f /= 2.0;
5757

58+
// no error, overflows are checked by `overflowing_literals`
59+
-1.;
60+
-(-1.);
61+
5862
// No errors for the following items because they are constant expressions
5963
enum Foo {
6064
Bar = -2,

0 commit comments

Comments
 (0)