]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/overflow_check_conditional.rs
Rollup merge of #89789 - jkugelman:must-use-thread-builder, r=joshtriplett
[rust.git] / src / tools / clippy / clippy_lints / src / overflow_check_conditional.rs
index 34755afdb72f0c1bf011551507cef2e92a03f3c3..0f9e5ada3a8a4e1186a5f5471e9c270272ac440f 100644 (file)
@@ -26,6 +26,9 @@
 
 declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]);
 
+const OVERFLOW_MSG: &str = "you are trying to use classic C overflow conditions that will fail in Rust";
+const UNDERFLOW_MSG: &str = "you are trying to use classic C underflow conditions that will fail in Rust";
+
 impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
     // a + b < a, a > a + b, a < a - b, a - b > a
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
@@ -40,17 +43,11 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             if cx.typeck_results().expr_ty(ident1).is_integral();
             if cx.typeck_results().expr_ty(ident2).is_integral();
             then {
-                if let BinOpKind::Lt = op.node {
-                    if let BinOpKind::Add = op2.node {
-                        span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
-                            "you are trying to use classic C overflow conditions that will fail in Rust");
-                    }
+                if op.node == BinOpKind::Lt && op2.node == BinOpKind::Add {
+                    span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, OVERFLOW_MSG);
                 }
-                if let BinOpKind::Gt = op.node {
-                    if let BinOpKind::Sub = op2.node {
-                        span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
-                            "you are trying to use classic C underflow conditions that will fail in Rust");
-                    }
+                if op.node == BinOpKind::Gt && op2.node == BinOpKind::Sub {
+                    span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, UNDERFLOW_MSG);
                 }
             }
         }
@@ -65,17 +62,11 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             if cx.typeck_results().expr_ty(ident1).is_integral();
             if cx.typeck_results().expr_ty(ident2).is_integral();
             then {
-                if let BinOpKind::Gt = op.node {
-                    if let BinOpKind::Add = op2.node {
-                        span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
-                            "you are trying to use classic C overflow conditions that will fail in Rust");
-                    }
+                if op.node == BinOpKind::Gt && op2.node == BinOpKind::Add {
+                    span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, OVERFLOW_MSG);
                 }
-                if let BinOpKind::Lt = op.node {
-                    if let BinOpKind::Sub = op2.node {
-                        span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
-                            "you are trying to use classic C underflow conditions that will fail in Rust");
-                    }
+                if op.node == BinOpKind::Lt && op2.node == BinOpKind::Sub {
+                    span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, UNDERFLOW_MSG);
                 }
             }
         }