]> git.lizzy.rs Git - rust.git/commitdiff
BinOpKind
authorcsmoe <35686186+csmoe@users.noreply.github.com>
Thu, 12 Jul 2018 07:50:09 +0000 (15:50 +0800)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Mon, 16 Jul 2018 09:46:37 +0000 (11:46 +0200)
36 files changed:
clippy_lints/src/arithmetic.rs
clippy_lints/src/assign_ops.rs
clippy_lints/src/bit_mask.rs
clippy_lints/src/booleans.rs
clippy_lints/src/bytecount.rs
clippy_lints/src/consts.rs
clippy_lints/src/cyclomatic_complexity.rs
clippy_lints/src/double_comparison.rs
clippy_lints/src/duration_subsec.rs
clippy_lints/src/eq_op.rs
clippy_lints/src/erasing_op.rs
clippy_lints/src/eval_order_dependence.rs
clippy_lints/src/identity_op.rs
clippy_lints/src/len_zero.rs
clippy_lints/src/loops.rs
clippy_lints/src/methods.rs
clippy_lints/src/misc.rs
clippy_lints/src/needless_bool.rs
clippy_lints/src/neg_cmp_op_on_partial_ord.rs
clippy_lints/src/neg_multiply.rs
clippy_lints/src/no_effect.rs
clippy_lints/src/overflow_check_conditional.rs
clippy_lints/src/ptr.rs
clippy_lints/src/ranges.rs
clippy_lints/src/strings.rs
clippy_lints/src/suspicious_trait_impl.rs
clippy_lints/src/types.rs
clippy_lints/src/unwrap.rs
clippy_lints/src/utils/author.rs
clippy_lints/src/utils/comparisons.rs
clippy_lints/src/utils/higher.rs
clippy_lints/src/utils/hir_utils.rs
clippy_lints/src/utils/sugg.rs
clippy_lints/src/zero_div_zero.rs
tests/ui/suspicious_arithmetic_impl.rs
tests/ui/trailing_zeros.stdout

index 3f15f955e1997722d3f5c00c2ddfe08b51b63b25..0ab7a3388637c70c1a2c7e544594cd997d259969 100644 (file)
@@ -57,19 +57,19 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
         match expr.node {
             hir::ExprKind::Binary(ref op, ref l, ref r) => {
                 match op.node {
-                    hir::BiAnd
-                    | hir::BiOr
-                    | hir::BiBitAnd
-                    | hir::BiBitOr
-                    | hir::BiBitXor
-                    | hir::BiShl
-                    | hir::BiShr
-                    | hir::BiEq
-                    | hir::BiLt
-                    | hir::BiLe
-                    | hir::BiNe
-                    | hir::BiGe
-                    | hir::BiGt => return,
+                    hir::BinOpKind::And
+                    | hir::BinOpKind::Or
+                    | hir::BinOpKind::BitAnd
+                    | hir::BinOpKind::BitOr
+                    | hir::BinOpKind::BitXor
+                    | hir::BinOpKind::Shl
+                    | hir::BinOpKind::Shr
+                    | hir::BinOpKind::Eq
+                    | hir::BinOpKind::Lt
+                    | hir::BinOpKind::Le
+                    | hir::BinOpKind::Ne
+                    | hir::BinOpKind::Ge
+                    | hir::BinOpKind::Gt => return,
                     _ => (),
                 }
                 let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));
index 15871cdfe025494e21b04ede25fda1d70195aa30..53b4904fa96aa8c67c78b68de78c67c3d22e4c11 100644 (file)
@@ -175,18 +175,18 @@ macro_rules! ops {
                             cx,
                             ty,
                             rty.into(),
-                            Add: BiAdd,
-                            Sub: BiSub,
-                            Mul: BiMul,
-                            Div: BiDiv,
-                            Rem: BiRem,
-                            And: BiAnd,
-                            Or: BiOr,
-                            BitAnd: BiBitAnd,
-                            BitOr: BiBitOr,
-                            BitXor: BiBitXor,
-                            Shr: BiShr,
-                            Shl: BiShl
+                            Add: BinOpKind::Add,
+                            Sub: BinOpKind::Sub,
+                            Mul: BinOpKind::Mul,
+                            Div: BinOpKind::Div,
+                            Rem: BinOpKind::Rem,
+                            And: BinOpKind::And,
+                            Or: BinOpKind::Or,
+                            BitAnd: BinOpKind::BitAnd,
+                            BitOr: BinOpKind::BitOr,
+                            BitXor: BinOpKind::BitXor,
+                            Shr: BinOpKind::Shr,
+                            Shl: BinOpKind::Shl
                         ) {
                             span_lint_and_then(
                                 cx,
@@ -224,13 +224,13 @@ macro_rules! ops {
                         // a = b commutative_op a
                         if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
                             match op.node {
-                                hir::BiAdd
-                                | hir::BiMul
-                                | hir::BiAnd
-                                | hir::BiOr
-                                | hir::BiBitXor
-                                | hir::BiBitAnd
-                                | hir::BiBitOr => {
+                                hir::BinOpKind::Add
+                                | hir::BinOpKind::Mul
+                                | hir::BinOpKind::And
+                                | hir::BinOpKind::Or
+                                | hir::BinOpKind::BitXor
+                                | hir::BinOpKind::BitAnd
+                                | hir::BinOpKind::BitOr => {
                                     lint(assignee, l);
                                 },
                                 _ => {},
@@ -244,11 +244,11 @@ macro_rules! ops {
     }
 }
 
-fn is_commutative(op: hir::BinOp_) -> bool {
-    use rustc::hir::BinOp_::*;
+fn is_commutative(op: hir::BinOpKind) -> bool {
+    use rustc::hir::BinOpKind::*;
     match op {
-        BiAdd | BiMul | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr | BiEq | BiNe => true,
-        BiSub | BiDiv | BiRem | BiShl | BiShr | BiLt | BiLe | BiGe | BiGt => false,
+        Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
+        Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,
     }
 }
 
index 0558ad36b34889ce7dbe8e5bc5466c8ad62565d7..25d5e4d4db1d573b986d902bad7008fa23cad5a2 100644 (file)
@@ -120,9 +120,9 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         }
         if_chain! {
             if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
-            if BinOp_::BiEq == op.node;
+            if BinOpKind::Eq == op.node;
             if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
-            if BinOp_::BiBitAnd == op1.node;
+            if BinOpKind::BitAnd == op1.node;
             if let ExprKind::Lit(ref lit) = right1.node;
             if let LitKind::Int(n, _) = lit.node;
             if let ExprKind::Lit(ref lit1) = right.node;
@@ -143,22 +143,22 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
     }
 }
 
-fn invert_cmp(cmp: BinOp_) -> BinOp_ {
+fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
     match cmp {
-        BiEq => BiEq,
-        BiNe => BiNe,
-        BiLt => BiGt,
-        BiGt => BiLt,
-        BiLe => BiGe,
-        BiGe => BiLe,
-        _ => BiOr, // Dummy
+        BinOpKind::Eq => BinOpKind::Eq,
+        BinOpKind::Ne => BinOpKind::Ne,
+        BinOpKind::Lt => BinOpKind::Gt,
+        BinOpKind::Gt => BinOpKind::Lt,
+        BinOpKind::Le => BinOpKind::Ge,
+        BinOpKind::Ge => BinOpKind::Le,
+        _ => BinOpKind::Or, // Dummy
     }
 }
 
 
-fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u128, span: Span) {
+fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
     if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
-        if op.node != BiBitAnd && op.node != BiBitOr {
+        if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
             return;
         }
         fetch_int_literal(cx, right)
@@ -167,10 +167,10 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u12
     }
 }
 
-fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u128, cmp_value: u128, span: Span) {
+fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
     match cmp_op {
-        BiEq | BiNe => match bit_op {
-            BiBitAnd => if mask_value & cmp_value != cmp_value {
+        BinOpKind::Eq | BinOpKind::Ne => match bit_op {
+            BinOpKind::BitAnd => if mask_value & cmp_value != cmp_value {
                 if cmp_value != 0 {
                     span_lint(
                         cx,
@@ -186,7 +186,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             } else if mask_value == 0 {
                 span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
             },
-            BiBitOr => if mask_value | cmp_value != cmp_value {
+            BinOpKind::BitOr => if mask_value | cmp_value != cmp_value {
                 span_lint(
                     cx,
                     BAD_BIT_MASK,
@@ -200,8 +200,8 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             },
             _ => (),
         },
-        BiLt | BiGe => match bit_op {
-            BiBitAnd => if mask_value < cmp_value {
+        BinOpKind::Lt | BinOpKind::Ge => match bit_op {
+            BinOpKind::BitAnd => if mask_value < cmp_value {
                 span_lint(
                     cx,
                     BAD_BIT_MASK,
@@ -215,7 +215,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             } else if mask_value == 0 {
                 span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
             },
-            BiBitOr => if mask_value >= cmp_value {
+            BinOpKind::BitOr => if mask_value >= cmp_value {
                 span_lint(
                     cx,
                     BAD_BIT_MASK,
@@ -229,11 +229,11 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             } else {
                 check_ineffective_lt(cx, span, mask_value, cmp_value, "|");
             },
-            BiBitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
+            BinOpKind::BitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
             _ => (),
         },
-        BiLe | BiGt => match bit_op {
-            BiBitAnd => if mask_value <= cmp_value {
+        BinOpKind::Le | BinOpKind::Gt => match bit_op {
+            BinOpKind::BitAnd => if mask_value <= cmp_value {
                 span_lint(
                     cx,
                     BAD_BIT_MASK,
@@ -247,7 +247,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             } else if mask_value == 0 {
                 span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
             },
-            BiBitOr => if mask_value > cmp_value {
+            BinOpKind::BitOr => if mask_value > cmp_value {
                 span_lint(
                     cx,
                     BAD_BIT_MASK,
@@ -261,7 +261,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
             } else {
                 check_ineffective_gt(cx, span, mask_value, cmp_value, "|");
             },
-            BiBitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
+            BinOpKind::BitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
             _ => (),
         },
         _ => (),
index c6d0942a87708a2c877294716cf6742689b7cc9c..e23978ebc1d476e8c6ab04c45561eb3542fb4055 100644 (file)
@@ -84,7 +84,7 @@ struct Hir2Qmm<'a, 'tcx: 'a, 'v> {
 }
 
 impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
-    fn extract(&mut self, op: BinOp_, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
+    fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
         for a in a {
             if let ExprKind::Binary(binop, ref lhs, ref rhs) = a.node {
                 if binop.node == op {
@@ -103,8 +103,8 @@ fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
             match e.node {
                 ExprKind::Unary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
                 ExprKind::Binary(binop, ref lhs, ref rhs) => match binop.node {
-                    BiOr => return Ok(Bool::Or(self.extract(BiOr, &[lhs, rhs], Vec::new())?)),
-                    BiAnd => return Ok(Bool::And(self.extract(BiAnd, &[lhs, rhs], Vec::new())?)),
+                    BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
+                    BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)),
                     _ => (),
                 },
                 ExprKind::Lit(ref lit) => match lit.node {
@@ -137,12 +137,12 @@ fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
                         }
                     };
                     match binop.node {
-                        BiEq => mk_expr(BiNe),
-                        BiNe => mk_expr(BiEq),
-                        BiGt => mk_expr(BiLe),
-                        BiGe => mk_expr(BiLt),
-                        BiLt => mk_expr(BiGe),
-                        BiLe => mk_expr(BiGt),
+                        BinOpKind::Eq => mk_expr(BinOpKind::Ne),
+                        BinOpKind::Ne => mk_expr(BinOpKind::Eq),
+                        BinOpKind::Gt => mk_expr(BinOpKind::Le),
+                        BinOpKind::Ge => mk_expr(BinOpKind::Lt),
+                        BinOpKind::Lt => mk_expr(BinOpKind::Ge),
+                        BinOpKind::Le => mk_expr(BinOpKind::Gt),
                         _ => continue,
                     }
                 },
@@ -185,12 +185,12 @@ fn simplify_not(&self, expr: &Expr) -> Option<String> {
                 }
 
                 match binop.node {
-                    BiEq => Some(" != "),
-                    BiNe => Some(" == "),
-                    BiLt => Some(" >= "),
-                    BiGt => Some(" <= "),
-                    BiLe => Some(" > "),
-                    BiGe => Some(" < "),
+                    BinOpKind::Eq => Some(" != "),
+                    BinOpKind::Ne => Some(" == "),
+                    BinOpKind::Lt => Some(" >= "),
+                    BinOpKind::Gt => Some(" <= "),
+                    BinOpKind::Le => Some(" > "),
+                    BinOpKind::Ge => Some(" < "),
                     _ => None,
                 }.and_then(|op| Some(format!("{}{}{}", self.snip(lhs)?, op, self.snip(rhs)?)))
             },
@@ -441,7 +441,7 @@ fn visit_expr(&mut self, e: &'tcx Expr) {
             return;
         }
         match e.node {
-            ExprKind::Binary(binop, _, _) if binop.node == BiOr || binop.node == BiAnd => self.bool_expr(e),
+            ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => self.bool_expr(e),
             ExprKind::Unary(UnNot, ref inner) => if self.cx.tables.node_types()[inner.hir_id].is_bool() {
                 self.bool_expr(e);
             } else {
index e60fbbbe51db30cf8a51ed542d375153deb751f9..aaa924e95b1ec923b0f306c8879eebcada2d7521 100644 (file)
@@ -51,7 +51,7 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
                     if body.arguments.len() == 1;
                     if let Some(argname) = get_pat_name(&body.arguments[0].pat);
                     if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
-                    if op.node == BiEq;
+                    if op.node == BinOpKind::Eq;
                     if match_type(cx,
                                walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
                                &paths::SLICE_ITER);
index 8e0e60193bbafb9247fb646c45e79976ee2accde..d7323337f2472023314bf207c19a5b103da1bc87 100644 (file)
@@ -340,43 +340,43 @@ fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option<Constant> {
                         let r = sext(self.tcx, r, ity);
                         let zext = |n: i128| Constant::Int(unsext(self.tcx, n, ity));
                         match op.node {
-                            BiAdd => l.checked_add(r).map(zext),
-                            BiSub => l.checked_sub(r).map(zext),
-                            BiMul => l.checked_mul(r).map(zext),
-                            BiDiv if r != 0 => l.checked_div(r).map(zext),
-                            BiRem if r != 0 => l.checked_rem(r).map(zext),
-                            BiShr => l.checked_shr(r as u128 as u32).map(zext),
-                            BiShl => l.checked_shl(r as u128 as u32).map(zext),
-                            BiBitXor => Some(zext(l ^ r)),
-                            BiBitOr => Some(zext(l | r)),
-                            BiBitAnd => Some(zext(l & r)),
-                            BiEq => Some(Constant::Bool(l == r)),
-                            BiNe => Some(Constant::Bool(l != r)),
-                            BiLt => Some(Constant::Bool(l < r)),
-                            BiLe => Some(Constant::Bool(l <= r)),
-                            BiGe => Some(Constant::Bool(l >= r)),
-                            BiGt => Some(Constant::Bool(l > r)),
+                            BinOpKind::Add => l.checked_add(r).map(zext),
+                            BinOpKind::Sub => l.checked_sub(r).map(zext),
+                            BinOpKind::Mul => l.checked_mul(r).map(zext),
+                            BinOpKind::Div if r != 0 => l.checked_div(r).map(zext),
+                            BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext),
+                            BinOpKind::Shr => l.checked_shr(r as u128 as u32).map(zext),
+                            BinOpKind::Shl => l.checked_shl(r as u128 as u32).map(zext),
+                            BinOpKind::BitXor => Some(zext(l ^ r)),
+                            BinOpKind::BitOr => Some(zext(l | r)),
+                            BinOpKind::BitAnd => Some(zext(l & r)),
+                            BinOpKind::Eq => Some(Constant::Bool(l == r)),
+                            BinOpKind::Ne => Some(Constant::Bool(l != r)),
+                            BinOpKind::Lt => Some(Constant::Bool(l < r)),
+                            BinOpKind::Le => Some(Constant::Bool(l <= r)),
+                            BinOpKind::Ge => Some(Constant::Bool(l >= r)),
+                            BinOpKind::Gt => Some(Constant::Bool(l > r)),
                             _ => None,
                         }
                     }
                     ty::TyUint(_) => {
                         match op.node {
-                            BiAdd => l.checked_add(r).map(Constant::Int),
-                            BiSub => l.checked_sub(r).map(Constant::Int),
-                            BiMul => l.checked_mul(r).map(Constant::Int),
-                            BiDiv => l.checked_div(r).map(Constant::Int),
-                            BiRem => l.checked_rem(r).map(Constant::Int),
-                            BiShr => l.checked_shr(r as u32).map(Constant::Int),
-                            BiShl => l.checked_shl(r as u32).map(Constant::Int),
-                            BiBitXor => Some(Constant::Int(l ^ r)),
-                            BiBitOr => Some(Constant::Int(l | r)),
-                            BiBitAnd => Some(Constant::Int(l & r)),
-                            BiEq => Some(Constant::Bool(l == r)),
-                            BiNe => Some(Constant::Bool(l != r)),
-                            BiLt => Some(Constant::Bool(l < r)),
-                            BiLe => Some(Constant::Bool(l <= r)),
-                            BiGe => Some(Constant::Bool(l >= r)),
-                            BiGt => Some(Constant::Bool(l > r)),
+                            BinOpKind::Add => l.checked_add(r).map(Constant::Int),
+                            BinOpKind::Sub => l.checked_sub(r).map(Constant::Int),
+                            BinOpKind::Mul => l.checked_mul(r).map(Constant::Int),
+                            BinOpKind::Div => l.checked_div(r).map(Constant::Int),
+                            BinOpKind::Rem => l.checked_rem(r).map(Constant::Int),
+                            BinOpKind::Shr => l.checked_shr(r as u32).map(Constant::Int),
+                            BinOpKind::Shl => l.checked_shl(r as u32).map(Constant::Int),
+                            BinOpKind::BitXor => Some(Constant::Int(l ^ r)),
+                            BinOpKind::BitOr => Some(Constant::Int(l | r)),
+                            BinOpKind::BitAnd => Some(Constant::Int(l & r)),
+                            BinOpKind::Eq => Some(Constant::Bool(l == r)),
+                            BinOpKind::Ne => Some(Constant::Bool(l != r)),
+                            BinOpKind::Lt => Some(Constant::Bool(l < r)),
+                            BinOpKind::Le => Some(Constant::Bool(l <= r)),
+                            BinOpKind::Ge => Some(Constant::Bool(l >= r)),
+                            BinOpKind::Gt => Some(Constant::Bool(l > r)),
                             _ => None,
                         }
                     },
@@ -384,40 +384,40 @@ fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option<Constant> {
                 }
             },
             (Constant::F32(l), Some(Constant::F32(r))) => match op.node {
-                BiAdd => Some(Constant::F32(l + r)),
-                BiSub => Some(Constant::F32(l - r)),
-                BiMul => Some(Constant::F32(l * r)),
-                BiDiv => Some(Constant::F32(l / r)),
-                BiRem => Some(Constant::F32(l % r)),
-                BiEq => Some(Constant::Bool(l == r)),
-                BiNe => Some(Constant::Bool(l != r)),
-                BiLt => Some(Constant::Bool(l < r)),
-                BiLe => Some(Constant::Bool(l <= r)),
-                BiGe => Some(Constant::Bool(l >= r)),
-                BiGt => Some(Constant::Bool(l > r)),
+                BinOpKind::Add => Some(Constant::F32(l + r)),
+                BinOpKind::Sub => Some(Constant::F32(l - r)),
+                BinOpKind::Mul => Some(Constant::F32(l * r)),
+                BinOpKind::Div => Some(Constant::F32(l / r)),
+                BinOpKind::Rem => Some(Constant::F32(l % r)),
+                BinOpKind::Eq => Some(Constant::Bool(l == r)),
+                BinOpKind::Ne => Some(Constant::Bool(l != r)),
+                BinOpKind::Lt => Some(Constant::Bool(l < r)),
+                BinOpKind::Le => Some(Constant::Bool(l <= r)),
+                BinOpKind::Ge => Some(Constant::Bool(l >= r)),
+                BinOpKind::Gt => Some(Constant::Bool(l > r)),
                 _ => None,
             },
             (Constant::F64(l), Some(Constant::F64(r))) => match op.node {
-                BiAdd => Some(Constant::F64(l + r)),
-                BiSub => Some(Constant::F64(l - r)),
-                BiMul => Some(Constant::F64(l * r)),
-                BiDiv => Some(Constant::F64(l / r)),
-                BiRem => Some(Constant::F64(l % r)),
-                BiEq => Some(Constant::Bool(l == r)),
-                BiNe => Some(Constant::Bool(l != r)),
-                BiLt => Some(Constant::Bool(l < r)),
-                BiLe => Some(Constant::Bool(l <= r)),
-                BiGe => Some(Constant::Bool(l >= r)),
-                BiGt => Some(Constant::Bool(l > r)),
+                BinOpKind::Add => Some(Constant::F64(l + r)),
+                BinOpKind::Sub => Some(Constant::F64(l - r)),
+                BinOpKind::Mul => Some(Constant::F64(l * r)),
+                BinOpKind::Div => Some(Constant::F64(l / r)),
+                BinOpKind::Rem => Some(Constant::F64(l % r)),
+                BinOpKind::Eq => Some(Constant::Bool(l == r)),
+                BinOpKind::Ne => Some(Constant::Bool(l != r)),
+                BinOpKind::Lt => Some(Constant::Bool(l < r)),
+                BinOpKind::Le => Some(Constant::Bool(l <= r)),
+                BinOpKind::Ge => Some(Constant::Bool(l >= r)),
+                BinOpKind::Gt => Some(Constant::Bool(l > r)),
                 _ => None,
             },
             (l, r) => match (op.node, l, r) {
-                (BiAnd, Constant::Bool(false), _) => Some(Constant::Bool(false)),
-                (BiOr, Constant::Bool(true), _) => Some(Constant::Bool(true)),
-                (BiAnd, Constant::Bool(true), Some(r)) | (BiOr, Constant::Bool(false), Some(r)) => Some(r),
-                (BiBitXor, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l ^ r)),
-                (BiBitAnd, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l & r)),
-                (BiBitOr, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l | r)),
+                (BinOpKind::And, Constant::Bool(false), _) => Some(Constant::Bool(false)),
+                (BinOpKind::Or, Constant::Bool(true), _) => Some(Constant::Bool(true)),
+                (BinOpKind::And, Constant::Bool(true), Some(r)) | (BinOpKind::Or, Constant::Bool(false), Some(r)) => Some(r),
+                (BinOpKind::BitXor, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l ^ r)),
+                (BinOpKind::BitAnd, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l & r)),
+                (BinOpKind::BitOr, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l | r)),
                 _ => None,
             },
         }
index 33dbf1afc890ebe4cc374c3be6befce75c158150..b1b667d046ca7e738f6d90395ac6bbd4e3595ed3 100644 (file)
@@ -171,7 +171,7 @@ fn visit_expr(&mut self, e: &'tcx Expr) {
             ExprKind::Binary(op, _, _) => {
                 walk_expr(self, e);
                 match op.node {
-                    BiAnd | BiOr => self.short_circuits += 1,
+                    BinOpKind::And | BinOpKind::Or => self.short_circuits += 1,
                     _ => (),
                 }
             },
index 7681cc7225f6667167be18278f9c62e8b41d49d8..e2ea5723a98e0a7303237127cfc1c58744249ee3 100644 (file)
@@ -41,7 +41,7 @@ impl<'a, 'tcx> DoubleComparisonPass {
     fn check_binop(
         &self,
         cx: &LateContext<'a, 'tcx>,
-        op: BinOp_,
+        op: BinOpKind,
         lhs: &'tcx Expr,
         rhs: &'tcx Expr,
         span: Span,
@@ -67,10 +67,10 @@ macro_rules! lint_double_comparison {
             }}
         }
         match (op, lkind, rkind) {
-            (BiOr, BiEq, BiLt) | (BiOr, BiLt, BiEq) => lint_double_comparison!(<=),
-            (BiOr, BiEq, BiGt) | (BiOr, BiGt, BiEq) => lint_double_comparison!(>=),
-            (BiOr, BiLt, BiGt) | (BiOr, BiGt, BiLt) => lint_double_comparison!(!=),
-            (BiAnd, BiLe, BiGe) | (BiAnd, BiGe, BiLe) => lint_double_comparison!(==),
+            (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => lint_double_comparison!(<=),
+            (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Eq) => lint_double_comparison!(>=),
+            (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Lt) => lint_double_comparison!(!=),
+            (BinOpKind::And, BinOpKind::Le, BinOpKind::Ge) | (BinOpKind::And, BinOpKind::Ge, BinOpKind::Le) => lint_double_comparison!(==),
             _ => (),
         };
     }
index b3f8279c943b2d729324631f4e638d72228601d0..d374973e35b4d84f7531a26423d567f0da81c0c2 100644 (file)
@@ -38,7 +38,7 @@ fn get_lints(&self) -> LintArray {
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         if_chain! {
-            if let ExprKind::Binary(Spanned { node: BiDiv, .. }, ref left, ref right) = expr.node;
+            if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.node;
             if let ExprKind::MethodCall(ref method_path, _ , ref args) = left.node;
             if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION);
             if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right);
index 7c4c09893d3e768cd0ab7b314e8e1faf852ccd96..f58b499d8065688f0e9d192dd50053afd3775403 100644 (file)
@@ -66,20 +66,20 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
                 return;
             }
             let (trait_id, requires_ref) = match op.node {
-                BiAdd => (cx.tcx.lang_items().add_trait(), false),
-                BiSub => (cx.tcx.lang_items().sub_trait(), false),
-                BiMul => (cx.tcx.lang_items().mul_trait(), false),
-                BiDiv => (cx.tcx.lang_items().div_trait(), false),
-                BiRem => (cx.tcx.lang_items().rem_trait(), false),
+                BinOpKind::Add => (cx.tcx.lang_items().add_trait(), false),
+                BinOpKind::Sub => (cx.tcx.lang_items().sub_trait(), false),
+                BinOpKind::Mul => (cx.tcx.lang_items().mul_trait(), false),
+                BinOpKind::Div => (cx.tcx.lang_items().div_trait(), false),
+                BinOpKind::Rem => (cx.tcx.lang_items().rem_trait(), false),
                 // don't lint short circuiting ops
-                BiAnd | BiOr => return,
-                BiBitXor => (cx.tcx.lang_items().bitxor_trait(), false),
-                BiBitAnd => (cx.tcx.lang_items().bitand_trait(), false),
-                BiBitOr => (cx.tcx.lang_items().bitor_trait(), false),
-                BiShl => (cx.tcx.lang_items().shl_trait(), false),
-                BiShr => (cx.tcx.lang_items().shr_trait(), false),
-                BiNe | BiEq => (cx.tcx.lang_items().eq_trait(), true),
-                BiLt | BiLe | BiGe | BiGt => (cx.tcx.lang_items().ord_trait(), true),
+                BinOpKind::And | BinOpKind::Or => return,
+                BinOpKind::BitXor => (cx.tcx.lang_items().bitxor_trait(), false),
+                BinOpKind::BitAnd => (cx.tcx.lang_items().bitand_trait(), false),
+                BinOpKind::BitOr => (cx.tcx.lang_items().bitor_trait(), false),
+                BinOpKind::Shl => (cx.tcx.lang_items().shl_trait(), false),
+                BinOpKind::Shr => (cx.tcx.lang_items().shr_trait(), false),
+                BinOpKind::Ne | BinOpKind::Eq => (cx.tcx.lang_items().eq_trait(), true),
+                BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => (cx.tcx.lang_items().ord_trait(), true),
             };
             if let Some(trait_id) = trait_id {
                 #[allow(match_same_arms)]
@@ -159,7 +159,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
 
 fn is_valid_operator(op: BinOp) -> bool {
     match op.node {
-        BiSub | BiDiv | BiEq | BiLt | BiLe | BiGt | BiGe | BiNe | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr => true,
+        BinOpKind::Sub | BinOpKind::Div | BinOpKind::Eq | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Gt | BinOpKind::Ge | BinOpKind::Ne | BinOpKind::And | BinOpKind::Or | BinOpKind::BitXor | BinOpKind::BitAnd | BinOpKind::BitOr => true,
         _ => false,
     }
 }
index c14aafbd417dd3707e03720e81f3e50d26ccba8e..acede5d1a132fdd2698e9f73276de8092a793706 100644 (file)
@@ -38,11 +38,11 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         }
         if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
             match cmp.node {
-                BiMul | BiBitAnd => {
+                BinOpKind::Mul | BinOpKind::BitAnd => {
                     check(cx, left, e.span);
                     check(cx, right, e.span);
                 },
-                BiDiv => check(cx, left, e.span),
+                BinOpKind::Div => check(cx, left, e.span),
                 _ => (),
             }
         }
index ebbffc6680807ddacecd5df67e64289f422c5732..250ae92ea591807198ebc61bb04b1578ad224a78 100644 (file)
@@ -229,7 +229,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
             walk_expr(vis, expr);
         },
         ExprKind::Binary(op, _, _) | ExprKind::AssignOp(op, _, _) => {
-            if op.node == BiAnd || op.node == BiOr {
+            if op.node == BinOpKind::And || op.node == BinOpKind::Or {
                 // x && y and x || y always evaluate x first, so these are
                 // strictly sequenced.
             } else {
index 95dea6fc6d2bf03abb3f74f1d96ea434ff34dcf4..92e07401818eb5dd2d7d4900c293dceba2da79f5 100644 (file)
@@ -38,17 +38,17 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         }
         if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
             match cmp.node {
-                BiAdd | BiBitOr | BiBitXor => {
+                BinOpKind::Add | BinOpKind::BitOr | BinOpKind::BitXor => {
                     check(cx, left, 0, e.span, right.span);
                     check(cx, right, 0, e.span, left.span);
                 },
-                BiShl | BiShr | BiSub => check(cx, right, 0, e.span, left.span),
-                BiMul => {
+                BinOpKind::Shl | BinOpKind::Shr | BinOpKind::Sub => check(cx, right, 0, e.span, left.span),
+                BinOpKind::Mul => {
                     check(cx, left, 1, e.span, right.span);
                     check(cx, right, 1, e.span, left.span);
                 },
-                BiDiv => check(cx, right, 1, e.span, left.span),
-                BiBitAnd => {
+                BinOpKind::Div => check(cx, right, 1, e.span, left.span),
+                BinOpKind::BitAnd => {
                     check(cx, left, -1, e.span, right.span);
                     check(cx, right, -1, e.span, left.span);
                 },
index 17164c6c56a539edfcc958b4047f03fd28e6bc96..3b73e78d1a79ff1ea9d49a4f7746e1bc981eeed1 100644 (file)
@@ -81,24 +81,24 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
 
         if let ExprKind::Binary(Spanned { node: cmp, .. }, ref left, ref right) = expr.node {
             match cmp {
-                BiEq => {
+                BinOpKind::Eq => {
                     check_cmp(cx, expr.span, left, right, "", 0); // len == 0
                     check_cmp(cx, expr.span, right, left, "", 0); // 0 == len
                 },
-                BiNe => {
+                BinOpKind::Ne => {
                     check_cmp(cx, expr.span, left, right, "!", 0); // len != 0
                     check_cmp(cx, expr.span, right, left, "!", 0); // 0 != len
                 },
-                BiGt => {
+                BinOpKind::Gt => {
                     check_cmp(cx, expr.span, left, right, "!", 0); // len > 0
                     check_cmp(cx, expr.span, right, left, "", 1); // 1 > len
                 },
-                BiLt => {
+                BinOpKind::Lt => {
                     check_cmp(cx, expr.span, left, right, "", 1); // len < 1
                     check_cmp(cx, expr.span, right, left, "!", 0); // 0 < len
                 },
-                BiGe => check_cmp(cx, expr.span, left, right, "!", 1), // len <= 1
-                BiLe => check_cmp(cx, expr.span, right, left, "!", 1), // 1 >= len
+                BinOpKind::Ge => check_cmp(cx, expr.span, left, right, "!", 1), // len <= 1
+                BinOpKind::Le => check_cmp(cx, expr.span, right, left, "!", 1), // 1 >= len
                 _ => (),
             }
         }
index 7dd7263551da43933939f136ef28ff1feab0f67f..5095ddfda2587a134da90517f52f244d466ffa2d 100644 (file)
@@ -771,7 +771,7 @@ fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::Node
 
         let offset = match idx.node {
             ExprKind::Binary(op, ref lhs, ref rhs) => match op.node {
-                BinOp_::BiAdd => {
+                BinOpKindAdd => {
                     let offset_opt = if same_var(cx, lhs, var) {
                         extract_offset(cx, rhs, var)
                     } else if same_var(cx, rhs, var) {
@@ -782,7 +782,7 @@ fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::Node
 
                     offset_opt.map(Offset::positive)
                 },
-                BinOp_::BiSub if same_var(cx, lhs, var) => extract_offset(cx, rhs, var).map(Offset::negative),
+                BinOpKind::Sub if same_var(cx, lhs, var) => extract_offset(cx, rhs, var).map(Offset::negative),
                 _ => None,
             },
             ExprKind::Path(..) => if same_var(cx, idx, var) {
@@ -1884,7 +1884,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
                 match parent.node {
                     ExprKind::AssignOp(op, ref lhs, ref rhs) => {
                         if lhs.id == expr.id {
-                            if op.node == BiAdd && is_integer_literal(rhs, 1) {
+                            if op.node == BinOpKind::Add && is_integer_literal(rhs, 1) {
                                 *state = match *state {
                                     VarState::Initial if self.depth == 0 => VarState::IncrOnce,
                                     _ => VarState::DontWarn,
index ee7658334b3554d58e957e2485e98dd571abb4d7..d1740081e67de274f34696e31ad45d3adf5aab2e 100644 (file)
@@ -789,12 +789,12 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
                     _ => (),
                 }
             },
-            hir::ExprKind::Binary(op, ref lhs, ref rhs) if op.node == hir::BiEq || op.node == hir::BiNe => {
+            hir::ExprKind::Binary(op, ref lhs, ref rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => {
                 let mut info = BinaryExprInfo {
                     expr,
                     chain: lhs,
                     other: rhs,
-                    eq: op.node == hir::BiEq,
+                    eq: op.node == hir::BinOpKind::Eq,
                 };
                 lint_binary_expr_with_method_call(cx, &mut info);
             },
@@ -1274,7 +1274,7 @@ fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E
     fn check_fold_with_op(
         cx: &LateContext,
         fold_args: &[hir::Expr],
-        op: hir::BinOp_,
+        op: hir::BinOpKind,
         replacement_method_name: &str,
         replacement_has_args: bool) {
 
@@ -1332,16 +1332,16 @@ fn check_fold_with_op(
         hir::ExprKind::Lit(ref lit) => {
             match lit.node {
                 ast::LitKind::Bool(false) => check_fold_with_op(
-                    cx, fold_args, hir::BinOp_::BiOr, "any", true
+                    cx, fold_args, hir::BinOpKind::Or, "any", true
                 ),
                 ast::LitKind::Bool(true) => check_fold_with_op(
-                    cx, fold_args, hir::BinOp_::BiAnd, "all", true
+                    cx, fold_args, hir::BinOpKind::And, "all", true
                 ),
                 ast::LitKind::Int(0, _) => check_fold_with_op(
-                    cx, fold_args, hir::BinOp_::BiAdd, "sum", false
+                    cx, fold_args, hir::BinOpKindAdd, "sum", false
                 ),
                 ast::LitKind::Int(1, _) => check_fold_with_op(
-                    cx, fold_args, hir::BinOp_::BiMul, "product", false
+                    cx, fold_args, hir::BinOpKind::Mul, "product", false
                 ),
                 _ => return
             }
index f701f957031bdbdd594bd56d3d2343cdcd56ee43..f8f8aae46f8f0ee88ed9c0411de3004f69e94981 100644 (file)
@@ -305,7 +305,7 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
         if_chain! {
             if let StmtSemi(ref expr, _) = s.node;
             if let ExprKind::Binary(ref binop, ref a, ref b) = expr.node;
-            if binop.node == BiAnd || binop.node == BiOr;
+            if binop.node == BinOpKind::And || binop.node == BinOpKind::Or;
             if let Some(sugg) = Sugg::hir_opt(cx, a);
             then {
                 span_lint_and_then(cx,
@@ -313,7 +313,7 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
                     s.span,
                     "boolean short circuit operator in statement may be clearer using an explicit test",
                     |db| {
-                        let sugg = if binop.node == BiOr { !sugg } else { sugg };
+                        let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg };
                         db.span_suggestion(s.span, "replace it with",
                                            format!("if {} {{ {}; }}", sugg, &snippet(cx, b.span, "..")));
                     });
@@ -339,7 +339,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     check_to_owned(cx, left, right);
                     check_to_owned(cx, right, left);
                 }
-                if (op == BiEq || op == BiNe) && (is_float(cx, left) || is_float(cx, right)) {
+                if (op == BinOpKind::Eq || op == BinOpKind::Ne) && (is_float(cx, left) || is_float(cx, right)) {
                     if is_allowed(cx, left) || is_allowed(cx, right) {
                         return;
                     }
@@ -367,7 +367,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                         );
                         db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available.");
                     });
-                } else if op == BiRem && is_integer_literal(right, 1) {
+                } else if op == BinOpKind::Rem && is_integer_literal(right, 1) {
                     span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
                 }
             },
index 03c602bc234e4169c7e11375d21fbf3e95d2e1c6..db019bdce8899969ba0634751e6558593feeea37 100644 (file)
@@ -123,7 +123,7 @@ fn get_lints(&self) -> LintArray {
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         use self::Expression::*;
-        if let ExprKind::Binary(Spanned { node: BiEq, .. }, ref left_side, ref right_side) = e.node {
+        if let ExprKind::Binary(Spanned { node: BinOpKind::Eq, .. }, ref left_side, ref right_side) = e.node {
             match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) {
                 (Bool(true), Other) => {
                     let hint = snippet(cx, right_side.span, "..").into_owned();
index 2eb63c264fdd04cb39de2cdf2612bf9dd34d1e1a..e0374b80dd810a490150e3af3f2f2c442cbdef80 100644 (file)
@@ -56,7 +56,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             if !in_external_macro(cx, expr.span);
             if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.node;
             if let ExprKind::Binary(ref op, ref left, _) = inner.node;
-            if let BinOp_::BiLe | BinOp_::BiGe | BinOp_::BiLt | BinOp_::BiGt = op.node;
+            if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
 
             then {
 
index 70cc9eecf6e78a00b70362ffc89691be1a33bad7..e30ac8695dc8fef99eabd772f29eaf88668f8b91 100644 (file)
@@ -33,7 +33,7 @@ fn get_lints(&self) -> LintArray {
 #[allow(match_same_arms)]
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
-        if let ExprKind::Binary(Spanned { node: BiMul, .. }, ref l, ref r) = e.node {
+        if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref l, ref r) = e.node {
             match (&l.node, &r.node) {
                 (&ExprKind::Unary(..), &ExprKind::Unary(..)) => (),
                 (&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, r),
index fea0a83b4447e68ab1642db4b11c51d2ad9d9594..7dc2ab734dca3ac54a005d568445d9f9cc0bb45a 100644 (file)
@@ -133,7 +133,7 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Exp
     }
     match expr.node {
         ExprKind::Index(ref a, ref b) => Some(vec![&**a, &**b]),
-        ExprKind::Binary(ref binop, ref a, ref b) if binop.node != BiAnd && binop.node != BiOr => {
+        ExprKind::Binary(ref binop, ref a, ref b) if binop.node != BinOpKind::And && binop.node != BinOpKind::Or => {
             Some(vec![&**a, &**b])
         },
         ExprKind::Array(ref v) | ExprKind::Tup(ref v) => Some(v.iter().collect()),
index 4e63fc2f7fce262c941aebe7e4eb77f0c077ce6c..4887edea2f39ba27324b02b0ebce5cbd9b2a3640 100644 (file)
@@ -42,14 +42,14 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             if cx.tables.expr_ty(ident1).is_integral();
             if cx.tables.expr_ty(ident2).is_integral();
             then {
-                if let BinOp_::BiLt = op.node {
-                    if let BinOp_::BiAdd = op2.node {
+                if let BinOpKind::Lt = op.node {
+                    if let BinOpKindAdd = 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 let BinOp_::BiGt = op.node {
-                    if let BinOp_::BiSub = op2.node {
+                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.");
                     }
@@ -67,14 +67,14 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             if cx.tables.expr_ty(ident1).is_integral();
             if cx.tables.expr_ty(ident2).is_integral();
             then {
-                if let BinOp_::BiGt = op.node {
-                    if let BinOp_::BiAdd = op2.node {
+                if let BinOpKind::Gt = op.node {
+                    if let BinOpKindAdd = 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 let BinOp_::BiLt = op.node {
-                    if let BinOp_::BiSub = op2.node {
+                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.");
                     }
index a2c204dd1494cfa1782ba995baf1d966483dd07b..2ecdf983e6bdafd76ad6f91d7a4bdd1bc9d00e69 100644 (file)
@@ -132,7 +132,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem
 
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         if let ExprKind::Binary(ref op, ref l, ref r) = expr.node {
-            if (op.node == BiEq || op.node == BiNe) && (is_null_path(l) || is_null_path(r)) {
+            if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) {
                 span_lint(
                     cx,
                     CMP_NULL,
index e33e112f05115b37a6851fbe506723584d737b29..2fb3bf5182cd8b546ac5731a152a734378d10e1c 100644 (file)
@@ -184,7 +184,7 @@ fn has_step_by(cx: &LateContext, expr: &Expr) -> bool {
 
 fn y_plus_one(expr: &Expr) -> Option<&Expr> {
     match expr.node {
-        ExprKind::Binary(Spanned { node: BiAdd, .. }, ref lhs, ref rhs) => if is_integer_literal(lhs, 1) {
+        ExprKind::Binary(Spanned { node: BinOpKind::Add, .. }, ref lhs, ref rhs) => if is_integer_literal(lhs, 1) {
             Some(rhs)
         } else if is_integer_literal(rhs, 1) {
             Some(lhs)
@@ -197,7 +197,7 @@ fn y_plus_one(expr: &Expr) -> Option<&Expr> {
 
 fn y_minus_one(expr: &Expr) -> Option<&Expr> {
     match expr.node {
-        ExprKind::Binary(Spanned { node: BiSub, .. }, ref lhs, ref rhs) if is_integer_literal(rhs, 1) => Some(lhs),
+        ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) if is_integer_literal(rhs, 1) => Some(lhs),
         _ => None,
     }
 }
index fb9becbd43bd76a822d14952788e6a764f89b16a..40f5c66ce1582b69bcb9887ae400bd5e371090bb 100644 (file)
@@ -82,7 +82,7 @@ fn get_lints(&self) -> LintArray {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
-        if let ExprKind::Binary(Spanned { node: BiAdd, .. }, ref left, _) = e.node {
+        if let ExprKind::Binary(Spanned { node: BinOpKind::Add, .. }, ref left, _) = e.node {
             if is_string(cx, left) {
                 if !is_allowed(cx, STRING_ADD_ASSIGN, e.id) {
                     let parent = get_parent_expr(cx, e);
@@ -122,7 +122,7 @@ fn is_string(cx: &LateContext, e: &Expr) -> bool {
 
 fn is_add(cx: &LateContext, src: &Expr, target: &Expr) -> bool {
     match src.node {
-        ExprKind::Binary(Spanned { node: BiAdd, .. }, ref left, _) => SpanlessEq::new(cx).eq_expr(target, left),
+        ExprKind::Binary(Spanned { node: BinOpKind::Add, .. }, ref left, _) => SpanlessEq::new(cx).eq_expr(target, left),
         ExprKind::Block(ref block, _) => {
             block.stmts.is_empty()
                 && block
index a3342591a1bd092f362817a7fa3732d5fbc9ed06..ce2ef951a4330c8af0e1e999325cb83d19625808 100644 (file)
@@ -59,10 +59,10 @@ fn get_lints(&self) -> LintArray {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
-        use rustc::hir::BinOp_::*;
+        use rustc::hir::BinOpKind::*;
         if let hir::ExprKind::Binary(binop, _, _) = expr.node {
             match binop.node {
-                BiEq | BiLt | BiLe | BiNe | BiGe | BiGt => return,
+                BinOpKind::Eq | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ne | BinOpKind::Ge | BinOpKind::Gt => return,
                 _ => {},
             }
             // Check if the binary expression is part of another bi/unary expression
@@ -94,7 +94,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
                 expr,
                 binop.node,
                 &["Add", "Sub", "Mul", "Div"],
-                &[BiAdd, BiSub, BiMul, BiDiv],
+                &[BinOpKind::Add, BinOpKind::Sub, BinOpKind::Mul, BinOpKind::Div],
             ) {
                 span_lint(
                     cx,
@@ -124,7 +124,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
                     "ShrAssign",
                 ],
                 &[
-                    BiAdd, BiSub, BiMul, BiDiv, BiBitAnd, BiBitOr, BiBitXor, BiRem, BiShl, BiShr
+                    BinOpKind::Add, BinOpKind::Sub, BinOpKind::Mul, BinOpKind::Div, BinOpKind::BitAnd, BinOpKind::BitOr, BinOpKind::BitXor, BinOpKind::Rem, BinOpKind::Shl, BinOpKind::Shr
                 ],
             ) {
                 span_lint(
@@ -144,9 +144,9 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
 fn check_binop<'a>(
     cx: &LateContext,
     expr: &hir::Expr,
-    binop: hir::BinOp_,
+    binop: hir::BinOpKind,
     traits: &[&'a str],
-    expected_ops: &[hir::BinOp_],
+    expected_ops: &[hir::BinOpKind],
 ) -> Option<&'a str> {
     let mut trait_ids = vec![];
     let [krate, module] = crate::utils::paths::OPS_MODULE;
index 6c7c62c741ab5cfea76674810d9c68525a722db9..5b88c517abb99b93f926d726ab1365cdcd688327 100644 (file)
@@ -450,7 +450,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             let op = cmp.node;
             if op.is_comparison() && is_unit(cx.tables.expr_ty(left)) {
                 let result = match op {
-                    BiEq | BiLe | BiGe => "true",
+                    BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true",
                     _ => "false",
                 };
                 span_lint(
@@ -1374,7 +1374,7 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(
 
 fn detect_absurd_comparison<'a, 'tcx>(
     cx: &LateContext<'a, 'tcx>,
-    op: BinOp_,
+    op: BinOpKind,
     lhs: &'tcx Expr,
     rhs: &'tcx Expr,
 ) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> {
index f9faa3b48f77ca6aabb125d7e4d5f4e8610dbb89..fcc3c2f68c1ce86fde16dfe161c510a5b5f63b60 100644 (file)
@@ -80,7 +80,7 @@ fn collect_unwrap_info<'a, 'tcx: 'a>(
 ) -> Vec<UnwrapInfo<'tcx>> {
     if let ExprKind::Binary(op, left, right) = &expr.node {
         match (invert, op.node) {
-            (false, BinOp_::BiAnd) | (false, BinOp_::BiBitAnd) | (true, BinOp_::BiOr) | (true, BinOp_::BiBitOr) => {
+            (false, BinOpKind::And) | (false, BinOpKind::BitAnd) | (true, BinOpKind::Or) | (true, BinOpKind::BitOr) => {
                 let mut unwrap_info = collect_unwrap_info(cx, left, invert);
                 unwrap_info.append(&mut collect_unwrap_info(cx, right, invert));
                 return unwrap_info;
index 42beb971bef7b508668551211e0ba4e6452b4ba0..2ea3636f15abcfbdbf243b034dec4747cafa8758 100644 (file)
@@ -240,7 +240,7 @@ fn visit_expr(&mut self, expr: &Expr) {
                 let left_pat = self.next("left");
                 let right_pat = self.next("right");
                 println!("Binary(ref {}, ref {}, ref {}) = {};", op_pat, left_pat, right_pat, current);
-                println!("    if BinOp_::{:?} == {}.node;", op.node, op_pat);
+                println!("    if BinOpKind::{:?} == {}.node;", op.node, op_pat);
                 self.current = left_pat;
                 self.visit_expr(left);
                 self.current = right_pat;
@@ -385,7 +385,7 @@ fn visit_expr(&mut self, expr: &Expr) {
                 let target_pat = self.next("target");
                 let value_pat = self.next("value");
                 println!("AssignOp(ref {}, ref {}, ref {}) = {};", op_pat, target_pat, value_pat, current);
-                println!("    if BinOp_::{:?} == {}.node;", op.node, op_pat);
+                println!("    if BinOpKind::{:?} == {}.node;", op.node, op_pat);
                 self.current = target_pat;
                 self.visit_expr(target);
                 self.current = value_pat;
index 5cb9b50a79d2b0a1cbd1252925c2444c2bb27ad4..35f41d400ad8417db4f416f14f3ed81d908c3de4 100644 (file)
@@ -2,7 +2,7 @@
 
 #![deny(missing_docs_in_private_items)]
 
-use rustc::hir::{BinOp_, Expr};
+use rustc::hir::{BinOpKind, Expr};
 
 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
 /// Represent a normalized comparison operator.
@@ -19,14 +19,14 @@ pub enum Rel {
 
 /// Put the expression in the form  `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or
 /// `lhs != rhs`.
-pub fn normalize_comparison<'a>(op: BinOp_, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
+pub fn normalize_comparison<'a>(op: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
     match op {
-        BinOp_::BiLt => Some((Rel::Lt, lhs, rhs)),
-        BinOp_::BiLe => Some((Rel::Le, lhs, rhs)),
-        BinOp_::BiGt => Some((Rel::Lt, rhs, lhs)),
-        BinOp_::BiGe => Some((Rel::Le, rhs, lhs)),
-        BinOp_::BiEq => Some((Rel::Eq, rhs, lhs)),
-        BinOp_::BiNe => Some((Rel::Ne, rhs, lhs)),
+        BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)),
+        BinOpKind::Le => Some((Rel::Le, lhs, rhs)),
+        BinOpKind::Gt => Some((Rel::Lt, rhs, lhs)),
+        BinOpKind::Ge => Some((Rel::Le, rhs, lhs)),
+        BinOpKind::Eq => Some((Rel::Eq, rhs, lhs)),
+        BinOpKind::Ne => Some((Rel::Ne, rhs, lhs)),
         _ => None,
     }
 }
index 74f476f55e3461dc2a7737182f8dc23a1f963dd9..75b7fd9e2fe3773f44fc6217121586a5d2cac65f 100644 (file)
@@ -9,7 +9,7 @@
 use crate::utils::{is_expn_of, match_def_path, match_qpath, opt_def_id, paths, resolve_node};
 
 /// Convert a hir binary operator to the corresponding `ast` type.
-pub fn binop(op: hir::BinOp_) -> ast::BinOpKind {
+pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
     match op {
         hir::BinOpKind::Eq => ast::BinOpKind::Eq,
         hir::BinOpKind::Ge => ast::BinOpKind::Ge,
index 6d3d1eeb9fe878713c3280195f40e72cbf34614c..5ff847a53b43da442cab187c7227c3fc7cc7c9a3 100644 (file)
@@ -280,14 +280,26 @@ fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
     }
 }
 
-fn swap_binop<'a>(binop: BinOp_, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOp_, &'a Expr, &'a Expr)> {
+fn swap_binop<'a>(binop: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(BinOpKind, &'a Expr, &'a Expr)> {
     match binop {
-        BiAdd | BiMul | BiBitXor | BiBitAnd | BiEq | BiNe | BiBitOr => Some((binop, rhs, lhs)),
-        BiLt => Some((BiGt, rhs, lhs)),
-        BiLe => Some((BiGe, rhs, lhs)),
-        BiGe => Some((BiLe, rhs, lhs)),
-        BiGt => Some((BiLt, rhs, lhs)),
-        BiShl | BiShr | BiRem | BiSub | BiDiv | BiAnd | BiOr => None,
+        BinOpKind::Add |
+        BinOpKind::Mul |
+        BinOpKind::Eq |
+        BinOpKind::Ne |
+        BinOpKind::BitAnd |
+        BinOpKind::BitXor |
+        BinOpKind::BitOr => Some((binop, rhs, lhs)),
+        BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
+        BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
+        BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
+        BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
+        BinOpKind::Shl |
+        BinOpKind::Shr |
+        BinOpKind::Rem |
+        BinOpKind::Sub |
+        BinOpKind::Div |
+        BinOpKind::And |
+        BinOpKind::Or => None,
     }
 }
 
index 46c14f846abcb1c57c73588352eb930cee7b3cf2..27362bd9be9af98965e156edc44065406157d661 100644 (file)
@@ -382,21 +382,21 @@ fn associativity(op: &AssocOp) -> Associativity {
 
 /// Convert a `hir::BinOp` to the corresponding assigning binary operator.
 fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
-    use rustc::hir::BinOp_::*;
+    use rustc::hir::BinOpKind::*;
     use syntax::parse::token::BinOpToken::*;
 
     AssocOp::AssignOp(match op.node {
-        BiAdd => Plus,
-        BiBitAnd => And,
-        BiBitOr => Or,
-        BiBitXor => Caret,
-        BiDiv => Slash,
-        BiMul => Star,
-        BiRem => Percent,
-        BiShl => Shl,
-        BiShr => Shr,
-        BiSub => Minus,
-        BiAnd | BiEq | BiGe | BiGt | BiLe | BiLt | BiNe | BiOr => panic!("This operator does not exist"),
+        BinOpKind::Add => Plus,
+        BinOpKind::BitAnd => And,
+        BinOpKind::BitOr => Or,
+        BinOpKind::BitXor => Caret,
+        BinOpKind::Div => Slash,
+        BinOpKind::Mul => Star,
+        BinOpKind::Rem => Percent,
+        BinOpKind::Shl => Shl,
+        BinOpKind::Shr => Shr,
+        BinOpKind::Sub => Minus,
+        BinOpKind::And | BinOpKind::Eq | BinOpKind::Ge | BinOpKind::Gt | BinOpKind::Le | BinOpKind::Lt | BinOpKind::Ne | BinOpKind::Or => panic!("This operator does not exist"),
     })
 }
 
index d77950bddc02892daf8179570f47871d317e0d52..5232d5714f1351bb0be34d910f52cd5496ac7574 100644 (file)
@@ -33,7 +33,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         // check for instances of 0.0/0.0
         if_chain! {
             if let ExprKind::Binary(ref op, ref left, ref right) = expr.node;
-            if let BinOp_::BiDiv = op.node;
+            if let BinOpKind::Div = op.node;
             // TODO - constant_simple does not fold many operations involving floats.
             // That's probably fine for this lint - it's pretty unlikely that someone would
             // do something like 0.0/(2.0 - 2.0), but it would be nice to warn on that case too.
index d5982efe12fbc8c7c722771d6c945940a0d85c9a..9f6fce2495a3dfdbfd82e10957744fc8e93341d6 100644 (file)
@@ -25,7 +25,7 @@ impl Mul for Foo {
     type Output = Foo;
 
     fn mul(self, other: Foo) -> Foo {
-        Foo(self.0 * other.0 % 42) // OK: BiRem part of BiExpr as parent node
+        Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
     }
 }
 
@@ -33,7 +33,7 @@ impl Sub for Foo {
     type Output = Foo;
 
     fn sub(self, other: Self) -> Self {
-        Foo(self.0 * other.0 - 42) // OK: BiMul part of BiExpr as child node
+        Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
     }
 }
 
@@ -41,7 +41,7 @@ impl Div for Foo {
     type Output = Foo;
 
     fn div(self, other: Self) -> Self {
-        Foo(do_nothing(self.0 + other.0) / 42) // OK: BiAdd part of BiExpr as child node
+        Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
     }
 }
 
index b8f408ae29af27e03bd6ec70e66d65def9fcd6e8..b311604c0c87eafd4bbc4172d4b9b13d92f02da4 100644 (file)
@@ -1,8 +1,8 @@
 if_chain! {
     if let ExprKind::Binary(ref op, ref left, ref right) = expr.node;
-    if BinOp_::BiEq == op.node;
+    if BinOpKind::Eq == op.node;
     if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
-    if BinOp_::BiBitAnd == op1.node;
+    if BinOpKind::BitAnd == op1.node;
     if let ExprKind::Path(ref path) = left1.node;
     if match_qpath(path, &["x"]);
     if let ExprKind::Lit(ref lit) = right1.node;