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));
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,
// 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);
},
_ => {},
}
}
-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,
}
}
}
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;
}
}
-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)
}
}
-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,
} 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,
},
_ => (),
},
- 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,
} 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,
} 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,
} 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,
} 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, "^"),
_ => (),
},
_ => (),
}
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 {
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 {
}
};
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,
}
},
}
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)?)))
},
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 {
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);
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,
}
},
}
},
(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,
},
}
ExprKind::Binary(op, _, _) => {
walk_expr(self, e);
match op.node {
- BiAnd | BiOr => self.short_circuits += 1,
+ BinOpKind::And | BinOpKind::Or => self.short_circuits += 1,
_ => (),
}
},
fn check_binop(
&self,
cx: &LateContext<'a, 'tcx>,
- op: BinOp_,
+ op: BinOpKind,
lhs: &'tcx Expr,
rhs: &'tcx Expr,
span: Span,
}}
}
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!(==),
_ => (),
};
}
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);
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)]
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,
}
}
}
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),
_ => (),
}
}
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 {
}
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);
},
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
_ => (),
}
}
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) {
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) {
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,
_ => (),
}
},
- 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);
},
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) {
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
}
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,
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, "..")));
});
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;
}
);
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");
}
},
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();
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 {
#[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),
}
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()),
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.");
}
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.");
}
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,
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)
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,
}
}
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);
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
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
expr,
binop.node,
&["Add", "Sub", "Mul", "Div"],
- &[BiAdd, BiSub, BiMul, BiDiv],
+ &[BinOpKind::Add, BinOpKind::Sub, BinOpKind::Mul, BinOpKind::Div],
) {
span_lint(
cx,
"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(
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;
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(
fn detect_absurd_comparison<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
- op: BinOp_,
+ op: BinOpKind,
lhs: &'tcx Expr,
rhs: &'tcx Expr,
) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> {
) -> 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;
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;
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;
#![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.
/// 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,
}
}
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,
}
}
-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,
}
}
/// 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"),
})
}
// 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.
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
}
}
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
}
}
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
}
}
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;