mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Auto merge of #4851 - daxpedda:float-arithmetic, r=flip1995
Remove negative float literal checks. Fixes #4850. changelog: Remove negative float literal checks.
This commit is contained in:
commit
f3288eb48d
@ -92,14 +92,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
|
|||||||
},
|
},
|
||||||
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
|
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
|
||||||
let ty = cx.tables.expr_ty(arg);
|
let ty = cx.tables.expr_ty(arg);
|
||||||
if ty.is_integral() {
|
if constant_simple(cx, cx.tables, expr).is_none() {
|
||||||
if constant_simple(cx, cx.tables, expr).is_none() {
|
if ty.is_integral() {
|
||||||
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
|
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
|
||||||
self.expr_span = Some(expr.span);
|
self.expr_span = Some(expr.span);
|
||||||
|
} else if ty.is_floating_point() {
|
||||||
|
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
|
||||||
|
self.expr_span = Some(expr.span);
|
||||||
}
|
}
|
||||||
} else if ty.is_floating_point() {
|
|
||||||
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
|
|
||||||
self.expr_span = Some(expr.span);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -55,6 +55,10 @@ fn main() {
|
|||||||
f *= 2.0;
|
f *= 2.0;
|
||||||
f /= 2.0;
|
f /= 2.0;
|
||||||
|
|
||||||
|
// no error, overflows are checked by `overflowing_literals`
|
||||||
|
-1.;
|
||||||
|
-(-1.);
|
||||||
|
|
||||||
// No errors for the following items because they are constant expressions
|
// No errors for the following items because they are constant expressions
|
||||||
enum Foo {
|
enum Foo {
|
||||||
Bar = -2,
|
Bar = -2,
|
||||||
|
Loading…
Reference in New Issue
Block a user