about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaio <c410.f3r@gmail.com>2022-10-03 20:10:00 -0300
committerCaio <c410.f3r@gmail.com>2022-10-03 20:10:00 -0300
commita44914fcd32eb3c0c3ff65f10b8b062e0b11b6f5 (patch)
tree413c48f7534306a7450f76446405c97a490e7569
parent2a6a98f95be4d630bac368b0bbd622749e999eb3 (diff)
downloadrust-a44914fcd32eb3c0c3ff65f10b8b062e0b11b6f5.tar.gz
rust-a44914fcd32eb3c0c3ff65f10b8b062e0b11b6f5.zip
Dogfood
-rw-r--r--clippy_lints/src/operators/arithmetic_side_effects.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs
index 54cbcd35587..8827daaa3ee 100644
--- a/clippy_lints/src/operators/arithmetic_side_effects.rs
+++ b/clippy_lints/src/operators/arithmetic_side_effects.rs
@@ -45,10 +45,10 @@ impl ArithmeticSideEffects {
             let ast::LitKind::Int(value, _) = lit.node
         {
             match (&op.node, value) {
-                (hir::BinOpKind::Add | hir::BinOpKind::Sub, 0) |
-                (hir::BinOpKind::Mul, 0 | 1) => true,
                 (hir::BinOpKind::Div | hir::BinOpKind::Rem, 0) => false,
-                (hir::BinOpKind::Div | hir::BinOpKind::Rem, _) => true,
+                (hir::BinOpKind::Add | hir::BinOpKind::Sub, 0)
+                    | (hir::BinOpKind::Div | hir::BinOpKind::Rem, _)
+                    | (hir::BinOpKind::Mul, 0 | 1) => true,
                 _ => false,
             }
         } else {
@@ -74,7 +74,7 @@ impl ArithmeticSideEffects {
         self.expr_span = Some(expr.span);
     }
 
-    /// If `expr` does not match any variant of [LiteralIntegerTy], returns `None`.
+    /// If `expr` does not match any variant of `LiteralIntegerTy`, returns `None`.
     fn literal_integer<'expr, 'tcx>(expr: &'expr hir::Expr<'tcx>) -> Option<LiteralIntegerTy<'expr, 'tcx>> {
         if matches!(expr.kind, hir::ExprKind::Lit(_)) {
             return Some(LiteralIntegerTy::Value(expr));
@@ -118,11 +118,9 @@ impl ArithmeticSideEffects {
         }
         let has_valid_op = if Self::is_integral(lhs_ty) && Self::is_integral(rhs_ty) {
             match (Self::literal_integer(lhs), Self::literal_integer(rhs)) {
-                (None, None) => false,
-                (None, Some(lit_int_ty)) => Self::has_valid_op(op, lit_int_ty.into()),
-                (Some(lit_int_ty), None) => Self::has_valid_op(op, lit_int_ty.into()),
+                (None, Some(lit_int_ty)) | (Some(lit_int_ty), None) => Self::has_valid_op(op, lit_int_ty.into()),
                 (Some(LiteralIntegerTy::Value(_)), Some(LiteralIntegerTy::Value(_))) => true,
-                (Some(_), Some(_)) => false,
+                (None, None) | (Some(_), Some(_)) => false,
             }
         } else {
             false
@@ -180,9 +178,9 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
     }
 }
 
-/// Tells if an expression is a integer passed by value or by reference.
+/// Tells if an expression is a integer declared by value or by reference.
 ///
-/// If [LiteralIntegerTy::Ref], then the contained value will be `hir::ExprKind::Lit` rather
+/// If `LiteralIntegerTy::Ref`, then the contained value will be `hir::ExprKind::Lit` rather
 /// than `hirExprKind::Addr`.
 enum LiteralIntegerTy<'expr, 'tcx> {
     /// For example, `&199`
@@ -194,8 +192,7 @@ enum LiteralIntegerTy<'expr, 'tcx> {
 impl<'expr, 'tcx> From<LiteralIntegerTy<'expr, 'tcx>> for &'expr hir::Expr<'tcx> {
     fn from(from: LiteralIntegerTy<'expr, 'tcx>) -> Self {
         match from {
-            LiteralIntegerTy::Ref(elem) => elem,
-            LiteralIntegerTy::Value(elem) => elem,
+            LiteralIntegerTy::Ref(elem) | LiteralIntegerTy::Value(elem) => elem,
         }
     }
 }