3 use utils::{SpanlessEq, span_lint};
5 /// **What it does:** Checks for equal operands to comparison, logical and
6 /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`,
7 /// `||`, `&`, `|`, `^`, `-` and `/`).
9 /// **Why is this bad?** This is usually just a typo or a copy and paste error.
11 /// **Known problems:** False negatives: We had some false positives regarding
12 /// calls (notably [racer](https://github.com/phildawes/racer) had one instance
13 /// of `x.pop() && x.pop()`), so we removed matching any function or method
14 /// calls. We may introduce a whitelist of known pure functions in the future.
23 "equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)"
29 impl LintPass for EqOp {
30 fn get_lints(&self) -> LintArray {
35 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
36 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
37 if let ExprBinary(ref op, ref left, ref right) = e.node {
38 if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
42 &format!("equal expressions as operands to `{}`", op.node.as_str()));
49 fn is_valid_operator(op: &BinOp) -> bool {