mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Merge pull request #2545 from flip1995/sus_arith
Don't lint comparison operators in arithmetic impls
This commit is contained in:
commit
cb7af65e28
2 changed files with 9 additions and 1 deletions
|
@ -61,6 +61,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||||
use rustc::hir::BinOp_::*;
|
use rustc::hir::BinOp_::*;
|
||||||
if let hir::ExprBinary(binop, _, _) = expr.node {
|
if let hir::ExprBinary(binop, _, _) = expr.node {
|
||||||
|
match binop.node {
|
||||||
|
BiEq | BiLt | BiLe | BiNe | BiGe | BiGt => return,
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
// Check if the binary expression is part of another bi/unary expression
|
// Check if the binary expression is part of another bi/unary expression
|
||||||
// as a child node
|
// as a child node
|
||||||
let mut parent_expr = cx.tcx.hir.get_parent_node(expr.id);
|
let mut parent_expr = cx.tcx.hir.get_parent_node(expr.id);
|
||||||
|
|
|
@ -59,7 +59,11 @@ impl Sub for Bar {
|
||||||
type Output = Bar;
|
type Output = Bar;
|
||||||
|
|
||||||
fn sub(self, other: Self) -> Self {
|
fn sub(self, other: Self) -> Self {
|
||||||
|
if self.0 <= other.0 {
|
||||||
Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
|
Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
|
||||||
|
} else {
|
||||||
|
Bar(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue