1 //! Utility functions about comparison operators.
3 #![deny(clippy::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>(
26 ) -> Option<(Rel, &'a Expr<'a>, &'a Expr<'a>)> {
28 BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)),
29 BinOpKind::Le => Some((Rel::Le, lhs, rhs)),
30 BinOpKind::Gt => Some((Rel::Lt, rhs, lhs)),
31 BinOpKind::Ge => Some((Rel::Le, rhs, lhs)),
32 BinOpKind::Eq => Some((Rel::Eq, rhs, lhs)),
33 BinOpKind::Ne => Some((Rel::Ne, rhs, lhs)),