Deduplicate is_comparison impl between BinOpKind and AssocOp

This commit is contained in:
Oli Scherer 2024-04-10 10:53:24 +00:00
parent bb78dba64c
commit 07a9854b5c

View File

@ -920,14 +920,8 @@ impl BinOpKind {
matches!(self, BinOpKind::And | BinOpKind::Or)
}
pub fn is_comparison(&self) -> bool {
use BinOpKind::*;
// Note for developers: please keep this match exhaustive;
// we want compilation to fail if another variant is added.
match *self {
Eq | Lt | Le | Ne | Gt | Ge => true,
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
}
pub fn is_comparison(self) -> bool {
crate::util::parser::AssocOp::from_ast_binop(self).is_comparison()
}
/// Returns `true` if the binary operator takes its arguments by value.