const folding for eq_op

This commit is contained in:
llogiq 2015-08-21 12:26:03 +02:00
parent 4dcbad1b08
commit a22b3cdcee
2 changed files with 7 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}