diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 3f15f955e199..0ab7a3388637 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -57,19 +57,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { 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)); diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 15871cdfe025..53b4904fa96a 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -175,18 +175,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { // 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { } } -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, } } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 0558ad36b348..25d5e4d4db1d 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -120,9 +120,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { } 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { } } -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, "^"), _ => (), }, _ => (), diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index c6d0942a8770..e23978ebc1d4 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -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) -> Result, String> { + fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec) -> Result, String> { for a in a { if let ExprKind::Binary(binop, ref lhs, ref rhs) = a.node { if binop.node == op { @@ -103,8 +103,8 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { 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 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { } }; 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 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { } 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 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { 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 { diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index e60fbbbe51db..aaa924e95b1e 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -51,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { 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); diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 8e0e60193bba..d7323337f247 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -340,43 +340,43 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { 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 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } }, (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, }, } diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cyclomatic_complexity.rs index 33dbf1afc890..b1b667d046ca 100644 --- a/clippy_lints/src/cyclomatic_complexity.rs +++ b/clippy_lints/src/cyclomatic_complexity.rs @@ -171,7 +171,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> { ExprKind::Binary(op, _, _) => { walk_expr(self, e); match op.node { - BiAnd | BiOr => self.short_circuits += 1, + BinOpKind::And | BinOpKind::Or => self.short_circuits += 1, _ => (), } }, diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 7681cc7225f6..e2ea5723a98e 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -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 @@ impl<'a, 'tcx> DoubleComparisonPass { }} } 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!(==), _ => (), }; } diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index b3f8279c943b..d374973e35b4 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -38,7 +38,7 @@ impl LintPass for DurationSubsec { 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); diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 7c4c09893d3e..f58b499d8065 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -66,20 +66,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { 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, } } diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index c14aafbd417d..acede5d1a132 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -38,11 +38,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { } 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), _ => (), } } diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index ebbffc668080..250ae92ea591 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -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 { diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 95dea6fc6d2b..92e07401818e 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -38,17 +38,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { } 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); }, diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 17164c6c56a5..3b73e78d1a79 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -81,24 +81,24 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { 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 _ => (), } } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 7dd7263551da..5095ddfda258 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -771,7 +771,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: 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 get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: 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 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { 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, diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index ee7658334b35..d1740081e67d 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -789,12 +789,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { _ => (), } }, - 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 lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E 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 } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index f701f957031b..f8f8aae46f8f 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -305,7 +305,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { ); 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"); } }, diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 03c602bc234e..db019bdce889 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -123,7 +123,7 @@ impl LintPass for BoolComparison { 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(); diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 2eb63c264fdd..e0374b80dd81 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { 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 { diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 70cc9eecf6e7..e30ac8695dc8 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -33,7 +33,7 @@ impl LintPass for NegMultiply { #[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), diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index fea0a83b4447..7dc2ab734dca 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -133,7 +133,7 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option 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()), diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 4e63fc2f7fce..4887edea2f39 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -42,14 +42,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { 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."); } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index a2c204dd1494..2ecdf983e6bd 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass { 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, diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index e33e112f0511..2fb3bf5182cd 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -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, } } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index fb9becbd43bd..40f5c66ce158 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -82,7 +82,7 @@ impl LintPass for StringAdd { 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 diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index a3342591a1bd..ce2ef951a433 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -59,10 +59,10 @@ impl LintPass for SuspiciousImpl { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { "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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { 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; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 6c7c62c741ab..5b88c517abb9 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -450,7 +450,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { 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)> { diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index f9faa3b48f77..fcc3c2f68c1c 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -80,7 +80,7 @@ fn collect_unwrap_info<'a, 'tcx: 'a>( ) -> Vec> { 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; diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 42beb971bef7..2ea3636f15ab 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -240,7 +240,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { 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 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { 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; diff --git a/clippy_lints/src/utils/comparisons.rs b/clippy_lints/src/utils/comparisons.rs index 5cb9b50a79d2..35f41d400ad8 100644 --- a/clippy_lints/src/utils/comparisons.rs +++ b/clippy_lints/src/utils/comparisons.rs @@ -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, } } diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 74f476f55e34..75b7fd9e2fe3 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -9,7 +9,7 @@ use syntax::ast; 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, diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 6d3d1eeb9fe8..5ff847a53b43 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -280,14 +280,26 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { } } -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, } } diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 46c14f846abc..27362bd9be9a 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -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"), }) } diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index d77950bddc02..5232d5714f13 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -33,7 +33,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { // 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. diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index d5982efe12fb..9f6fce2495a3 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -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 } } diff --git a/tests/ui/trailing_zeros.stdout b/tests/ui/trailing_zeros.stdout index b8f408ae29af..b311604c0c87 100644 --- a/tests/ui/trailing_zeros.stdout +++ b/tests/ui/trailing_zeros.stdout @@ -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;