1 //! Utility functions about comparison operators.
3 #![deny(missing_docs_in_private_items)]
5 use rustc::hir::{BinOpKind, Expr};
7 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
8 /// Represent a normalized comparison operator.
20 /// Put the expression in the form `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or
22 pub fn normalize_comparison<'a>(op: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
24 BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)),
25 BinOpKind::Le => Some((Rel::Le, lhs, rhs)),
26 BinOpKind::Gt => Some((Rel::Lt, rhs, lhs)),
27 BinOpKind::Ge => Some((Rel::Le, rhs, lhs)),
28 BinOpKind::Eq => Some((Rel::Eq, rhs, lhs)),
29 BinOpKind::Ne => Some((Rel::Ne, rhs, lhs)),