if_same_then_else: don't assume multiplication is always commutative
This commit is contained in:
parent
f065d4b887
commit
a083b84b78
@ -309,18 +309,15 @@ fn swap_binop<'a>(
|
|||||||
rhs: &'a Expr<'a>,
|
rhs: &'a Expr<'a>,
|
||||||
) -> Option<(BinOpKind, &'a Expr<'a>, &'a Expr<'a>)> {
|
) -> Option<(BinOpKind, &'a Expr<'a>, &'a Expr<'a>)> {
|
||||||
match binop {
|
match binop {
|
||||||
BinOpKind::Add
|
BinOpKind::Add | BinOpKind::Eq | BinOpKind::Ne | BinOpKind::BitAnd | BinOpKind::BitXor | BinOpKind::BitOr => {
|
||||||
| BinOpKind::Mul
|
Some((binop, rhs, lhs))
|
||||||
| BinOpKind::Eq
|
},
|
||||||
| BinOpKind::Ne
|
|
||||||
| BinOpKind::BitAnd
|
|
||||||
| BinOpKind::BitXor
|
|
||||||
| BinOpKind::BitOr => Some((binop, rhs, lhs)),
|
|
||||||
BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
|
BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)),
|
||||||
BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
|
BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)),
|
||||||
BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
|
BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)),
|
||||||
BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
|
BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)),
|
||||||
BinOpKind::Shl
|
BinOpKind::Mul
|
||||||
|
| BinOpKind::Shl
|
||||||
| BinOpKind::Shr
|
| BinOpKind::Shr
|
||||||
| BinOpKind::Rem
|
| BinOpKind::Rem
|
||||||
| BinOpKind::Sub
|
| BinOpKind::Sub
|
||||||
|
@ -142,4 +142,16 @@ fn func() {
|
|||||||
|
|
||||||
fn f(val: &[u8]) {}
|
fn f(val: &[u8]) {}
|
||||||
|
|
||||||
|
mod issue_5698 {
|
||||||
|
fn mul_not_always_commutative(x: i32, y: i32) -> i32 {
|
||||||
|
if x == 42 {
|
||||||
|
x * y
|
||||||
|
} else if x == 21 {
|
||||||
|
y * x
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user