]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/modulo_arithmetic.rs
Auto merge of #6278 - ThibsG:DerefAddrOf, r=llogiq
[rust.git] / clippy_lints / src / modulo_arithmetic.rs
index 3bb3eb15d9c262ad9e3ee8f4665bf7deb030e18c..da3ae1d652f6c515862ebb2c74016b4c7e69c4f0 100644 (file)
@@ -8,7 +8,7 @@
 use std::fmt::Display;
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for modulo arithemtic.
+    /// **What it does:** Checks for modulo arithmetic.
     ///
     /// **Why is this bad?** The results of modulo (%) operation might differ
     /// depending on the language, when negative numbers are involved.
@@ -36,10 +36,9 @@ struct OperandInfo {
     is_integral: bool,
 }
 
-fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<OperandInfo> {
-    #[allow(clippy::match_wildcard_for_single_variants)]
-    match constant(cx, cx.tables, operand) {
-        Some((Constant::Int(v), _)) => match cx.tables.expr_ty(expr).kind {
+fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<OperandInfo> {
+    match constant(cx, cx.typeck_results(), operand) {
+        Some((Constant::Int(v), _)) => match *cx.typeck_results().expr_ty(expr).kind() {
             ty::Int(ity) => {
                 let value = sext(cx.tcx, v, ity);
                 return Some(OperandInfo {
@@ -80,8 +79,8 @@ fn might_have_negative_value(t: &ty::TyS<'_>) -> bool {
     t.is_signed() || t.is_floating_point()
 }
 
-fn check_const_operands<'a, 'tcx>(
-    cx: &LateContext<'a, 'tcx>,
+fn check_const_operands<'tcx>(
+    cx: &LateContext<'tcx>,
     expr: &'tcx Expr<'_>,
     lhs_operand: &OperandInfo,
     rhs_operand: &OperandInfo,
@@ -106,8 +105,8 @@ fn check_const_operands<'a, 'tcx>(
     }
 }
 
-fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) {
-    let operand_type = cx.tables.expr_ty(operand);
+fn check_non_const_operands<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) {
+    let operand_type = cx.typeck_results().expr_ty(operand);
     if might_have_negative_value(operand_type) {
         span_lint_and_then(
             cx,
@@ -124,8 +123,8 @@ fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Ex
     }
 }
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
+impl<'tcx> LateLintPass<'tcx> for ModuloArithmetic {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
         match &expr.kind {
             ExprKind::Binary(op, lhs, rhs) | ExprKind::AssignOp(op, lhs, rhs) => {
                 if let BinOpKind::Rem = op.node {