mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
const folding for eq_op
This commit is contained in:
parent
4dcbad1b08
commit
a22b3cdcee
2 changed files with 7 additions and 2 deletions
|
@ -33,7 +33,7 @@ impl LintPass for EqOp {
|
|||
}
|
||||
|
||||
pub fn is_exp_equal(cx: &Context, left : &Expr, right : &Expr) -> bool {
|
||||
match (&left.node, &right.node) {
|
||||
if match (&left.node, &right.node) {
|
||||
(&ExprBinary(ref lop, ref ll, ref lr),
|
||||
&ExprBinary(ref rop, ref rl, ref rr)) =>
|
||||
lop.node == rop.node &&
|
||||
|
@ -66,7 +66,8 @@ pub fn is_exp_equal(cx: &Context, left : &Expr, right : &Expr) -> bool {
|
|||
lunop == runop && is_exp_equal(cx, l, r),
|
||||
(&ExprVec(ref l), &ExprVec(ref r)) => is_exps_equal(cx, l, r),
|
||||
_ => false
|
||||
} || match (constant(cx, left), constant(cx, right)) {
|
||||
} { return true; }
|
||||
match (constant(cx, left), constant(cx, right)) {
|
||||
(Some(l), Some(r)) => l == r,
|
||||
_ => false
|
||||
}
|
||||
|
|
|
@ -34,4 +34,8 @@ fn main() {
|
|||
((1, 2) != (1, 2)); //~ERROR equal expressions
|
||||
[1].len() == [1].len(); //~ERROR equal expressions
|
||||
vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
|
||||
|
||||
// const folding
|
||||
1 + 1 == 2; //~ERROR equal expressions
|
||||
1 - 1 == 0; //~ERROR equal expressions
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue